--- gcc/objc/hash.c 2018/04/24 18:03:32 1.1 +++ gcc/objc/hash.c 2018/04/24 18:20:08 1.1.1.3 @@ -1,5 +1,5 @@ -/* Hash tables for Objective C method dispatch. - Copyright (C) 1992 Free Software Foundation, Inc. +/* Hash tables for Objective C internal structures + Copyright (C) 1993 Free Software Foundation, Inc. This file is part of GNU CC. @@ -23,15 +23,12 @@ the Free Software Foundation, 675 Mass A This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ -#include "tconfig.h" -#include "gstddef.h" -#include "gstdarg.h" #include "assert.h" -#include "hash.h" -#include "objc.h" -#include "objc-proto.h" +#include "objc/hash.h" +#include "objc/objc.h" +#include "runtime.h" /* for DEBUG_PRINTF */ /* These two macros determine when a hash table is full and by how much it should be expanded respectively. @@ -42,26 +39,27 @@ the Free Software Foundation, 675 Mass A #define EXPANSION(cache) \ ((cache)->size * 2) +void *__objc_xcalloc (size_t, size_t); + cache_ptr hash_new (unsigned int size, hash_func_type hash_func, compare_func_type compare_func) { cache_ptr cache; - /* Pass me a value greater than 0 and a power of 2. */ assert (size); assert (!(size & (size - 1))); /* Allocate the cache structure. calloc insures its initialization for default values. */ - cache = (cache_ptr) calloc (1, sizeof (struct cache)); + cache = (cache_ptr) __objc_xcalloc (1, sizeof (struct cache)); assert (cache); /* Allocate the array of buckets for the cache. calloc initializes all of the pointers to NULL. */ cache->node_table - = (node_ptr *) calloc (size, sizeof (node_ptr)); + = (node_ptr *) __objc_xcalloc (size, sizeof (node_ptr)); assert (cache->node_table); cache->size = size; @@ -87,7 +85,7 @@ hash_delete (cache_ptr cache) /* Purge all key/value pairs from the table. */ - while (node = hash_next (cache, NULL)) + while ((node = hash_next (cache, NULL))) hash_remove (cache, node->key); /* Release the array of nodes and the cache itself. */ @@ -100,7 +98,7 @@ void hash_add (cache_ptr *cachep, const void *key, void *value) { size_t indx = (*(*cachep)->hash_func)(*cachep, key); - node_ptr node = (node_ptr) calloc (1, sizeof (struct cache_node)); + node_ptr node = (node_ptr) __objc_xcalloc (1, sizeof (struct cache_node)); assert (node); @@ -148,7 +146,7 @@ hash_add (cache_ptr *cachep, const void *cachep, (*cachep)->size, new->size); /* Copy the nodes from the first hash table to the new one. */ - while (node1 = hash_next (*cachep, node1)) + while ((node1 = hash_next (*cachep, node1))) hash_add (&new, node1->key, node1->value); /* Trash the old cache. */