summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/Hash.32
-rw-r--r--generic/tcl.h25
-rw-r--r--generic/tclAssembly.c2
-rw-r--r--generic/tclCompExpr.c4
-rw-r--r--generic/tclCompile.c6
-rw-r--r--generic/tclCompile.h12
-rw-r--r--generic/tclEnsemble.c4
-rw-r--r--generic/tclHash.c74
-rw-r--r--generic/tclInt.decls8
-rw-r--r--generic/tclInt.h8
-rw-r--r--generic/tclIntDecls.h10
-rw-r--r--generic/tclLiteral.c106
-rw-r--r--generic/tclOOInt.h2
-rw-r--r--generic/tclTest.c2
14 files changed, 136 insertions, 129 deletions
diff --git a/doc/Hash.3 b/doc/Hash.3
index aa79b86..41617d3 100644
--- a/doc/Hash.3
+++ b/doc/Hash.3
@@ -259,7 +259,7 @@ typedef struct Tcl_HashKeyType {
.PP
The \fIversion\fR member is the version of the table. If this structure is
extended in future then the version can be used to distinguish between
-different structures. It should be set to \fBTCL_HASH_KEY_TYPE_VERSION\fR.
+different structures. It should be set to \fBTCL_HASH_KEY_TYPE_VERSION_2\fR.
.PP
The \fIflags\fR member is 0 or one or more of the following values OR'ed
together:
diff --git a/generic/tcl.h b/generic/tcl.h
index a8f4dd1..5035365 100644
--- a/generic/tcl.h
+++ b/generic/tcl.h
@@ -959,13 +959,11 @@ struct Tcl_HashEntry {
Tcl_HashEntry *nextPtr; /* Pointer to next entry in this hash bucket,
* or NULL for end of chain. */
Tcl_HashTable *tablePtr; /* Pointer to table containing entry. */
- void *hash; /* Hash value, stored as pointer to ensure
- * that the offsets of the fields in this
- * structure are not changed. */
+ size_t hash; /* Hash value */
ClientData clientData; /* Application stores something here with
* Tcl_SetHashValue. */
union { /* Key has one of these forms: */
- char *oneWordValue; /* One-word value for key. */
+ const void *oneWordValue; /* One-word value for key. */
Tcl_Obj *objPtr; /* Tcl_Obj * key value. */
int words[1]; /* Multiple integer words for key. The actual
* size will be as large as necessary for this
@@ -998,6 +996,7 @@ struct Tcl_HashEntry {
*/
#define TCL_HASH_KEY_TYPE_VERSION 1
+
struct Tcl_HashKeyType {
int version; /* Version of the table. If this structure is
* extended in future then the version can be
@@ -1050,23 +1049,23 @@ struct Tcl_HashTable {
Tcl_HashEntry *staticBuckets[TCL_SMALL_HASH_TABLE];
/* Bucket array used for small tables (to
* avoid mallocs and frees). */
- int numBuckets; /* Total number of buckets allocated at
+ size_t numBuckets; /* Total number of buckets allocated at
* **bucketPtr. */
- int numEntries; /* Total number of entries present in
+ size_t numEntries; /* Total number of entries present in
* table. */
- int rebuildSize; /* Enlarge table when numEntries gets to be
+ size_t rebuildSize; /* Enlarge table when numEntries gets to be
* this large. */
+ size_t mask; /* Mask value used in hashing function. */
int downShift; /* Shift count used in hashing function.
* Designed to use high-order bits of
* randomized keys. */
- int mask; /* Mask value used in hashing function. */
int keyType; /* Type of keys used in this table. It's
* either TCL_CUSTOM_KEYS, TCL_STRING_KEYS,
* TCL_ONE_WORD_KEYS, or an integer giving the
* number of ints that is the size of the
* key. */
- Tcl_HashEntry *(*findProc) (Tcl_HashTable *tablePtr, const char *key);
- Tcl_HashEntry *(*createProc) (Tcl_HashTable *tablePtr, const char *key,
+ Tcl_HashEntry *(*findProc) (Tcl_HashTable *tablePtr, const void *key);
+ Tcl_HashEntry *(*createProc) (Tcl_HashTable *tablePtr, const void *key,
int *newPtr);
const Tcl_HashKeyType *typePtr;
/* Type of the keys used in the
@@ -1080,7 +1079,7 @@ struct Tcl_HashTable {
typedef struct Tcl_HashSearch {
Tcl_HashTable *tablePtr; /* Table being searched. */
- int nextIndex; /* Index of next bucket to be enumerated after
+ size_t nextIndex; /* Index of next bucket to be enumerated after
* present one. */
Tcl_HashEntry *nextEntryPtr;/* Next entry to be enumerated in the current
* bucket. */
@@ -2364,9 +2363,9 @@ TCLAPI void Tcl_GetMemoryInfo(Tcl_DString *dsPtr);
*/
#define Tcl_FindHashEntry(tablePtr, key) \
- (*((tablePtr)->findProc))(tablePtr, (const char *)(key))
+ (*((tablePtr)->findProc))(tablePtr, key)
#define Tcl_CreateHashEntry(tablePtr, key, newPtr) \
- (*((tablePtr)->createProc))(tablePtr, (const char *)(key), newPtr)
+ (*((tablePtr)->createProc))(tablePtr, key, newPtr)
/*
*----------------------------------------------------------------------------
diff --git a/generic/tclAssembly.c b/generic/tclAssembly.c
index 7a5ffcc..ab7dcce 100644
--- a/generic/tclAssembly.c
+++ b/generic/tclAssembly.c
@@ -2884,7 +2884,7 @@ CheckJumpTableLabels(
valEntryPtr = Tcl_FindHashEntry(&assemEnvPtr->labelHash,
Tcl_GetString(symbolObj));
DEBUG_PRINT(" %s -> %s (%d)\n",
- (char*) Tcl_GetHashKey(symHash, symEntryPtr),
+ Tcl_GetHashKey(symHash, symEntryPtr),
Tcl_GetString(symbolObj), (valEntryPtr != NULL));
if (valEntryPtr == NULL) {
ReportUndefinedLabel(assemEnvPtr, bbPtr, symbolObj);
diff --git a/generic/tclCompExpr.c b/generic/tclCompExpr.c
index 0f1a22a..8b07fd0 100644
--- a/generic/tclCompExpr.c
+++ b/generic/tclCompExpr.c
@@ -498,7 +498,7 @@ typedef struct JumpList {
*/
static void CompileExprTree(Tcl_Interp *interp, OpNode *nodes,
- int index, Tcl_Obj *const **litObjvPtr,
+ unsigned int index, Tcl_Obj *const **litObjvPtr,
Tcl_Obj *const *funcObjv, Tcl_Token *tokenPtr,
CompileEnv *envPtr, int optimize);
static void ConvertTreeToTokens(const char *start, int numBytes,
@@ -2230,7 +2230,7 @@ static void
CompileExprTree(
Tcl_Interp *interp,
OpNode *nodes,
- int index,
+ unsigned int index,
Tcl_Obj *const **litObjvPtr,
Tcl_Obj *const *funcObjv,
Tcl_Token *tokenPtr,
diff --git a/generic/tclCompile.c b/generic/tclCompile.c
index f758462..c8c71ee 100644
--- a/generic/tclCompile.c
+++ b/generic/tclCompile.c
@@ -1630,7 +1630,7 @@ TclFreeCompileEnv(
* have transferred to it.
*/
- int i;
+ size_t i;
LiteralEntry *entryPtr = envPtr->literalArrayPtr;
AuxData *auxDataPtr = envPtr->auxDataArrayPtr;
@@ -2713,7 +2713,7 @@ PreventCycle(
Tcl_Obj *objPtr,
CompileEnv *envPtr)
{
- int i;
+ size_t i;
for (i = 0; i < envPtr->literalArrayNext; i++) {
if (objPtr == TclFetchLiteral(envPtr, i)) {
@@ -3683,7 +3683,7 @@ TclCreateAuxData(
register CompileEnv *envPtr)/* Points to the CompileEnv for which a new
* aux data structure is to be allocated. */
{
- int index; /* Index for the new AuxData structure. */
+ size_t index; /* Index for the new AuxData structure. */
register AuxData *auxDataPtr;
/* Points to the new AuxData structure */
diff --git a/generic/tclCompile.h b/generic/tclCompile.h
index ab8edf7..dddf0a6 100644
--- a/generic/tclCompile.h
+++ b/generic/tclCompile.h
@@ -318,8 +318,8 @@ typedef struct CompileEnv {
* codeStart points into the heap.*/
LiteralEntry *literalArrayPtr;
/* Points to start of LiteralEntry array. */
- int literalArrayNext; /* Index of next free object array entry. */
- int literalArrayEnd; /* Index just after last obj array entry. */
+ size_t literalArrayNext; /* Index of next free object array entry. */
+ size_t literalArrayEnd; /* Index just after last obj array entry. */
int mallocedLiteralArray; /* 1 if object array was expanded and objArray
* points into the heap, else 0. */
ExceptionRange *exceptArrayPtr;
@@ -346,11 +346,11 @@ typedef struct CompileEnv {
int mallocedCmdMap; /* 1 if command map array was expanded and
* cmdMapPtr points in the heap, else 0. */
AuxData *auxDataArrayPtr; /* Points to auxiliary data array start. */
- int auxDataArrayNext; /* Next free compile aux data array index.
+ size_t auxDataArrayNext; /* Next free compile aux data array index.
* auxDataArrayNext is the number of aux data
* items and (auxDataArrayNext-1) is index of
* current aux data array entry. */
- int auxDataArrayEnd; /* Index after last aux data array entry. */
+ size_t auxDataArrayEnd; /* Index after last aux data array entry. */
int mallocedAuxDataArray; /* 1 if aux data array was expanded and
* auxDataArrayPtr points in heap else 0. */
unsigned char staticCodeSpace[COMPILEENV_INIT_CODE_BYTES];
@@ -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,
- size_t length, TCL_HASH_TYPE hash, int *newPtr,
+ size_t length, size_t hash, int *newPtr,
Namespace *nsPtr, int flags,
LiteralEntry **globalPtrPtr);
MODULE_SCOPE void TclDeleteExecEnv(ExecEnv *eePtr);
@@ -1110,7 +1110,7 @@ MODULE_SCOPE ExceptionRange * TclGetExceptionRangeForPc(unsigned char *pc,
MODULE_SCOPE void TclExpandJumpFixupArray(JumpFixupArray *fixupArrayPtr);
MODULE_SCOPE int TclNRExecuteByteCode(Tcl_Interp *interp,
ByteCode *codePtr);
-MODULE_SCOPE Tcl_Obj * TclFetchLiteral(CompileEnv *envPtr, unsigned int index);
+MODULE_SCOPE Tcl_Obj * TclFetchLiteral(CompileEnv *envPtr, size_t index);
MODULE_SCOPE int TclFindCompiledLocal(const char *name, int nameChars,
int create, CompileEnv *envPtr);
MODULE_SCOPE int TclFixupForwardJump(CompileEnv *envPtr,
diff --git a/generic/tclEnsemble.c b/generic/tclEnsemble.c
index c4c773e..f7931ac 100644
--- a/generic/tclEnsemble.c
+++ b/generic/tclEnsemble.c
@@ -1931,7 +1931,7 @@ NsEnsembleImplementationCmdNR(
if (ensemblePtr->subcommandTable.numEntries == 1) {
Tcl_AppendToObj(errorObj, ensemblePtr->subcommandArrayPtr[0], -1);
} else {
- int i;
+ size_t i;
for (i=0 ; i<ensemblePtr->subcommandTable.numEntries-1 ; i++) {
Tcl_AppendToObj(errorObj, ensemblePtr->subcommandArrayPtr[i], -1);
@@ -3174,7 +3174,7 @@ TclAttemptCompileProc(
Tcl_Token *saveTokenPtr = parsePtr->tokenPtr;
int savedStackDepth = envPtr->currStackDepth;
unsigned savedCodeNext = envPtr->codeNext - envPtr->codeStart;
- int savedAuxDataArrayNext = envPtr->auxDataArrayNext;
+ size_t savedAuxDataArrayNext = envPtr->auxDataArrayNext;
int savedExceptArrayNext = envPtr->exceptArrayNext;
#ifdef TCL_COMPILE_DEBUG
int savedExceptDepth = envPtr->exceptDepth;
diff --git a/generic/tclHash.c b/generic/tclHash.c
index 66b1b79..52f35ce 100644
--- a/generic/tclHash.c
+++ b/generic/tclHash.c
@@ -48,7 +48,7 @@ static TCL_HASH_TYPE HashArrayKey(Tcl_HashTable *tablePtr, void *keyPtr);
static Tcl_HashEntry * AllocOneWordEntry(Tcl_HashTable *tablePtr,
void *keyPtr);
static int CompareOneWordKeys(void *keyPtr, Tcl_HashEntry *hPtr);
-static unsigned int HashOneWordKey(Tcl_HashTable *tablePtr, void *keyPtr);
+static size_t HashOneWordKey(Tcl_HashTable *tablePtr, const void *keyPtr);
#endif
/*
@@ -64,12 +64,12 @@ static TCL_HASH_TYPE HashStringKey(Tcl_HashTable *tablePtr, void *keyPtr);
* Function prototypes for static functions in this file:
*/
-static Tcl_HashEntry * BogusFind(Tcl_HashTable *tablePtr, const char *key);
-static Tcl_HashEntry * BogusCreate(Tcl_HashTable *tablePtr, const char *key,
+static Tcl_HashEntry * BogusFind(Tcl_HashTable *tablePtr, const void *key);
+static Tcl_HashEntry * BogusCreate(Tcl_HashTable *tablePtr, const void *key,
int *newPtr);
-static Tcl_HashEntry * CreateHashEntry(Tcl_HashTable *tablePtr, const char *key,
+static Tcl_HashEntry * CreateHashEntry(Tcl_HashTable *tablePtr, const void *key,
int *newPtr);
-static Tcl_HashEntry * FindHashEntry(Tcl_HashTable *tablePtr, const char *key);
+static Tcl_HashEntry * FindHashEntry(Tcl_HashTable *tablePtr, const void *key);
static void RebuildTable(Tcl_HashTable *tablePtr);
const Tcl_HashKeyType tclArrayHashKeyType = {
@@ -206,7 +206,7 @@ Tcl_InitCustomHashTable(
static Tcl_HashEntry *
FindHashEntry(
Tcl_HashTable *tablePtr, /* Table in which to lookup entry. */
- const char *key) /* Key to use to find matching entry. */
+ const void *key) /* Key to use to find matching entry. */
{
return CreateHashEntry(tablePtr, key, NULL);
}
@@ -236,15 +236,14 @@ FindHashEntry(
static Tcl_HashEntry *
CreateHashEntry(
Tcl_HashTable *tablePtr, /* Table in which to lookup entry. */
- const char *key, /* Key to use to find or create matching
+ const void *key, /* Key to use to find or create matching
* entry. */
int *newPtr) /* Store info here telling whether a new entry
* was created. */
{
register Tcl_HashEntry *hPtr;
const Tcl_HashKeyType *typePtr;
- unsigned int hash;
- int index;
+ size_t hash, index;
if (tablePtr->keyType == TCL_STRING_KEYS) {
typePtr = &tclStringHashKeyType;
@@ -265,7 +264,7 @@ CreateHashEntry(
index = hash & tablePtr->mask;
}
} else {
- hash = PTR2UINT(key);
+ hash = (size_t)(key);
index = RANDOM_INDEX(tablePtr, hash);
}
@@ -278,7 +277,7 @@ CreateHashEntry(
for (hPtr = tablePtr->buckets[index]; hPtr != NULL;
hPtr = hPtr->nextPtr) {
- if (hash != PTR2UINT(hPtr->hash)) {
+ if (hash != hPtr->hash) {
continue;
}
if (((void *) key == hPtr) || compareKeysProc((void *) key, hPtr)) {
@@ -291,7 +290,7 @@ CreateHashEntry(
} else {
for (hPtr = tablePtr->buckets[index]; hPtr != NULL;
hPtr = hPtr->nextPtr) {
- if (hash != PTR2UINT(hPtr->hash)) {
+ if (hash != hPtr->hash) {
continue;
}
if (key == hPtr->key.oneWordValue) {
@@ -316,12 +315,12 @@ CreateHashEntry(
hPtr = typePtr->allocEntryProc(tablePtr, (void *) key);
} else {
hPtr = ckalloc(sizeof(Tcl_HashEntry));
- hPtr->key.oneWordValue = (char *) key;
+ hPtr->key.oneWordValue = key;
hPtr->clientData = 0;
}
hPtr->tablePtr = tablePtr;
- hPtr->hash = UINT2PTR(hash);
+ hPtr->hash = hash;
hPtr->nextPtr = tablePtr->buckets[index];
tablePtr->buckets[index] = hPtr;
tablePtr->numEntries++;
@@ -363,7 +362,7 @@ Tcl_DeleteHashEntry(
const Tcl_HashKeyType *typePtr;
Tcl_HashTable *tablePtr;
Tcl_HashEntry **bucketPtr;
- int index;
+ size_t index;
tablePtr = entryPtr->tablePtr;
@@ -380,9 +379,9 @@ Tcl_DeleteHashEntry(
if (typePtr->hashKeyProc == NULL
|| typePtr->flags & TCL_HASH_KEY_RANDOMIZE_HASH) {
- index = RANDOM_INDEX(tablePtr, PTR2INT(entryPtr->hash));
+ index = RANDOM_INDEX(tablePtr, entryPtr->hash);
} else {
- index = PTR2UINT(entryPtr->hash) & tablePtr->mask;
+ index = entryPtr->hash & tablePtr->mask;
}
bucketPtr = &tablePtr->buckets[index];
@@ -432,7 +431,7 @@ Tcl_DeleteHashTable(
{
register Tcl_HashEntry *hPtr, *nextPtr;
const Tcl_HashKeyType *typePtr;
- int i;
+ size_t i;
if (tablePtr->keyType == TCL_STRING_KEYS) {
typePtr = &tclStringHashKeyType;
@@ -581,7 +580,7 @@ Tcl_HashStats(
Tcl_HashTable *tablePtr) /* Table for which to produce stats. */
{
#define NUM_COUNTERS 10
- int count[NUM_COUNTERS], overflow, i, j;
+ size_t count[NUM_COUNTERS], overflow, i, j;
double average, tmp;
register Tcl_HashEntry *hPtr;
char *result, *p;
@@ -616,16 +615,16 @@ Tcl_HashStats(
*/
result = ckalloc((NUM_COUNTERS * 60) + 300);
- sprintf(result, "%d entries in table, %d buckets\n",
- tablePtr->numEntries, tablePtr->numBuckets);
+ sprintf(result, "%" TCL_LL_MODIFIER "d entries in table, %" TCL_LL_MODIFIER "d buckets\n",
+ (Tcl_WideInt)tablePtr->numEntries, (Tcl_WideInt)tablePtr->numBuckets);
p = result + strlen(result);
for (i = 0; i < NUM_COUNTERS; i++) {
- sprintf(p, "number of buckets with %d entries: %d\n",
- i, count[i]);
+ sprintf(p, "number of buckets with %d entries: %" TCL_LL_MODIFIER "d\n",
+ (int)i, (Tcl_WideInt)count[i]);
p += strlen(p);
}
- sprintf(p, "number of buckets with %d or more entries: %d\n",
- NUM_COUNTERS, overflow);
+ sprintf(p, "number of buckets with %d or more entries: %" TCL_LL_MODIFIER "d\n",
+ NUM_COUNTERS, (Tcl_WideInt)overflow);
p += strlen(p);
sprintf(p, "average search distance for entry: %.1f", average);
return result;
@@ -656,7 +655,7 @@ AllocArrayEntry(
register int *iPtr1, *iPtr2;
Tcl_HashEntry *hPtr;
int count;
- unsigned int size;
+ size_t size;
count = tablePtr->keyType;
@@ -768,9 +767,9 @@ AllocStringEntry(
Tcl_HashTable *tablePtr, /* Hash table. */
void *keyPtr) /* Key to store in the hash table entry. */
{
- const char *string = (const char *) keyPtr;
+ const char *string = keyPtr;
Tcl_HashEntry *hPtr;
- unsigned int size, allocsize;
+ size_t size, allocsize;
allocsize = size = strlen(string) + 1;
if (size < sizeof(hPtr->key)) {
@@ -804,8 +803,8 @@ CompareStringKeys(
void *keyPtr, /* New key to compare. */
Tcl_HashEntry *hPtr) /* Existing key to compare. */
{
- register const char *p1 = (const char *) keyPtr;
- register const char *p2 = (const char *) hPtr->key.string;
+ register const char *p1 = keyPtr;
+ register const char *p2 = hPtr->key.string;
return !strcmp(p1, p2);
}
@@ -897,7 +896,7 @@ HashStringKey(
static Tcl_HashEntry *
BogusFind(
Tcl_HashTable *tablePtr, /* Table in which to lookup entry. */
- const char *key) /* Key to use to find matching entry. */
+ const void *key) /* Key to use to find matching entry. */
{
Tcl_Panic("called %s on deleted table", "Tcl_FindHashEntry");
return NULL;
@@ -924,7 +923,7 @@ BogusFind(
static Tcl_HashEntry *
BogusCreate(
Tcl_HashTable *tablePtr, /* Table in which to lookup entry. */
- const char *key, /* Key to use to find or create matching
+ const void *key, /* Key to use to find or create matching
* entry. */
int *newPtr) /* Store info here telling whether a new entry
* was created. */
@@ -955,7 +954,8 @@ static void
RebuildTable(
register Tcl_HashTable *tablePtr) /* Table to enlarge. */
{
- int oldSize, count, index;
+ size_t oldSize, count;
+ size_t index;
Tcl_HashEntry **oldBuckets;
register Tcl_HashEntry **oldChainPtr, **newChainPtr;
register Tcl_HashEntry *hPtr;
@@ -982,8 +982,8 @@ RebuildTable(
tablePtr->numBuckets *= 4;
if (typePtr->flags & TCL_HASH_KEY_SYSTEM_HASH) {
- tablePtr->buckets = (Tcl_HashEntry **) TclpSysAlloc((unsigned)
- (tablePtr->numBuckets * sizeof(Tcl_HashEntry *)), 0);
+ tablePtr->buckets = (Tcl_HashEntry **) TclpSysAlloc(
+ tablePtr->numBuckets * sizeof(Tcl_HashEntry *), 0);
} else {
tablePtr->buckets =
ckalloc(tablePtr->numBuckets * sizeof(Tcl_HashEntry *));
@@ -1005,9 +1005,9 @@ RebuildTable(
*oldChainPtr = hPtr->nextPtr;
if (typePtr->hashKeyProc == NULL
|| typePtr->flags & TCL_HASH_KEY_RANDOMIZE_HASH) {
- index = RANDOM_INDEX(tablePtr, PTR2INT(hPtr->hash));
+ index = RANDOM_INDEX(tablePtr, hPtr->hash);
} else {
- index = PTR2UINT(hPtr->hash) & tablePtr->mask;
+ index = hPtr->hash & tablePtr->mask;
}
hPtr->nextPtr = tablePtr->buckets[index];
tablePtr->buckets[index] = hPtr;
diff --git a/generic/tclInt.decls b/generic/tclInt.decls
index 5b69ed8..d308eec 100644
--- a/generic/tclInt.decls
+++ b/generic/tclInt.decls
@@ -584,8 +584,8 @@ declare 142 {
CompileHookProc *hookProc, ClientData clientData)
}
declare 143 {
- int TclAddLiteralObj(struct CompileEnv *envPtr, Tcl_Obj *objPtr,
- LiteralEntry **litPtrPtr)
+ unsigned int TclAddLiteralObj(struct CompileEnv *envPtr,
+ Tcl_Obj *objPtr, LiteralEntry **litPtrPtr)
}
declare 144 {
void TclHideLiteral(Tcl_Interp *interp, struct CompileEnv *envPtr,
@@ -1023,8 +1023,8 @@ declare 250 {
# Allow extensions for optimization
declare 251 {
- int TclRegisterLiteral(void *envPtr,
- char *bytes, int length, int flags)
+ unsigned int TclRegisterLiteral(void *envPtr,
+ char *bytes, size_t length, int flags)
}
##############################################################################
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 8a88b72..ea5e124 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -1497,13 +1497,13 @@ typedef struct LiteralTable {
LiteralEntry *staticBuckets[TCL_SMALL_HASH_TABLE];
/* Bucket array used for small tables to avoid
* mallocs and frees. */
- int numBuckets; /* Total number of buckets allocated at
+ size_t numBuckets; /* Total number of buckets allocated at
* **buckets. */
- int numEntries; /* Total number of entries present in
+ size_t numEntries; /* Total number of entries present in
* table. */
- int rebuildSize; /* Enlarge table when numEntries gets to be
+ size_t rebuildSize; /* Enlarge table when numEntries gets to be
* this large. */
- int mask; /* Mask value used in hashing function. */
+ size_t mask; /* Mask value used in hashing function. */
} LiteralTable;
/*
diff --git a/generic/tclIntDecls.h b/generic/tclIntDecls.h
index 7b0a0e0..38b6520 100644
--- a/generic/tclIntDecls.h
+++ b/generic/tclIntDecls.h
@@ -310,7 +310,7 @@ TCLAPI int TclSetByteCodeFromAny(Tcl_Interp *interp,
Tcl_Obj *objPtr, CompileHookProc *hookProc,
ClientData clientData);
/* 143 */
-TCLAPI int TclAddLiteralObj(struct CompileEnv *envPtr,
+TCLAPI unsigned int TclAddLiteralObj(struct CompileEnv *envPtr,
Tcl_Obj *objPtr, LiteralEntry **litPtrPtr);
/* 144 */
TCLAPI void TclHideLiteral(Tcl_Interp *interp,
@@ -547,8 +547,8 @@ TCLAPI char * TclDoubleDigits(double dv, int ndigits, int flags,
TCLAPI void TclSetSlaveCancelFlags(Tcl_Interp *interp, int flags,
int force);
/* 251 */
-TCLAPI int TclRegisterLiteral(void *envPtr, char *bytes,
- int length, int flags);
+TCLAPI unsigned int TclRegisterLiteral(void *envPtr, char *bytes,
+ size_t length, int flags);
typedef struct TclIntStubs {
int magic;
@@ -697,7 +697,7 @@ typedef struct TclIntStubs {
void (*reserved140)(void);
const char * (*tclpGetCwd) (Tcl_Interp *interp, Tcl_DString *cwdPtr); /* 141 */
int (*tclSetByteCodeFromAny) (Tcl_Interp *interp, Tcl_Obj *objPtr, CompileHookProc *hookProc, ClientData clientData); /* 142 */
- int (*tclAddLiteralObj) (struct CompileEnv *envPtr, Tcl_Obj *objPtr, LiteralEntry **litPtrPtr); /* 143 */
+ unsigned int (*tclAddLiteralObj) (struct CompileEnv *envPtr, Tcl_Obj *objPtr, LiteralEntry **litPtrPtr); /* 143 */
void (*tclHideLiteral) (Tcl_Interp *interp, struct CompileEnv *envPtr, int index); /* 144 */
const struct AuxDataType * (*tclGetAuxDataType) (const char *typeName); /* 145 */
TclHandle (*tclHandleCreate) (void *ptr); /* 146 */
@@ -805,7 +805,7 @@ typedef struct TclIntStubs {
int (*tclCopyChannel) (Tcl_Interp *interp, Tcl_Channel inChan, Tcl_Channel outChan, Tcl_WideInt toRead, Tcl_Obj *cmdPtr); /* 248 */
char * (*tclDoubleDigits) (double dv, int ndigits, int flags, int *decpt, int *signum, char **endPtr); /* 249 */
void (*tclSetSlaveCancelFlags) (Tcl_Interp *interp, int flags, int force); /* 250 */
- int (*tclRegisterLiteral) (void *envPtr, char *bytes, int length, int flags); /* 251 */
+ unsigned int (*tclRegisterLiteral) (void *envPtr, char *bytes, size_t length, int flags); /* 251 */
} TclIntStubs;
extern const TclIntStubs *tclIntStubsPtr;
diff --git a/generic/tclLiteral.c b/generic/tclLiteral.c
index 3864ad5..7fd1e5a 100644
--- a/generic/tclLiteral.c
+++ b/generic/tclLiteral.c
@@ -28,10 +28,10 @@
* Function prototypes for static functions in this file:
*/
-static int AddLocalLiteralEntry(CompileEnv *envPtr,
- Tcl_Obj *objPtr, int localHash);
+static unsigned int AddLocalLiteralEntry(CompileEnv *envPtr,
+ Tcl_Obj *objPtr, size_t localHash);
static void ExpandLocalLiteralArray(CompileEnv *envPtr);
-static unsigned HashString(const char *string, int length);
+static size_t HashString(const char *string, size_t length);
#ifdef TCL_COMPILE_DEBUG
static LiteralEntry * LookupLiteralEntry(Tcl_Interp *interp,
Tcl_Obj *objPtr);
@@ -104,7 +104,7 @@ TclDeleteLiteralTable(
{
LiteralEntry *entryPtr, *nextPtr;
Tcl_Obj *objPtr;
- int i;
+ size_t i;
/*
* Release remaining literals in the table. Note that releasing a literal
@@ -177,7 +177,7 @@ TclCreateLiteral(
char *bytes, /* The start of the string. Note that this is
* not a NUL-terminated string. */
size_t length, /* Number of bytes in the string. */
- TCL_HASH_TYPE hash, /* The string's hash. If -1, it will be
+ size_t hash, /* The string's hash. If -1, it will be
* computed here. */
int *newPtr,
Namespace *nsPtr,
@@ -186,14 +186,14 @@ TclCreateLiteral(
{
LiteralTable *globalTablePtr = &iPtr->literalTable;
LiteralEntry *globalPtr;
- TCL_HASH_TYPE globalHash;
+ size_t globalHash;
Tcl_Obj *objPtr;
/*
* Is it in the interpreter's global literal table?
*/
- if (hash == (TCL_HASH_TYPE) -1) {
+ if (hash == (size_t) -1) {
hash = HashString(bytes, length);
}
globalHash = (hash & globalTablePtr->mask);
@@ -320,10 +320,10 @@ Tcl_Obj *
TclFetchLiteral(
CompileEnv *envPtr, /* Points to the CompileEnv from which to
* fetch the registered literal value. */
- unsigned int index) /* Index of the desired literal, as returned
+ size_t index) /* Index of the desired literal, as returned
* by prior call to TclRegisterLiteral() */
{
- if (index >= (unsigned int) envPtr->literalArrayNext) {
+ if (index >= envPtr->literalArrayNext) {
return NULL;
}
return envPtr->literalArrayPtr[index].objPtr;
@@ -356,14 +356,14 @@ TclFetchLiteral(
*----------------------------------------------------------------------
*/
-int
+unsigned int
TclRegisterLiteral(
void *ePtr, /* Points to the CompileEnv in whose object
* array an object is found or created. */
register char *bytes, /* Points to string for which to find or
* create an object in CompileEnv's object
* array. */
- int length, /* Number of bytes in the string. If < 0, the
+ size_t length, /* Number of bytes in the string. If < 0, the
* string consists of all bytes up to the
* first null character. */
int flags) /* If LITERAL_ON_HEAP then the caller already
@@ -377,12 +377,14 @@ TclRegisterLiteral(
LiteralTable *localTablePtr = &envPtr->localLitTable;
LiteralEntry *globalPtr, *localPtr;
Tcl_Obj *objPtr;
- unsigned hash;
- int localHash, objIndex, new;
+ size_t hash;
+ size_t localHash;
+ unsigned int objIndex;
+ int new;
Namespace *nsPtr;
- if (length < 0) {
- length = (bytes ? strlen(bytes) : 0);
+ if (length == (size_t)-1) {
+ length = bytes ? strlen(bytes) : 0;
}
hash = HashString(bytes, length);
@@ -395,9 +397,9 @@ TclRegisterLiteral(
for (localPtr=localTablePtr->buckets[localHash] ; localPtr!=NULL;
localPtr = localPtr->nextPtr) {
objPtr = localPtr->objPtr;
- if ((objPtr->length == length) && ((length == 0)
+ if (((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)))) {
if (flags & LITERAL_ON_HEAP) {
ckfree(bytes);
}
@@ -476,9 +478,10 @@ LookupLiteralEntry(
LiteralTable *globalTablePtr = &iPtr->literalTable;
register LiteralEntry *entryPtr;
const char *bytes;
- int length, globalHash;
+ size_t length, globalHash;
- bytes = TclGetStringFromObj(objPtr, &length);
+ bytes = TclGetString(objPtr);
+ length = objPtr->length;
globalHash = (HashString(bytes, length) & globalTablePtr->mask);
for (entryPtr=globalTablePtr->buckets[globalHash] ; entryPtr!=NULL;
entryPtr=entryPtr->nextPtr) {
@@ -539,8 +542,9 @@ TclHideLiteral(
TclReleaseLiteral(interp, lPtr->objPtr);
lPtr->objPtr = newObjPtr;
- bytes = TclGetStringFromObj(newObjPtr, &length);
- localHash = (HashString(bytes, length) & localTablePtr->mask);
+ bytes = TclGetString(newObjPtr);
+ length = newObjPtr->length;
+ localHash = HashString(bytes, length) & localTablePtr->mask;
nextPtrPtr = &localTablePtr->buckets[localHash];
for (entryPtr=*nextPtrPtr ; entryPtr!=NULL ; entryPtr=*nextPtrPtr) {
@@ -575,7 +579,7 @@ TclHideLiteral(
*----------------------------------------------------------------------
*/
-int
+unsigned int
TclAddLiteralObj(
register CompileEnv *envPtr,/* Points to CompileEnv in whose literal array
* the object is to be inserted. */
@@ -585,7 +589,7 @@ TclAddLiteralObj(
* NULL. */
{
register LiteralEntry *lPtr;
- int objIndex;
+ unsigned int objIndex;
if (envPtr->literalArrayNext >= envPtr->literalArrayEnd) {
ExpandLocalLiteralArray(envPtr);
@@ -624,16 +628,16 @@ TclAddLiteralObj(
*----------------------------------------------------------------------
*/
-static int
+static unsigned int
AddLocalLiteralEntry(
register CompileEnv *envPtr,/* Points to CompileEnv in whose literal array
* the object is to be inserted. */
Tcl_Obj *objPtr, /* The literal to add to the CompileEnv. */
- int localHash) /* Hash value for the literal's string. */
+ size_t localHash) /* Hash value for the literal's string. */
{
register LiteralTable *localTablePtr = &envPtr->localLitTable;
LiteralEntry *localPtr;
- int objIndex;
+ unsigned int objIndex;
objIndex = TclAddLiteralObj(envPtr, objPtr, &localPtr);
@@ -658,7 +662,8 @@ AddLocalLiteralEntry(
TclVerifyLocalLiteralTable(envPtr);
{
char *bytes;
- int length, found, i;
+ size_t length, i;
+ int found;
found = 0;
for (i=0 ; i<localTablePtr->numBuckets ; i++) {
@@ -671,9 +676,10 @@ AddLocalLiteralEntry(
}
if (!found) {
- bytes = TclGetStringFromObj(objPtr, &length);
+ bytes = TclGetString(objPtr);
+ length = objPtr->length;
Tcl_Panic("%s: literal \"%.*s\" wasn't found locally",
- "AddLocalLiteralEntry", (length>60? 60 : length), bytes);
+ "AddLocalLiteralEntry", (length>60? 60 : (int)length), bytes);
}
}
#endif /*TCL_COMPILE_DEBUG*/
@@ -712,16 +718,15 @@ ExpandLocalLiteralArray(
*/
LiteralTable *localTablePtr = &envPtr->localLitTable;
- int currElems = envPtr->literalArrayNext;
+ size_t currElems = envPtr->literalArrayNext;
size_t currBytes = (currElems * sizeof(LiteralEntry));
LiteralEntry *currArrayPtr = envPtr->literalArrayPtr;
LiteralEntry *newArrayPtr;
- int i;
- unsigned int newSize = (currBytes <= UINT_MAX / 2) ? 2*currBytes : UINT_MAX;
+ size_t i;
+ size_t newSize = (currBytes <= UINT_MAX / 2) ? 2*currBytes : UINT_MAX;
if (currBytes == newSize) {
- Tcl_Panic("max size of Tcl literal array (%d literals) exceeded",
- currElems);
+ Tcl_Panic("max size of Tcl literal array exceeded");
}
if (envPtr->mallocedLiteralArray) {
@@ -793,15 +798,16 @@ TclReleaseLiteral(
LiteralTable *globalTablePtr;
register LiteralEntry *entryPtr, *prevPtr;
const char *bytes;
- int length, index;
+ size_t length, index;
if (iPtr == NULL) {
goto done;
}
globalTablePtr = &iPtr->literalTable;
- bytes = TclGetStringFromObj(objPtr, &length);
- index = (HashString(bytes, length) & globalTablePtr->mask);
+ bytes = TclGetString(objPtr);
+ length = objPtr->length;
+ index = HashString(bytes, length) & globalTablePtr->mask;
/*
* Check to see if the object is in the global literal table and remove
@@ -864,12 +870,12 @@ TclReleaseLiteral(
*----------------------------------------------------------------------
*/
-static unsigned
+static size_t
HashString(
register const char *string, /* String for which to compute hash value. */
- int length) /* Number of bytes in the string. */
+ size_t length) /* Number of bytes in the string. */
{
- register unsigned int result = 0;
+ register size_t result = 0;
/*
* I tried a zillion different hash functions and asked many other people
@@ -938,8 +944,9 @@ RebuildLiteralTable(
register LiteralEntry *entryPtr;
LiteralEntry **bucketPtr;
const char *bytes;
- unsigned int oldSize;
- int count, index, length;
+ size_t oldSize;
+ size_t count, length;
+ size_t index;
oldSize = tablePtr->numBuckets;
oldBuckets = tablePtr->buckets;
@@ -974,8 +981,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];
@@ -1062,7 +1070,7 @@ TclLiteralStats(
LiteralTable *tablePtr) /* Table for which to produce stats. */
{
#define NUM_COUNTERS 10
- int count[NUM_COUNTERS], overflow, i, j;
+ size_t count[NUM_COUNTERS], overflow, i, j;
double average, tmp;
register LiteralEntry *entryPtr;
char *result, *p;
@@ -1138,8 +1146,8 @@ TclVerifyLocalLiteralTable(
register LiteralTable *localTablePtr = &envPtr->localLitTable;
register LiteralEntry *localPtr;
char *bytes;
- register int i;
- int length, count;
+ register size_t i;
+ size_t length, count;
count = 0;
for (i=0 ; i<localTablePtr->numBuckets ; i++) {
@@ -1150,14 +1158,14 @@ TclVerifyLocalLiteralTable(
bytes = TclGetStringFromObj(localPtr->objPtr, &length);
Tcl_Panic("%s: local literal \"%.*s\" had bad refCount %d",
"TclVerifyLocalLiteralTable",
- (length>60? 60 : length), bytes, localPtr->refCount);
+ (length>60? 60 : (int)length), bytes, localPtr->refCount);
}
if (LookupLiteralEntry((Tcl_Interp *) envPtr->iPtr,
localPtr->objPtr) == NULL) {
bytes = TclGetStringFromObj(localPtr->objPtr, &length);
Tcl_Panic("%s: local literal \"%.*s\" is not global",
"TclVerifyLocalLiteralTable",
- (length>60? 60 : length), bytes);
+ (length>60? 60 : (int)length), bytes);
}
if (localPtr->objPtr->bytes == NULL) {
Tcl_Panic("%s: literal has NULL string rep",
diff --git a/generic/tclOOInt.h b/generic/tclOOInt.h
index b75ffdb..cda1826 100644
--- a/generic/tclOOInt.h
+++ b/generic/tclOOInt.h
@@ -563,7 +563,7 @@ MODULE_SCOPE void TclOOSetupVariableResolver(Tcl_Namespace *nsPtr);
Tcl_HashEntry *hPtr;Tcl_HashSearch search
#define FOREACH_HASH(key,val,tablePtr) \
for(hPtr=Tcl_FirstHashEntry((tablePtr),&search); hPtr!=NULL ? \
- ((key)=(void *)Tcl_GetHashKey((tablePtr),hPtr),\
+ ((key)=Tcl_GetHashKey((tablePtr),hPtr),\
(val)=Tcl_GetHashValue(hPtr),1):0; hPtr=Tcl_NextHashEntry(&search))
#define FOREACH_HASH_VALUE(val,tablePtr) \
for(hPtr=Tcl_FirstHashEntry((tablePtr),&search); hPtr!=NULL ? \
diff --git a/generic/tclTest.c b/generic/tclTest.c
index f2a948a..fb8711a 100644
--- a/generic/tclTest.c
+++ b/generic/tclTest.c
@@ -6641,7 +6641,7 @@ TestHashSystemHashCmd(
Tcl_SetHashValue(hPtr, INT2PTR(i+42));
}
- if (hash.numEntries != limit) {
+ if (hash.numEntries != (size_t)limit) {
Tcl_AppendResult(interp, "unexpected maximal size", NULL);
Tcl_DeleteHashTable(&hash);
return TCL_ERROR;