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 | |
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).
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | generic/tcl.h | 6 | ||||
-rw-r--r-- | generic/tclHash.c | 81 |
3 files changed, 24 insertions, 72 deletions
@@ -1,3 +1,12 @@ +2006-10-21 Miguel Sofer <msofer@users.sf.net> + + * 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). + 2006-10-20 Daniel Steffen <das@users.sourceforge.net> *** 8.5a5 TAGGED FOR RELEASE *** diff --git a/generic/tcl.h b/generic/tcl.h index 3501c96..922da8f 100644 --- a/generic/tcl.h +++ b/generic/tcl.h @@ -13,7 +13,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tcl.h,v 1.219 2006/10/20 15:16:47 dkf Exp $ + * RCS: @(#) $Id: tcl.h,v 1.220 2006/10/22 00:13:29 msofer Exp $ */ #ifndef _TCL @@ -1394,7 +1394,9 @@ typedef struct Tcl_HashSearch { * Macro to use new extended version of Tcl_InitHashTable. */ # define Tcl_InitHashTable(tablePtr, keyType) \ - Tcl_InitHashTableEx(tablePtr, keyType, NULL) + Tcl_InitHashTableEx((tablePtr), (keyType), NULL) +# define Tcl_FindHashEntry(tablePtr, key) \ + Tcl_CreateHashEntry((tablePtr), (key), NULL) #endif /* TCL_PRESERVE_BINARY_COMPATABILITY */ /* 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. */ |