void free (void *p) { # ifndef NDEBUG { if (wrapper_state != WRAPPER_INITIALIZING) { if (static_mem <= ((char *) p) && ((char *) p) < top_static_mem) { print ("*** free() in wrapper called for argument\n"); print ("*** that was allocated during initialization!\n"); } } } # endif switch (wrapper_state) { case WRAPPER_UNINITIALIZED: print ("*** free() in wrapper called before malloc()\n"); exit (1); break; case WRAPPER_INITIALIZED: if (semaphore) { wrapper_num_deallocated++; MY_free(p); } else { semaphore++; ccmalloc_free (p); semaphore--; } break; default: case WRAPPER_INITIALIZING: static_free (p); break; } # ifdef LOG_EXTERNAL_MALLOC { print ("::: 0x"); print_hex ((unsigned) p); if (semaphore) print (" internal"); else print (" external"); print (" free\n"); } # endif }
/* Insert a key-value pair into a hash table. */ void ht_set( hashtable_t *hashtable, char *key, funct_t value ) { int bin = 0; entry_t *newpair = NULL; entry_t *next = NULL; entry_t *last = NULL; bin = ht_hash( hashtable, key ); next = hashtable->table[ bin ]; while( next != NULL && next->key != NULL && strcmp( key, next->key ) > 0 ) { last = next; next = next->next; } /* There's already a pair. Let's replace that string. */ if( next != NULL && next->key != NULL && strcmp( key, next->key ) == 0 ) { static_free( next->value ); next->value = value; /* Nope, could't find it. Time to grow a pair. */ } else { newpair = ht_newpair( key, value ); /* We're at the start of the linked list in this bin. */ if( next == hashtable->table[ bin ] ) { newpair->next = next; hashtable->table[ bin ] = newpair; /* We're at the end of the linked list in this bin. */ } else if ( next == NULL ) { last->next = newpair; /* We're in the middle of the list. */ } else { newpair->next = next; last->next = newpair; } } }