summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2016-07-08 09:46:01 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2016-07-08 09:46:01 (GMT)
commit2be6ee536d794c609ad15b4504a7eb235bf7f330 (patch)
tree6d895f484691ec4c5b4b0ea200cd4297ffd21ea6
parent8c713bd3abfd8d484a8793d1681e492aa0794592 (diff)
downloadtcl-2be6ee536d794c609ad15b4504a7eb235bf7f330.zip
tcl-2be6ee536d794c609ad15b4504a7eb235bf7f330.tar.gz
tcl-2be6ee536d794c609ad15b4504a7eb235bf7f330.tar.bz2
Use TCL_HASH_TYPE #define for compatibility with Tcl8 in stead of TCL_HASH_KEY_TYPE_VERSION_2
-rw-r--r--generic/tcl.h9
-rw-r--r--generic/tclCompile.h2
-rw-r--r--generic/tclDictObj.c2
-rw-r--r--generic/tclHash.c43
-rw-r--r--generic/tclInt.h2
-rw-r--r--generic/tclLiteral.c26
-rw-r--r--generic/tclObj.c6
-rw-r--r--generic/tclTest.c2
-rw-r--r--generic/tclVar.c2
9 files changed, 47 insertions, 47 deletions
diff --git a/generic/tcl.h b/generic/tcl.h
index cf43ff0..dd2848a 100644
--- a/generic/tcl.h
+++ b/generic/tcl.h
@@ -936,11 +936,15 @@ typedef struct Tcl_DString {
* Forward declarations of Tcl_HashTable and related types.
*/
+#ifndef TCL_HASH_TYPE
+# define TCL_HASH_TYPE size_t
+#endif
+
typedef struct Tcl_HashKeyType Tcl_HashKeyType;
typedef struct Tcl_HashTable Tcl_HashTable;
typedef struct Tcl_HashEntry Tcl_HashEntry;
-typedef size_t (Tcl_HashKeyProc) (Tcl_HashTable *tablePtr, void *keyPtr);
+typedef TCL_HASH_TYPE (Tcl_HashKeyProc) (Tcl_HashTable *tablePtr, void *keyPtr);
typedef int (Tcl_CompareHashKeysProc) (void *keyPtr, Tcl_HashEntry *hPtr);
typedef Tcl_HashEntry * (Tcl_AllocHashEntryProc) (Tcl_HashTable *tablePtr,
void *keyPtr);
@@ -992,7 +996,6 @@ struct Tcl_HashEntry {
*/
#define TCL_HASH_KEY_TYPE_VERSION 1
-#define TCL_HASH_KEY_TYPE_VERSION_2 2
struct Tcl_HashKeyType {
int version; /* Version of the table. If this structure is
@@ -1052,7 +1055,7 @@ struct Tcl_HashTable {
* table. */
size_t rebuildSize; /* Enlarge table when numEntries gets to be
* this large. */
- size_t mask; /* Mask value used in hashing function. */
+ TCL_HASH_TYPE mask1; /* Mask value used in hashing function. */
int downShift; /* Shift count used in hashing function.
* Designed to use high-order bits of
* randomized keys. */
diff --git a/generic/tclCompile.h b/generic/tclCompile.h
index db3e764..ab8edf7 100644
--- a/generic/tclCompile.h
+++ b/generic/tclCompile.h
@@ -1096,7 +1096,7 @@ MODULE_SCOPE int TclCreateExceptRange(ExceptionRangeType type,
CompileEnv *envPtr);
MODULE_SCOPE ExecEnv * TclCreateExecEnv(Tcl_Interp *interp, int size);
MODULE_SCOPE Tcl_Obj * TclCreateLiteral(Interp *iPtr, char *bytes,
- int length, unsigned int hash, int *newPtr,
+ size_t length, TCL_HASH_TYPE hash, int *newPtr,
Namespace *nsPtr, int flags,
LiteralEntry **globalPtrPtr);
MODULE_SCOPE void TclDeleteExecEnv(ExecEnv *eePtr);
diff --git a/generic/tclDictObj.c b/generic/tclDictObj.c
index e37dcb6..c172df0 100644
--- a/generic/tclDictObj.c
+++ b/generic/tclDictObj.c
@@ -179,7 +179,7 @@ const Tcl_ObjType tclDictType = {
*/
static const Tcl_HashKeyType chainHashType = {
- TCL_HASH_KEY_TYPE_VERSION_2,
+ TCL_HASH_KEY_TYPE_VERSION,
0,
TclHashObjKey,
TclCompareObjKeys,
diff --git a/generic/tclHash.c b/generic/tclHash.c
index f0d71d3..fbf5f10 100644
--- a/generic/tclHash.c
+++ b/generic/tclHash.c
@@ -28,7 +28,7 @@
*/
#define RANDOM_INDEX(tablePtr, i) \
- ((((i)*1103515245L) >> (tablePtr)->downShift) & (tablePtr)->mask)
+ ((((i)*1103515245L) >> (tablePtr)->downShift) & (tablePtr)->mask1)
/*
* Prototypes for the array hash key methods.
@@ -36,7 +36,7 @@
static Tcl_HashEntry * AllocArrayEntry(Tcl_HashTable *tablePtr, void *keyPtr);
static int CompareArrayKeys(void *keyPtr, Tcl_HashEntry *hPtr);
-static size_t HashArrayKey(Tcl_HashTable *tablePtr, void *keyPtr);
+static TCL_HASH_TYPE HashArrayKey(Tcl_HashTable *tablePtr, void *keyPtr);
/*
* Prototypes for the one word hash key methods. Not actually declared because
@@ -58,7 +58,7 @@ static size_t HashOneWordKey(Tcl_HashTable *tablePtr, const void *keyPtr);
static Tcl_HashEntry * AllocStringEntry(Tcl_HashTable *tablePtr,
void *keyPtr);
static int CompareStringKeys(void *keyPtr, Tcl_HashEntry *hPtr);
-static size_t HashStringKey(Tcl_HashTable *tablePtr, void *keyPtr);
+static TCL_HASH_TYPE HashStringKey(Tcl_HashTable *tablePtr, void *keyPtr);
/*
* Function prototypes for static functions in this file:
@@ -73,7 +73,7 @@ static Tcl_HashEntry * FindHashEntry(Tcl_HashTable *tablePtr, const void *key);
static void RebuildTable(Tcl_HashTable *tablePtr);
const Tcl_HashKeyType tclArrayHashKeyType = {
- TCL_HASH_KEY_TYPE_VERSION_2, /* version */
+ TCL_HASH_KEY_TYPE_VERSION, /* version */
TCL_HASH_KEY_RANDOMIZE_HASH, /* flags */
HashArrayKey, /* hashKeyProc */
CompareArrayKeys, /* compareKeysProc */
@@ -82,7 +82,7 @@ const Tcl_HashKeyType tclArrayHashKeyType = {
};
const Tcl_HashKeyType tclOneWordHashKeyType = {
- TCL_HASH_KEY_TYPE_VERSION_2, /* version */
+ TCL_HASH_KEY_TYPE_VERSION, /* version */
0, /* flags */
NULL, /* HashOneWordKey, */ /* hashProc */
NULL, /* CompareOneWordKey, */ /* compareProc */
@@ -91,7 +91,7 @@ const Tcl_HashKeyType tclOneWordHashKeyType = {
};
const Tcl_HashKeyType tclStringHashKeyType = {
- TCL_HASH_KEY_TYPE_VERSION_2, /* version */
+ TCL_HASH_KEY_TYPE_VERSION, /* version */
0, /* flags */
HashStringKey, /* hashKeyProc */
CompareStringKeys, /* compareKeysProc */
@@ -179,7 +179,7 @@ Tcl_InitCustomHashTable(
tablePtr->numEntries = 0;
tablePtr->rebuildSize = TCL_SMALL_HASH_TABLE*REBUILD_MULTIPLIER;
tablePtr->downShift = 28;
- tablePtr->mask = 3;
+ tablePtr->mask1 = 3;
tablePtr->keyType = keyType;
tablePtr->findProc = FindHashEntry;
tablePtr->createProc = CreateHashEntry;
@@ -243,8 +243,7 @@ CreateHashEntry(
{
register Tcl_HashEntry *hPtr;
const Tcl_HashKeyType *typePtr;
- size_t hash;
- size_t index;
+ TCL_HASH_TYPE hash, index;
if (tablePtr->keyType == TCL_STRING_KEYS) {
typePtr = &tclStringHashKeyType;
@@ -258,16 +257,11 @@ CreateHashEntry(
}
if (typePtr->hashKeyProc) {
- if (typePtr->version == TCL_HASH_KEY_TYPE_VERSION) {
- hash = ((unsigned int (*)(Tcl_HashTable *, void *))
- typePtr->hashKeyProc)(tablePtr, (void *) key);
- } else {
- hash = typePtr->hashKeyProc(tablePtr, (void *) key);
- }
+ hash = typePtr->hashKeyProc(tablePtr, (void *) key);
if (typePtr->flags & TCL_HASH_KEY_RANDOMIZE_HASH) {
index = RANDOM_INDEX(tablePtr, hash);
} else {
- index = hash & tablePtr->mask;
+ index = hash & tablePtr->mask1;
}
} else {
hash = (size_t)(key);
@@ -387,7 +381,7 @@ Tcl_DeleteHashEntry(
|| typePtr->flags & TCL_HASH_KEY_RANDOMIZE_HASH) {
index = RANDOM_INDEX(tablePtr, entryPtr->hash);
} else {
- index = entryPtr->hash & tablePtr->mask;
+ index = entryPtr->hash & tablePtr->mask1;
}
bucketPtr = &tablePtr->buckets[index];
@@ -736,13 +730,13 @@ CompareArrayKeys(
*----------------------------------------------------------------------
*/
-static size_t
+static TCL_HASH_TYPE
HashArrayKey(
Tcl_HashTable *tablePtr, /* Hash table. */
void *keyPtr) /* Key from which to compute hash value. */
{
register const int *array = (const int *) keyPtr;
- register size_t result;
+ register TCL_HASH_TYPE result;
int count;
for (result = 0, count = tablePtr->keyType; count > 0;
@@ -832,13 +826,13 @@ CompareStringKeys(
*----------------------------------------------------------------------
*/
-static size_t
+static TCL_HASH_TYPE
HashStringKey(
Tcl_HashTable *tablePtr, /* Hash table. */
void *keyPtr) /* Key from which to compute hash value. */
{
register const char *string = keyPtr;
- register size_t result;
+ register TCL_HASH_TYPE result;
register char c;
/*
@@ -960,7 +954,8 @@ static void
RebuildTable(
register Tcl_HashTable *tablePtr) /* Table to enlarge. */
{
- size_t oldSize, count, index;
+ size_t oldSize, count;
+ TCL_HASH_TYPE index;
Tcl_HashEntry **oldBuckets;
register Tcl_HashEntry **oldChainPtr, **newChainPtr;
register Tcl_HashEntry *hPtr;
@@ -999,7 +994,7 @@ RebuildTable(
}
tablePtr->rebuildSize *= 4;
tablePtr->downShift -= 2;
- tablePtr->mask = (tablePtr->mask << 2) + 3;
+ tablePtr->mask1 = (tablePtr->mask1 << 2) + 3;
/*
* Rehash all of the existing entries into the new bucket array.
@@ -1012,7 +1007,7 @@ RebuildTable(
|| typePtr->flags & TCL_HASH_KEY_RANDOMIZE_HASH) {
index = RANDOM_INDEX(tablePtr, hPtr->hash);
} else {
- index = hPtr->hash & tablePtr->mask;
+ index = hPtr->hash & tablePtr->mask1;
}
hPtr->nextPtr = tablePtr->buckets[index];
tablePtr->buckets[index] = hPtr;
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 762943b..0947afa 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -3898,7 +3898,7 @@ MODULE_SCOPE int TclObjCallVarTraces(Interp *iPtr, Var *arrayPtr,
MODULE_SCOPE int TclCompareObjKeys(void *keyPtr, Tcl_HashEntry *hPtr);
MODULE_SCOPE void TclFreeObjEntry(Tcl_HashEntry *hPtr);
-MODULE_SCOPE size_t TclHashObjKey(Tcl_HashTable *tablePtr, void *keyPtr);
+MODULE_SCOPE TCL_HASH_TYPE TclHashObjKey(Tcl_HashTable *tablePtr, void *keyPtr);
MODULE_SCOPE int TclFullFinalizationRequested(void);
diff --git a/generic/tclLiteral.c b/generic/tclLiteral.c
index 306e426..e8059f4 100644
--- a/generic/tclLiteral.c
+++ b/generic/tclLiteral.c
@@ -31,7 +31,7 @@
static int AddLocalLiteralEntry(CompileEnv *envPtr,
Tcl_Obj *objPtr, int localHash);
static void ExpandLocalLiteralArray(CompileEnv *envPtr);
-static size_t HashString(const char *string, size_t length);
+static TCL_HASH_TYPE HashString(const char *string, size_t length);
#ifdef TCL_COMPILE_DEBUG
static LiteralEntry * LookupLiteralEntry(Tcl_Interp *interp,
Tcl_Obj *objPtr);
@@ -176,8 +176,8 @@ TclCreateLiteral(
Interp *iPtr,
char *bytes, /* The start of the string. Note that this is
* not a NUL-terminated string. */
- int length, /* Number of bytes in the string. */
- unsigned hash, /* The string's hash. If -1, it will be
+ size_t length, /* Number of bytes in the string. */
+ TCL_HASH_TYPE hash, /* The string's hash. If -1, it will be
* computed here. */
int *newPtr,
Namespace *nsPtr,
@@ -193,7 +193,7 @@ TclCreateLiteral(
* Is it in the interpreter's global literal table?
*/
- if (hash == (unsigned) -1) {
+ if (hash == (TCL_HASH_TYPE) -1) {
hash = HashString(bytes, length);
}
globalHash = (hash & globalTablePtr->mask);
@@ -201,9 +201,9 @@ TclCreateLiteral(
globalPtr = globalPtr->nextPtr) {
objPtr = globalPtr->objPtr;
if ((globalPtr->nsPtr == nsPtr)
- && (objPtr->length == length) && ((length == 0)
+ && ((size_t)objPtr->length == length) && ((length == 0)
|| ((objPtr->bytes[0] == bytes[0])
- && (memcmp(objPtr->bytes, bytes, (unsigned) length) == 0)))) {
+ && (memcmp(objPtr->bytes, bytes, length) == 0)))) {
/*
* A literal was found: return it
*/
@@ -864,12 +864,12 @@ TclReleaseLiteral(
*----------------------------------------------------------------------
*/
-static size_t
+static TCL_HASH_TYPE
HashString(
register const char *string, /* String for which to compute hash value. */
size_t length) /* Number of bytes in the string. */
{
- register size_t result = 0;
+ register TCL_HASH_TYPE result = 0;
/*
* I tried a zillion different hash functions and asked many other people
@@ -938,8 +938,9 @@ RebuildLiteralTable(
register LiteralEntry *entryPtr;
LiteralEntry **bucketPtr;
const char *bytes;
- unsigned int oldSize;
- int count, index, length;
+ size_t oldSize;
+ size_t count, length;
+ TCL_HASH_TYPE index;
oldSize = tablePtr->numBuckets;
oldBuckets = tablePtr->buckets;
@@ -974,8 +975,9 @@ RebuildLiteralTable(
for (oldChainPtr=oldBuckets ; oldSize>0 ; oldSize--,oldChainPtr++) {
for (entryPtr=*oldChainPtr ; entryPtr!=NULL ; entryPtr=*oldChainPtr) {
- bytes = TclGetStringFromObj(entryPtr->objPtr, &length);
- index = (HashString(bytes, length) & tablePtr->mask);
+ bytes = TclGetString(entryPtr->objPtr);
+ length = entryPtr->objPtr->length;
+ index = HashString(bytes, length) & tablePtr->mask;
*oldChainPtr = entryPtr->nextPtr;
bucketPtr = &tablePtr->buckets[index];
diff --git a/generic/tclObj.c b/generic/tclObj.c
index dde9503..74f53cc 100644
--- a/generic/tclObj.c
+++ b/generic/tclObj.c
@@ -293,7 +293,7 @@ const Tcl_ObjType tclBignumType = {
*/
const Tcl_HashKeyType tclObjHashKeyType = {
- TCL_HASH_KEY_TYPE_VERSION_2, /* version */
+ TCL_HASH_KEY_TYPE_VERSION, /* version */
0, /* flags */
TclHashObjKey, /* hashKeyProc */
TclCompareObjKeys, /* compareKeysProc */
@@ -4049,7 +4049,7 @@ TclFreeObjEntry(
*----------------------------------------------------------------------
*/
-size_t
+TCL_HASH_TYPE
TclHashObjKey(
Tcl_HashTable *tablePtr, /* Hash table. */
void *keyPtr) /* Key from which to compute hash value. */
@@ -4057,7 +4057,7 @@ TclHashObjKey(
Tcl_Obj *objPtr = (Tcl_Obj *)keyPtr;
const char *string = TclGetString(objPtr);
size_t length = objPtr->length;
- size_t result = 0;
+ TCL_HASH_TYPE result = 0;
/*
* I tried a zillion different hash functions and asked many other people
diff --git a/generic/tclTest.c b/generic/tclTest.c
index 05383bb..fb8711a 100644
--- a/generic/tclTest.c
+++ b/generic/tclTest.c
@@ -6611,7 +6611,7 @@ TestHashSystemHashCmd(
Tcl_Obj *const objv[])
{
static const Tcl_HashKeyType hkType = {
- TCL_HASH_KEY_TYPE_VERSION_2, TCL_HASH_KEY_SYSTEM_HASH,
+ TCL_HASH_KEY_TYPE_VERSION, TCL_HASH_KEY_SYSTEM_HASH,
NULL, NULL, NULL, NULL
};
Tcl_HashTable hash;
diff --git a/generic/tclVar.c b/generic/tclVar.c
index 3031a8a..87771b2 100644
--- a/generic/tclVar.c
+++ b/generic/tclVar.c
@@ -29,7 +29,7 @@ static void FreeVarEntry(Tcl_HashEntry *hPtr);
static int CompareVarKeys(void *keyPtr, Tcl_HashEntry *hPtr);
static const Tcl_HashKeyType tclVarHashKeyType = {
- TCL_HASH_KEY_TYPE_VERSION_2, /* version */
+ TCL_HASH_KEY_TYPE_VERSION, /* version */
0, /* flags */
TclHashObjKey, /* hashKeyProc */
CompareVarKeys, /* compareKeysProc */