diff options
author | Miguel Sofer <miguel.sofer@gmail.com> | 2006-10-22 00:13:28 (GMT) |
---|---|---|
committer | Miguel Sofer <miguel.sofer@gmail.com> | 2006-10-22 00:13:28 (GMT) |
commit | 26d407419e1440003de4682f5d60c8c45ec76260 (patch) | |
tree | b77bf364d44aa23e0ee2899d93b8e0118c972b1a /generic/tclHash.c | |
parent | 90490cce920eb45b480cff3690ae01e5e2241794 (diff) | |
download | tcl-26d407419e1440003de4682f5d60c8c45ec76260.zip tcl-26d407419e1440003de4682f5d60c8c45ec76260.tar.gz tcl-26d407419e1440003de4682f5d60c8c45ec76260.tar.bz2 |
* generic/tcl.h:
* generic/tclHash.c: Tcl_FindHashEntry() now calls
Tcl_CreateHashEntry() with a newPtr set to NULL: this would have
caused a segfault previously and eliminates duplicated code. A
macro has been added to tcl.h (only used when
TCL_PRESERVE_BINARY_COMPATABALITY is not set - ie, not by default).
Diffstat (limited to 'generic/tclHash.c')
-rw-r--r-- | generic/tclHash.c | 81 |
1 files changed, 11 insertions, 70 deletions
diff --git a/generic/tclHash.c b/generic/tclHash.c index 3faadb9..cabf02a 100644 --- a/generic/tclHash.c +++ b/generic/tclHash.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclHash.c,v 1.25 2006/08/10 12:15:31 dkf Exp $ + * RCS: @(#) $Id: tclHash.c,v 1.26 2006/10/22 00:13:29 msofer Exp $ */ #include "tclInt.h" @@ -263,75 +263,10 @@ Tcl_FindHashEntry( Tcl_HashTable *tablePtr, /* Table in which to lookup entry. */ CONST char *key) /* Key to use to find matching entry. */ { - register Tcl_HashEntry *hPtr; - Tcl_HashKeyType *typePtr; - unsigned int hash; - int index; - -#if TCL_PRESERVE_BINARY_COMPATABILITY - if (tablePtr->keyType == TCL_STRING_KEYS) { - typePtr = &tclStringHashKeyType; - } else if (tablePtr->keyType == TCL_ONE_WORD_KEYS) { - typePtr = &tclOneWordHashKeyType; - } else if (tablePtr->keyType == TCL_CUSTOM_TYPE_KEYS - || tablePtr->keyType == TCL_CUSTOM_PTR_KEYS) { - typePtr = tablePtr->typePtr; - } else { - typePtr = &tclArrayHashKeyType; - } -#else - typePtr = tablePtr->typePtr; - if (typePtr == NULL) { - Tcl_Panic("called %s on deleted table", "Tcl_FindHashEntry"); - return NULL; - } -#endif - - if (typePtr->hashKeyProc) { - hash = typePtr->hashKeyProc (tablePtr, (VOID *) key); - if (typePtr->flags & TCL_HASH_KEY_RANDOMIZE_HASH) { - index = RANDOM_INDEX (tablePtr, hash); - } else { - index = hash & tablePtr->mask; - } - } else { - hash = (unsigned int) key; - index = RANDOM_INDEX (tablePtr, hash); - } - - /* - * Search all of the entries in the appropriate bucket. - */ - if (typePtr->compareKeysProc) { - Tcl_CompareHashKeysProc *compareKeysProc = typePtr->compareKeysProc; - for (hPtr = tablePtr->buckets[index]; hPtr != NULL; - hPtr = hPtr->nextPtr) { -#if TCL_HASH_KEY_STORE_HASH - if (hash != (unsigned int) hPtr->hash) { - continue; - } -#endif - if (compareKeysProc ((VOID *) key, hPtr)) { - return hPtr; - } - } - } else { - for (hPtr = tablePtr->buckets[index]; hPtr != NULL; - hPtr = hPtr->nextPtr) { -#if TCL_HASH_KEY_STORE_HASH - if (hash != (unsigned int) hPtr->hash) { - continue; - } -#endif - if (key == hPtr->key.oneWordValue) { - return hPtr; - } - } - } - - return NULL; + return Tcl_CreateHashEntry(tablePtr, key, NULL); } + /* *---------------------------------------------------------------------- @@ -412,7 +347,8 @@ Tcl_CreateHashEntry( } #endif if (compareKeysProc ((VOID *) key, hPtr)) { - *newPtr = 0; + if (newPtr) + *newPtr = 0; return hPtr; } } @@ -425,12 +361,17 @@ Tcl_CreateHashEntry( } #endif if (key == hPtr->key.oneWordValue) { - *newPtr = 0; + if (newPtr) + *newPtr = 0; return hPtr; } } } + if (!newPtr) + return NULL; + + /* * Entry not found. Add a new one to the bucket. */ |