From: Nathan Wagner Date: Fri, 14 Sep 2018 08:12:28 +0000 (+0000) Subject: remove c++isms from jsw code X-Git-Tag: v0.1.6~48 X-Git-Url: https://pd.if.org/git/?a=commitdiff_plain;h=94724d7dd33cf19e283d86109adc037c0d771b6d;hp=d37d830611a8dc438b2de37f68bf2f9ae1230490;p=zpackage remove c++isms from jsw code removed malloc casts and header externs --- diff --git a/lib/jsw/jsw_atree.c b/lib/jsw/jsw_atree.c index ba66bd0..36a90a7 100644 --- a/lib/jsw/jsw_atree.c +++ b/lib/jsw/jsw_atree.c @@ -15,15 +15,7 @@ */ #include "jsw_atree.h" -#ifdef __cplusplus -#include - -using std::malloc; -using std::free; -using std::size_t; -#else #include -#endif #ifndef HEIGHT_LIMIT #define HEIGHT_LIMIT 64 /* Tallest allowable tree */ @@ -74,7 +66,7 @@ struct jsw_atrav { static jsw_anode_t *new_node ( jsw_atree_t *tree, void *data ) { - jsw_anode_t *rn = (jsw_anode_t *)malloc ( sizeof *rn ); + jsw_anode_t *rn = malloc ( sizeof *rn ); if ( rn == NULL ) return tree->nil; @@ -88,13 +80,13 @@ static jsw_anode_t *new_node ( jsw_atree_t *tree, void *data ) jsw_atree_t *jsw_anew ( cmp_f cmp, dup_f dup, rel_f rel ) { - jsw_atree_t *rt = (jsw_atree_t *)malloc ( sizeof *rt ); + jsw_atree_t *rt = malloc ( sizeof *rt ); if ( rt == NULL ) return NULL; /* Initialize sentinel */ - rt->nil = (jsw_anode_t *)malloc ( sizeof *rt->nil ); + rt->nil = malloc ( sizeof *rt->nil ); if ( rt->nil == NULL ) { free ( rt ); return NULL; diff --git a/lib/jsw/jsw_atree.h b/lib/jsw/jsw_atree.h index 0faf528..54e4fd8 100644 --- a/lib/jsw/jsw_atree.h +++ b/lib/jsw/jsw_atree.h @@ -17,15 +17,10 @@ anyone who has modified the code through a header comment, such as this one. */ -#ifdef __cplusplus -#include -using std::size_t; +/* code modified for inclusion in zpm */ -extern "C" { -#else #include -#endif /* Opaque types */ typedef struct jsw_atree jsw_atree_t; @@ -52,8 +47,4 @@ void *jsw_atlast ( jsw_atrav_t *trav, jsw_atree_t *tree ); void *jsw_atnext ( jsw_atrav_t *trav ); void *jsw_atprev ( jsw_atrav_t *trav ); -#ifdef __cplusplus -} -#endif - #endif diff --git a/lib/jsw/jsw_avltree.c b/lib/jsw/jsw_avltree.c index f8910fb..eb91eb7 100644 --- a/lib/jsw/jsw_avltree.c +++ b/lib/jsw/jsw_avltree.c @@ -6,15 +6,7 @@ */ #include "jsw_avltree.h" -#ifdef __cplusplus -#include - -using std::malloc; -using std::free; -using std::size_t; -#else #include -#endif #ifndef HEIGHT_LIMIT #define HEIGHT_LIMIT 64 /* Tallest allowable tree */ @@ -114,7 +106,7 @@ struct jsw_avltrav { static jsw_avlnode_t *new_node ( jsw_avltree_t *tree, void *data ) { - jsw_avlnode_t *rn = (jsw_avlnode_t *)malloc ( sizeof *rn ); + jsw_avlnode_t *rn = malloc ( sizeof *rn ); if ( rn == NULL ) return NULL; @@ -128,7 +120,7 @@ static jsw_avlnode_t *new_node ( jsw_avltree_t *tree, void *data ) jsw_avltree_t *jsw_avlnew ( cmp_f cmp, dup_f dup, rel_f rel ) { - jsw_avltree_t *rt = (jsw_avltree_t *)malloc ( sizeof *rt ); + jsw_avltree_t *rt = malloc ( sizeof *rt ); if ( rt == NULL ) return NULL; diff --git a/lib/jsw/jsw_avltree.h b/lib/jsw/jsw_avltree.h index aaaf76e..bc46b26 100644 --- a/lib/jsw/jsw_avltree.h +++ b/lib/jsw/jsw_avltree.h @@ -18,15 +18,7 @@ anyone who has modified the code through a header comment, such as this one. */ -#ifdef __cplusplus -#include - -using std::size_t; - -extern "C" { -#else #include -#endif /* Opaque types */ typedef struct jsw_avltree jsw_avltree_t; @@ -53,8 +45,4 @@ void *jsw_avltlast ( jsw_avltrav_t *trav, jsw_avltree_t *tree ); void *jsw_avltnext ( jsw_avltrav_t *trav ); void *jsw_avltprev ( jsw_avltrav_t *trav ); -#ifdef __cplusplus -} -#endif - #endif diff --git a/lib/jsw/jsw_hlib.c b/lib/jsw/jsw_hlib.c index 6cc961a..a3a7a13 100644 --- a/lib/jsw/jsw_hlib.c +++ b/lib/jsw/jsw_hlib.c @@ -8,14 +8,7 @@ */ #include "jsw_hlib.h" -#ifdef __cplusplus -#include - -using std::malloc; -using std::free; -#else #include -#endif typedef struct jsw_node { void *key; /* Key used for searching */ @@ -44,7 +37,7 @@ struct jsw_hash { static jsw_node_t *new_node ( void *key, void *item, jsw_node_t *next ) { - jsw_node_t *node = (jsw_node_t *)malloc ( sizeof *node ); + jsw_node_t *node = malloc ( sizeof *node ); if ( node == NULL ) return NULL; @@ -58,7 +51,7 @@ static jsw_node_t *new_node ( void *key, void *item, jsw_node_t *next ) static jsw_head_t *new_chain ( void ) { - jsw_head_t *chain = (jsw_head_t *)malloc ( sizeof *chain ); + jsw_head_t *chain = malloc ( sizeof *chain ); if ( chain == NULL ) return NULL; @@ -79,13 +72,13 @@ jsw_hash_t *jsw_hnew ( size_t size, hash_f hash, cmp_f cmp, keydup_f keydup, itemdup_f itemdup, keyrel_f keyrel, itemrel_f itemrel ) { - jsw_hash_t *htab = (jsw_hash_t *)malloc ( sizeof *htab ); + jsw_hash_t *htab = malloc ( sizeof *htab ); size_t i; if ( htab == NULL ) return NULL; - htab->table = (jsw_head_t **)malloc ( size * sizeof *htab->table ); + htab->table = malloc ( size * sizeof *htab->table ); if ( htab->table == NULL ) { free ( htab ); @@ -385,7 +378,7 @@ jsw_hstat_t *jsw_hstat ( jsw_hash_t *htab ) if ( htab->size == 0 ) return NULL; - stat = (jsw_hstat_t *)malloc ( sizeof *stat ); + stat = malloc ( sizeof *stat ); if ( stat == NULL ) return NULL; diff --git a/lib/jsw/jsw_hlib.h b/lib/jsw/jsw_hlib.h index 78cbdd7..e64476b 100644 --- a/lib/jsw/jsw_hlib.h +++ b/lib/jsw/jsw_hlib.h @@ -18,15 +18,7 @@ anyone who has modified the code through a header comment, such as this one. */ -#ifdef __cplusplus -#include - -using std::size_t; - -extern "C" { -#else #include -#endif typedef struct jsw_hash jsw_hash_t; @@ -117,8 +109,4 @@ size_t jsw_hcapacity ( jsw_hash_t *htab ); /* Get statistics for the hash table */ jsw_hstat_t *jsw_hstat ( jsw_hash_t *htab ); -#ifdef __cplusplus -} -#endif - #endif diff --git a/lib/jsw/jsw_rbtree.c b/lib/jsw/jsw_rbtree.c index c5ec17c..62e4144 100644 --- a/lib/jsw/jsw_rbtree.c +++ b/lib/jsw/jsw_rbtree.c @@ -6,15 +6,7 @@ */ #include "jsw_rbtree.h" -#ifdef __cplusplus -#include - -using std::malloc; -using std::free; -using std::size_t; -#else #include -#endif #ifndef HEIGHT_LIMIT #define HEIGHT_LIMIT 64 /* Tallest allowable tree */ @@ -110,7 +102,7 @@ static jsw_rbnode_t *jsw_double ( jsw_rbnode_t *root, int dir ) */ static jsw_rbnode_t *new_node ( jsw_rbtree_t *tree, void *data ) { - jsw_rbnode_t *rn = (jsw_rbnode_t *)malloc ( sizeof *rn ); + jsw_rbnode_t *rn = malloc ( sizeof *rn ); if ( rn == NULL ) return NULL; @@ -137,7 +129,7 @@ static jsw_rbnode_t *new_node ( jsw_rbtree_t *tree, void *data ) */ jsw_rbtree_t *jsw_rbnew ( cmp_f cmp, dup_f dup, rel_f rel ) { - jsw_rbtree_t *rt = (jsw_rbtree_t *)malloc ( sizeof *rt ); + jsw_rbtree_t *rt = malloc ( sizeof *rt ); if ( rt == NULL ) return NULL; @@ -439,7 +431,7 @@ size_t jsw_rbsize ( jsw_rbtree_t *tree ) */ jsw_rbtrav_t *jsw_rbtnew ( void ) { - return (jsw_rbtrav_t*)malloc ( sizeof ( jsw_rbtrav_t ) ); + return malloc ( sizeof ( jsw_rbtrav_t ) ); } /** @@ -578,4 +570,4 @@ void *jsw_rbtnext ( jsw_rbtrav_t *trav ) void *jsw_rbtprev ( jsw_rbtrav_t *trav ) { return move ( trav, 0 ); /* Toward smaller items */ -} \ No newline at end of file +} diff --git a/lib/jsw/jsw_rbtree.h b/lib/jsw/jsw_rbtree.h index 1933bae..593fb86 100644 --- a/lib/jsw/jsw_rbtree.h +++ b/lib/jsw/jsw_rbtree.h @@ -18,15 +18,7 @@ anyone who has modified the code through a header comment, such as this one. */ -#ifdef __cplusplus -#include - -using std::size_t; - -extern "C" { -#else #include -#endif /* Opaque types */ typedef struct jsw_rbtree jsw_rbtree_t; @@ -53,8 +45,4 @@ void *jsw_rbtlast ( jsw_rbtrav_t *trav, jsw_rbtree_t *tree ); void *jsw_rbtnext ( jsw_rbtrav_t *trav ); void *jsw_rbtprev ( jsw_rbtrav_t *trav ); -#ifdef __cplusplus -} -#endif - #endif