Rev 4192 | Rev 4243 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4192 | Rev 4197 | ||
---|---|---|---|
Line 81... | Line 81... | ||
81 | int name##_add( name##_ref map, int key, type * value ){ \ |
81 | int name##_add( name##_ref map, int key, type * value ){ \ |
82 | if( name##_is_valid( map )){ \ |
82 | if( name##_is_valid( map )){ \ |
83 | if( map->next == ( map->size - 1 )){ \ |
83 | if( map->next == ( map->size - 1 )){ \ |
84 | name##_item_ref tmp; \ |
84 | name##_item_ref tmp; \ |
85 | \ |
85 | \ |
86 | tmp = ( name##_item_ref ) malloc( sizeof( name##_item_t ) * 2 * map->size ); \ |
86 | tmp = ( name##_item_ref ) realloc( map->items, sizeof( name##_item_t ) * 2 * map->size ); \ |
87 | if( ! tmp ) return ENOMEM; \ |
87 | if( ! tmp ) return ENOMEM; \ |
88 | map->size *= 2; \ |
88 | map->size *= 2; \ |
89 | memcpy( tmp, map->items, sizeof( name##_item_t ) * map->next ); \ |
- | |
90 | free( map->items ); \ |
- | |
91 | map->items = tmp; \ |
89 | map->items = tmp; \ |
92 | } \ |
90 | } \ |
93 | map->items[ map->next ].key = key; \ |
91 | map->items[ map->next ].key = key; \ |
94 | map->items[ map->next ].value = value; \ |
92 | map->items[ map->next ].value = value; \ |
95 | map->items[ map->next ].magic = INT_MAP_ITEM_MAGIC_VALUE; \ |
93 | map->items[ map->next ].magic = INT_MAP_ITEM_MAGIC_VALUE; \ |