From a057ea7bd4e1ced6c9f681489b5fafc68d9ff23b Mon Sep 17 00:00:00 2001 From: rlar Date: Sun, 17 Jul 2011 10:59:00 +0000 Subject: [PATCH] nghash cleanup, use stdint.h for proper sized integers representing a pointer --- ChangeLog | 5 +++++ src/include/hash.h | 22 +++++++++++++--------- src/misc/hash.c | 20 +++++--------------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5e50539bd..5f25bd2c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-07-17 Robert Larice + * src/include/hash.h , + * src/misc/hash.c : + nghash cleanup, use stdint.h for proper sized integers representing a pointer + 2011-07-17 Robert Larice * visualc/include/inttypes.h , * visualc/include/stdint.h : diff --git a/src/include/hash.h b/src/include/hash.h index ddfd60f37..546f19876 100644 --- a/src/include/hash.h +++ b/src/include/hash.h @@ -10,6 +10,7 @@ REVISIONS: Aug 21, 2009 - adapted for ngspice #define NGHASH_H #include +#include #define _NGMALLOC(size_xz) tmalloc((size_xz)) #define NGMALLOC(n, els) TMALLOC(els, n) @@ -68,14 +69,17 @@ typedef struct nghashbox NGHASHBOX, *NGHASHPTR; * on all architecture types include 64bits. * ----------------------------------------------------------------- */ typedef enum { - NGHASH_FUNC_NUM = -2L, - NGHASH_FUNC_PTR = -1L, - NGHASH_FUNC_STR = 0L, - NGHASH_UNIQUE = 1L, - NGHASH_POWER_OF_TWO = (1L<<1), + NGHASH_UNIQUE = 1 << 0, + NGHASH_POWER_OF_TWO = 1 << 1, NGHASH_UNIQUE_TWO = NGHASH_UNIQUE | NGHASH_POWER_OF_TWO } NGHASHFLAGS_T ; +enum nghash_default_func_t { + NGHASH_FUNC_NUM = -2, + NGHASH_FUNC_PTR = -1, + NGHASH_FUNC_STR = 0 +}; + typedef struct nghash_iter_rec { struct ngtable_rec *position ; @@ -92,8 +96,8 @@ we want to intentionally assign it. The compiler is warning unnecessarily. #define NGHASH_FIRST(x_yz) ( (x_yz)->position = NULL ) ; #define NGHASH_ITER_EQUAL(x_yz,y_yz) ( (x_yz)->position == (y_yz)->position ) -#define NGHASH_DEF_HASH(x) ((nghash_func_t *) (x)) -#define NGHASH_DEF_CMP(x) ((nghash_compare_func_t *) (x)) +#define NGHASH_DEF_HASH(x) ((nghash_func_t *) (intptr_t) (x)) +#define NGHASH_DEF_CMP(x) ((nghash_compare_func_t *) (intptr_t) (x)) /* defines for unique flag */ @@ -179,7 +183,7 @@ we want to intentionally assign it. The compiler is warning unnecessarily. #define NGHASH_NUM_TO_HASH( ptr, hsum, size ) \ do { \ unsigned int temp ; \ - long value = (long) ptr ; \ + intptr_t value = (intptr_t) ptr ; \ temp = (unsigned int) value ; \ hsum = temp & (unsigned int) (size - 1) ; \ } while(0); @@ -224,7 +228,7 @@ we want to intentionally assign it. The compiler is warning unnecessarily. #define NGHASH_PTR_TO_HASH( ptr, hsum, size ) \ do { \ unsigned int temp ; \ - long value = (long) ptr ; \ + intptr_t value = (intptr_t) ptr ; \ temp = (unsigned int) (value >> 4) ; \ hsum = temp & (unsigned int) (size - 1) ; \ } while(0); diff --git a/src/misc/hash.c b/src/misc/hash.c index 36a3a862b..abfde104d 100644 --- a/src/misc/hash.c +++ b/src/misc/hash.c @@ -227,7 +227,6 @@ void nghash_free_string_hashtable(NGHASHPTR hashtable) void * _nghash_find(NGHASHPTR hashtable, void * user_key,BOOL *status) { int ret_code ; - long hfunc ; unsigned int hsum ; NGTABLEPTR curPtr ; NGTABLEPTR *table ; @@ -239,8 +238,7 @@ void * _nghash_find(NGHASHPTR hashtable, void * user_key,BOOL *status) /* ----------------------------------------------------------------- * Process the hash function. ----------------------------------------------------------------- */ - hfunc = (long) hashtable->hash_func ; - switch( hfunc ){ + switch( (intptr_t) hashtable->hash_func ) { case NGHASH_FUNC_STR: NGHASH_STR_TO_HASH( user_key, hsum, hashtable->size); break ; @@ -340,7 +338,6 @@ void * nghash_find_again(NGHASHPTR hashtable, void * user_key) void * nghash_delete(NGHASHPTR hashtable, void * user_key) { int ret_code ; - long hfunc ; unsigned int hsum ; void * user_data_p ; NGTABLEPTR curPtr, *prevPtr ; @@ -353,8 +350,7 @@ void * nghash_delete(NGHASHPTR hashtable, void * user_key) /* ----------------------------------------------------------------- * Process the hash function. ----------------------------------------------------------------- */ - hfunc = (long) hashtable->hash_func ; - switch( hfunc ){ + switch( (intptr_t) hashtable->hash_func ) { case NGHASH_FUNC_STR: NGHASH_STR_TO_HASH( user_key, hsum, hashtable->size); break ; @@ -412,7 +408,6 @@ void * nghash_delete(NGHASHPTR hashtable, void * user_key) void * nghash_insert(NGHASHPTR hashtable, void * user_key, void * data) { int ret_code ; - long hfunc ; unsigned int hsum ; NGTABLEPTR curPtr, temptr, curTable ; NGTABLEPTR *table ; @@ -424,8 +419,7 @@ void * nghash_insert(NGHASHPTR hashtable, void * user_key, void * data) /* ----------------------------------------------------------------- * Process the hash function. ----------------------------------------------------------------- */ - hfunc = (long) hashtable->hash_func ; - switch( hfunc ){ + switch( (intptr_t) hashtable->hash_func ) { case NGHASH_FUNC_STR: NGHASH_STR_TO_HASH( user_key, hsum, hashtable->size); break ; @@ -503,7 +497,6 @@ void * nghash_insert(NGHASHPTR hashtable, void * user_key, void * data) static NGTABLEPTR _nghash_find_item(NGHASHPTR htable,void * user_key,void * data) { int ret_code ; - long hfunc ; unsigned int hsum ; NGTABLEPTR curPtr, temptr ; NGTABLEPTR *table ; @@ -514,8 +507,7 @@ static NGTABLEPTR _nghash_find_item(NGHASHPTR htable,void * user_key,void * data /* ----------------------------------------------------------------- * Process the hash function. ----------------------------------------------------------------- */ - hfunc = (long) htable->hash_func ; - switch( hfunc ){ + switch( (intptr_t) htable->hash_func ) { case NGHASH_FUNC_STR: NGHASH_STR_TO_HASH( user_key, hsum, htable->size); break ; @@ -738,7 +730,6 @@ void nghash_dump(NGHASHPTR htable, void (*print_key) (void *)) BOOL nghash_deleteItem(NGHASHPTR hashtable, void * user_key, void * data) { int ret_code ; - long hfunc ; unsigned long hsum ; NGTABLEPTR curPtr, temptr, *prevPtr ; NGTABLEPTR *table ; @@ -749,8 +740,7 @@ BOOL nghash_deleteItem(NGHASHPTR hashtable, void * user_key, void * data) /* ----------------------------------------------------------------- * Process the hash function. ----------------------------------------------------------------- */ - hfunc = (long) hashtable->hash_func ; - switch( hfunc ){ + switch( (intptr_t) hashtable->hash_func ) { case NGHASH_FUNC_STR: NGHASH_STR_TO_HASH( user_key, hsum, hashtable->size); break ;