summaryrefslogtreecommitdiffstats
path: root/generic/tclLiteral.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclLiteral.c')
-rw-r--r--generic/tclLiteral.c500
1 files changed, 249 insertions, 251 deletions
diff --git a/generic/tclLiteral.c b/generic/tclLiteral.c
index 962856e..c4bf5ee 100644
--- a/generic/tclLiteral.c
+++ b/generic/tclLiteral.c
@@ -1,26 +1,26 @@
-/*
+/*
* tclLiteral.c --
*
- * Implementation of the global and ByteCode-local literal tables
- * used to manage the Tcl objects created for literal values during
- * compilation of Tcl scripts. This implementation borrows heavily
- * from the more general hashtable implementation of Tcl hash tables
- * that appears in tclHash.c.
+ * Implementation of the global and ByteCode-local literal tables used to
+ * manage the Tcl objects created for literal values during compilation
+ * of Tcl scripts. This implementation borrows heavily from the more
+ * general hashtable implementation of Tcl hash tables that appears in
+ * tclHash.c.
*
* Copyright (c) 1997-1998 Sun Microsystems, Inc.
* Copyright (c) 2004 by Kevin B. Kenny. All rights reserved.
*
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution of
+ * this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclLiteral.c,v 1.24 2005/05/10 18:34:44 kennykb Exp $
+ * RCS: @(#) $Id: tclLiteral.c,v 1.25 2005/07/19 00:09:07 dkf Exp $
*/
#include "tclInt.h"
#include "tclCompile.h"
/*
- * When there are this many entries per bucket, on average, rebuild
- * a literal's hash table to make it larger.
+ * When there are this many entries per bucket, on average, rebuild a
+ * literal's hash table to make it larger.
*/
#define REBUILD_MULTIPLIER 3
@@ -51,7 +51,7 @@ static void RebuildLiteralTable _ANSI_ARGS_((
* Results:
* None.
*
- * Side effects:
+ * Side effects:
* The literal table is made ready for use.
*
*----------------------------------------------------------------------
@@ -59,14 +59,15 @@ static void RebuildLiteralTable _ANSI_ARGS_((
void
TclInitLiteralTable(tablePtr)
- register LiteralTable *tablePtr; /* Pointer to table structure, which
- * is supplied by the caller. */
+ register LiteralTable *tablePtr;
+ /* Pointer to table structure, which is
+ * supplied by the caller. */
{
-#if (TCL_SMALL_HASH_TABLE != 4)
+#if (TCL_SMALL_HASH_TABLE != 4)
Tcl_Panic("TclInitLiteralTable: TCL_SMALL_HASH_TABLE is %d, not 4\n",
TCL_SMALL_HASH_TABLE);
#endif
-
+
tablePtr->buckets = tablePtr->staticBuckets;
tablePtr->staticBuckets[0] = tablePtr->staticBuckets[1] = 0;
tablePtr->staticBuckets[2] = tablePtr->staticBuckets[3] = 0;
@@ -81,9 +82,9 @@ TclInitLiteralTable(tablePtr)
*
* TclCleanupLiteralTable --
*
- * This procedure frees the internal representation of every
- * literal in a literal table. It is called prior to deleting
- * an interp, so that variable refs will be cleaned up properly.
+ * This procedure frees the internal representation of every literal in a
+ * literal table. It is called prior to deleting an interp, so that
+ * variable refs will be cleaned up properly.
*
* Results:
* None.
@@ -96,58 +97,56 @@ TclInitLiteralTable(tablePtr)
void
TclCleanupLiteralTable( interp, tablePtr )
- Tcl_Interp* interp; /* Interpreter containing literals to purge */
- LiteralTable* tablePtr; /* Points to the literal table being cleaned */
+ Tcl_Interp* interp; /* Interpreter containing literals to
+ * purge. */
+ LiteralTable* tablePtr; /* Points to the literal table being
+ * cleaned. */
{
int i;
- LiteralEntry* entryPtr; /* Pointer to the current entry in the
- * hash table of literals */
- LiteralEntry* nextPtr; /* Pointer to the next entry in tbe
- * bucket */
- Tcl_Obj* objPtr; /* Pointer to a literal object whose internal
- * rep is being freed */
- Tcl_ObjType* typePtr; /* Pointer to the object's type */
- int didOne; /* Flag for whether we've removed a literal
- * in the current bucket */
+ LiteralEntry* entryPtr; /* Pointer to the current entry in the hash
+ * table of literals. */
+ LiteralEntry* nextPtr; /* Pointer to the next entry in the bucket. */
+ Tcl_Obj* objPtr; /* Pointer to a literal object whose internal
+ * rep is being freed. */
+ Tcl_ObjType* typePtr; /* Pointer to the object's type. */
+ int didOne; /* Flag for whether we've removed a literal in
+ * the current bucket. */
#ifdef TCL_COMPILE_DEBUG
TclVerifyGlobalLiteralTable( (Interp*) interp );
#endif /* TCL_COMPILE_DEBUG */
- for ( i = 0; i < tablePtr->numBuckets; i++ ) {
-
- /*
- * It is tempting simply to walk each hash bucket once and
- * delete the internal representations of each literal in turn.
- * It's also wrong. The problem is that freeing a literal's
- * internal representation can delete other literals to which
- * it refers, making nextPtr invalid. So each time we free an
- * internal rep, we start its bucket over again.
- */
- didOne = 1;
- while ( didOne ) {
- didOne = 0;
- entryPtr = tablePtr->buckets[i];
- while ( entryPtr != NULL ) {
- objPtr = entryPtr->objPtr;
- nextPtr = entryPtr->nextPtr;
- typePtr = objPtr->typePtr;
- if ( ( typePtr != NULL )
- && ( typePtr->freeIntRepProc != NULL ) ) {
- if ( objPtr->bytes == NULL ) {
- Tcl_Panic( "literal without a string rep" );
- }
- objPtr->typePtr = NULL;
- typePtr->freeIntRepProc( objPtr );
- didOne = 1;
- } else {
- entryPtr = nextPtr;
- }
- }
- }
+ for (i=0 ; i<tablePtr->numBuckets ; i++) {
+ /*
+ * It is tempting simply to walk each hash bucket once and delete the
+ * internal representations of each literal in turn. It's also wrong.
+ * The problem is that freeing a literal's internal representation can
+ * delete other literals to which it refers, making nextPtr invalid.
+ * So each time we free an internal rep, we start its bucket over
+ * again.
+ */
+
+ do {
+ didOne = 0;
+ entryPtr = tablePtr->buckets[i];
+ while (entryPtr != NULL) {
+ objPtr = entryPtr->objPtr;
+ nextPtr = entryPtr->nextPtr;
+ typePtr = objPtr->typePtr;
+ if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
+ if (objPtr->bytes == NULL) {
+ Tcl_Panic( "literal without a string rep" );
+ }
+ objPtr->typePtr = NULL;
+ typePtr->freeIntRepProc(objPtr);
+ didOne = 1;
+ } else {
+ entryPtr = nextPtr;
+ }
+ }
+ } while (didOne);
}
}
-
/*
*----------------------------------------------------------------------
@@ -162,10 +161,9 @@ TclCleanupLiteralTable( interp, tablePtr )
* None.
*
* Side effects:
- * Each literal in the table is released: i.e., its reference count
- * in the global literal table is decremented and, if it becomes zero,
- * the literal is freed. In addition, the table's bucket array is
- * freed.
+ * Each literal in the table is released: i.e., its reference count in
+ * the global literal table is decremented and, if it becomes zero, the
+ * literal is freed. In addition, the table's bucket array is freed.
*
*----------------------------------------------------------------------
*/
@@ -179,11 +177,11 @@ TclDeleteLiteralTable(interp, tablePtr)
LiteralEntry *entryPtr, *nextPtr;
Tcl_Obj *objPtr;
int i;
-
+
/*
- * Release remaining literals in the table. Note that releasing a
- * literal might release other literals, modifying the table, so we
- * restart the search from the bucket chain we last found an entry.
+ * Release remaining literals in the table. Note that releasing a literal
+ * might release other literals, modifying the table, so we restart the
+ * search from the bucket chain we last found an entry.
*/
#ifdef TCL_COMPILE_DEBUG
@@ -193,10 +191,10 @@ TclDeleteLiteralTable(interp, tablePtr)
/*
* We used to call TclReleaseLiteral for each literal in the table, which
* is rather inefficient as it causes one lookup-by-hash for each
- * reference to the literal.
- * We now rely at interp-deletion on each bytecode object to release its
- * references to the literal Tcl_Obj without requiring that it updates the
- * global table itself, and deal here only with the table.
+ * reference to the literal. We now rely at interp-deletion on each
+ * bytecode object to release its references to the literal Tcl_Obj
+ * without requiring that it updates the global table itself, and deal
+ * here only with the table.
*/
for (i = 0; i < tablePtr->numBuckets; i++) {
@@ -209,7 +207,7 @@ TclDeleteLiteralTable(interp, tablePtr)
entryPtr = nextPtr;
}
}
-
+
/*
* Free up the table's bucket array if it was dynamically allocated.
*/
@@ -224,19 +222,18 @@ TclDeleteLiteralTable(interp, tablePtr)
*
* TclRegisterLiteral --
*
- * Find, or if necessary create, an object in a CompileEnv literal
- * array that has a string representation matching the argument string.
+ * Find, or if necessary create, an object in a CompileEnv literal array
+ * that has a string representation matching the argument string.
*
* Results:
- * The index in the CompileEnv's literal array that references a
- * shared literal matching the string. The object is created if
- * necessary.
+ * The index in the CompileEnv's literal array that references a shared
+ * literal matching the string. The object is created if necessary.
*
* Side effects:
- * To maximize sharing, we look up the string in the interpreter's
- * global literal table. If not found, we create a new shared literal
- * in the global table. We then add a reference to the shared
- * literal in the CompileEnv's literal array.
+ * To maximize sharing, we look up the string in the interpreter's global
+ * literal table. If not found, we create a new shared literal in the
+ * global table. We then add a reference to the shared literal in the
+ * CompileEnv's literal array.
*
* If LITERAL_ON_HEAP is set in flags, this procedure is given ownership
* of the string: if an object is created then its string representation
@@ -254,9 +251,9 @@ TclRegisterLiteral(envPtr, bytes, length, flags)
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 string consists of all bytes up to
- * the first null character. */
+ int 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
* malloc'd bytes and ownership is passed to
* this procedure. If LITERAL_NS_SCOPE then
@@ -273,23 +270,22 @@ TclRegisterLiteral(envPtr, bytes, length, flags)
Namespace *nsPtr;
if (length < 0) {
- length = (bytes? strlen(bytes) : 0);
+ length = (bytes ? strlen(bytes) : 0);
}
hash = HashString(bytes, length);
/*
- * Is the literal already in the CompileEnv's local literal array?
- * If so, just return its index.
+ * Is the literal already in the CompileEnv's local literal array? If so,
+ * just return its index.
*/
localHash = (hash & localTablePtr->mask);
for (localPtr = localTablePtr->buckets[localHash];
- localPtr != NULL; localPtr = localPtr->nextPtr) {
+ localPtr != NULL; localPtr = localPtr->nextPtr) {
objPtr = localPtr->objPtr;
if ((objPtr->length == length) && ((length == 0)
|| ((objPtr->bytes[0] == bytes[0])
- && (memcmp(objPtr->bytes, bytes, (unsigned) length)
- == 0)))) {
+ && (memcmp(objPtr->bytes, bytes, (unsigned) length) == 0)))) {
if (flags & LITERAL_ON_HEAP) {
ckfree(bytes);
}
@@ -321,18 +317,17 @@ TclRegisterLiteral(envPtr, bytes, length, flags)
globalHash = (hash & globalTablePtr->mask);
for (globalPtr = globalTablePtr->buckets[globalHash];
- globalPtr != NULL; globalPtr = globalPtr->nextPtr) {
+ globalPtr != NULL; globalPtr = globalPtr->nextPtr) {
objPtr = globalPtr->objPtr;
if ((globalPtr->nsPtr == nsPtr)
&& (objPtr->length == length) && ((length == 0)
|| ((objPtr->bytes[0] == bytes[0])
- && (memcmp(objPtr->bytes, bytes, (unsigned) length)
- == 0)))) {
+ && (memcmp(objPtr->bytes, bytes, (unsigned) length) == 0)))) {
/*
* A global literal was found. Add an entry to the CompileEnv's
* local literal array.
*/
-
+
if (flags & LITERAL_ON_HEAP) {
ckfree(bytes);
}
@@ -340,11 +335,10 @@ TclRegisterLiteral(envPtr, bytes, length, flags)
#ifdef TCL_COMPILE_DEBUG
if (globalPtr->refCount < 1) {
Tcl_Panic("TclRegisterLiteral: global literal \"%.*s\" had bad refCount %d",
- (length>60? 60 : length), bytes,
- globalPtr->refCount);
+ (length>60? 60 : length), bytes, globalPtr->refCount);
}
TclVerifyLocalLiteralTable(envPtr);
-#endif /*TCL_COMPILE_DEBUG*/
+#endif /*TCL_COMPILE_DEBUG*/
return objIndex;
}
}
@@ -369,8 +363,10 @@ TclRegisterLiteral(envPtr, bytes, length, flags)
/*
* From here we use the objPtr, because it is NULL terminated
*/
+
long n;
char buf[TCL_INTEGER_SPACE];
+
if (TclGetLong((Tcl_Interp *) NULL, objPtr->bytes, &n) == TCL_OK) {
TclFormatInt(buf, n);
if (strcmp(objPtr->bytes, buf) == 0) {
@@ -380,11 +376,11 @@ TclRegisterLiteral(envPtr, bytes, length, flags)
}
}
#endif
-
+
#ifdef TCL_COMPILE_DEBUG
if (TclLookupLiteralEntry((Tcl_Interp *) iPtr, objPtr) != NULL) {
Tcl_Panic("TclRegisterLiteral: literal \"%.*s\" found globally but shouldn't be",
- (length>60? 60 : length), bytes);
+ (length>60? 60 : length), bytes);
}
#endif
@@ -397,8 +393,8 @@ TclRegisterLiteral(envPtr, bytes, length, flags)
globalTablePtr->numEntries++;
/*
- * If the global literal table has exceeded a decent size, rebuild it
- * with more buckets.
+ * If the global literal table has exceeded a decent size, rebuild it with
+ * more buckets.
*/
if (globalTablePtr->numEntries >= globalTablePtr->rebuildSize) {
@@ -412,28 +408,30 @@ TclRegisterLiteral(envPtr, bytes, length, flags)
{
LiteralEntry *entryPtr;
int found, i;
+
found = 0;
- for (i = 0; i < globalTablePtr->numBuckets; i++) {
- for (entryPtr = globalTablePtr->buckets[i];
- entryPtr != NULL; entryPtr = entryPtr->nextPtr) {
- if ((entryPtr == globalPtr)
- && (entryPtr->objPtr == objPtr)) {
+ for (i=0 ; i<globalTablePtr->numBuckets ; i++) {
+ for (entryPtr=globalTablePtr->buckets[i]; entryPtr!=NULL ;
+ entryPtr=entryPtr->nextPtr) {
+ if ((entryPtr == globalPtr) && (entryPtr->objPtr == objPtr)) {
found = 1;
}
}
}
if (!found) {
Tcl_Panic("TclRegisterLiteral: literal \"%.*s\" wasn't global",
- (length>60? 60 : length), bytes);
+ (length>60? 60 : length), bytes);
}
}
#endif /*TCL_COMPILE_DEBUG*/
-#ifdef TCL_COMPILE_STATS
+
+#ifdef TCL_COMPILE_STATS
iPtr->stats.numLiteralsCreated++;
- iPtr->stats.totalLitStringBytes += (double) (length + 1);
+ iPtr->stats.totalLitStringBytes += (double) (length + 1);
iPtr->stats.currentLitStringBytes += (double) (length + 1);
iPtr->stats.literalCount[TclLog2(length)]++;
#endif /*TCL_COMPILE_STATS*/
+
return objIndex;
}
@@ -443,24 +441,24 @@ TclRegisterLiteral(envPtr, bytes, length, flags)
* TclLookupLiteralEntry --
*
* Finds the LiteralEntry that corresponds to a literal Tcl object
- * holding a literal.
+ * holding a literal.
*
* Results:
- * Returns the matching LiteralEntry if found, otherwise NULL.
+ * Returns the matching LiteralEntry if found, otherwise NULL.
*
* Side effects:
- * None.
+ * None.
*
*----------------------------------------------------------------------
*/
LiteralEntry *
TclLookupLiteralEntry(interp, objPtr)
- Tcl_Interp *interp; /* Interpreter for which objPtr was created
- * to hold a literal. */
- register Tcl_Obj *objPtr; /* Points to a Tcl object holding a
- * literal that was previously created by a
- * call to TclRegisterLiteral. */
+ Tcl_Interp *interp; /* Interpreter for which objPtr was created to
+ * hold a literal. */
+ register Tcl_Obj *objPtr; /* Points to a Tcl object holding a literal
+ * that was previously created by a call to
+ * TclRegisterLiteral. */
{
Interp *iPtr = (Interp *) interp;
LiteralTable *globalTablePtr = &(iPtr->literalTable);
@@ -471,10 +469,10 @@ TclLookupLiteralEntry(interp, objPtr)
bytes = Tcl_GetStringFromObj(objPtr, &length);
globalHash = (HashString(bytes, length) & globalTablePtr->mask);
for (entryPtr = globalTablePtr->buckets[globalHash];
- entryPtr != NULL; entryPtr = entryPtr->nextPtr) {
- if (entryPtr->objPtr == objPtr) {
- return entryPtr;
- }
+ entryPtr != NULL; entryPtr = entryPtr->nextPtr) {
+ if (entryPtr->objPtr == objPtr) {
+ return entryPtr;
+ }
}
return NULL;
}
@@ -484,10 +482,10 @@ TclLookupLiteralEntry(interp, objPtr)
*
* TclHideLiteral --
*
- * Remove a literal entry from the literal hash tables, leaving it in
- * the literal array so existing references continue to function.
- * This makes it possible to turn a shared literal into a private
- * literal that cannot be shared.
+ * Remove a literal entry from the literal hash tables, leaving it in the
+ * literal array so existing references continue to function. This makes
+ * it possible to turn a shared literal into a private literal that
+ * cannot be shared.
*
* Results:
* None.
@@ -501,12 +499,12 @@ TclLookupLiteralEntry(interp, objPtr)
void
TclHideLiteral(interp, envPtr, index)
- Tcl_Interp *interp; /* Interpreter for which objPtr was created
- * to hold a literal. */
- register CompileEnv *envPtr; /* Points to CompileEnv whose literal array
- * contains the entry being hidden. */
- int index; /* The index of the entry in the literal
- * array. */
+ Tcl_Interp *interp; /* Interpreter for which objPtr was created to
+ * hold a literal. */
+ register CompileEnv *envPtr;/* Points to CompileEnv whose literal array
+ * contains the entry being hidden. */
+ int index; /* The index of the entry in the literal
+ * array. */
{
LiteralEntry **nextPtrPtr, *entryPtr, *lPtr;
LiteralTable *localTablePtr = &(envPtr->localLitTable);
@@ -518,9 +516,9 @@ TclHideLiteral(interp, envPtr, index)
/*
* To avoid unwanted sharing we need to copy the object and remove it from
- * the local and global literal tables. It still has a slot in the literal
- * array so it can be referred to by byte codes, but it will not be matched
- * by literal searches.
+ * the local and global literal tables. It still has a slot in the
+ * literal array so it can be referred to by byte codes, but it will not
+ * be matched by literal searches.
*/
newObjPtr = Tcl_DuplicateObj(lPtr->objPtr);
@@ -532,7 +530,7 @@ TclHideLiteral(interp, envPtr, index)
localHash = (HashString(bytes, length) & localTablePtr->mask);
nextPtrPtr = &localTablePtr->buckets[localHash];
- for (entryPtr = *nextPtrPtr; entryPtr != NULL; entryPtr = *nextPtrPtr) {
+ for (entryPtr=*nextPtrPtr ; entryPtr!=NULL ; entryPtr=*nextPtrPtr) {
if (entryPtr == lPtr) {
*nextPtrPtr = lPtr->nextPtr;
lPtr->nextPtr = NULL;
@@ -548,31 +546,30 @@ TclHideLiteral(interp, envPtr, index)
*
* TclAddLiteralObj --
*
- * Add a single literal object to the literal array. This
- * function does not add the literal to the local or global
- * literal tables. The caller is expected to add the entry
- * to whatever tables are appropriate.
+ * Add a single literal object to the literal array. This function does
+ * not add the literal to the local or global literal tables. The caller
+ * is expected to add the entry to whatever tables are appropriate.
*
* Results:
* The index in the CompileEnv's literal array that references the
- * literal. Stores the pointer to the new literal entry in the
- * location referenced by the localPtrPtr argument.
+ * literal. Stores the pointer to the new literal entry in the location
+ * referenced by the localPtrPtr argument.
*
* Side effects:
- * Expands the literal array if necessary. Increments the refcount
- * on the literal object.
+ * Expands the literal array if necessary. Increments the refcount on the
+ * literal object.
*
*----------------------------------------------------------------------
*/
int
TclAddLiteralObj(envPtr, objPtr, litPtrPtr)
- register CompileEnv *envPtr; /* Points to CompileEnv in whose literal
- * array the object is to be inserted. */
- Tcl_Obj *objPtr; /* The object to insert into the array. */
- LiteralEntry **litPtrPtr; /* The location where the pointer to the
- * new literal entry should be stored.
- * May be NULL. */
+ register CompileEnv *envPtr;/* Points to CompileEnv in whose literal array
+ * the object is to be inserted. */
+ Tcl_Obj *objPtr; /* The object to insert into the array. */
+ LiteralEntry **litPtrPtr; /* The location where the pointer to the new
+ * literal entry should be stored. May be
+ * NULL. */
{
register LiteralEntry *lPtr;
int objIndex;
@@ -609,8 +606,8 @@ TclAddLiteralObj(envPtr, objPtr, litPtrPtr)
*
* Side effects:
* Increments the ref count of the global LiteralEntry since the
- * CompileEnv now refers to the literal. Expands the literal array
- * if necessary. May rebuild the hash bucket array of the CompileEnv's
+ * CompileEnv now refers to the literal. Expands the literal array if
+ * necessary. May rebuild the hash bucket array of the CompileEnv's
* literal array if it becomes too large.
*
*----------------------------------------------------------------------
@@ -618,16 +615,16 @@ TclAddLiteralObj(envPtr, objPtr, litPtrPtr)
static int
AddLocalLiteralEntry(envPtr, globalPtr, localHash)
- register CompileEnv *envPtr; /* Points to CompileEnv in whose literal
- * array the object is to be inserted. */
- LiteralEntry *globalPtr; /* Points to the global LiteralEntry for
- * the literal to add to the CompileEnv. */
- int localHash; /* Hash value for the literal's string. */
+ register CompileEnv *envPtr;/* Points to CompileEnv in whose literal array
+ * the object is to be inserted. */
+ LiteralEntry *globalPtr; /* Points to the global LiteralEntry for the
+ * literal to add to the CompileEnv. */
+ int localHash; /* Hash value for the literal's string. */
{
register LiteralTable *localTablePtr = &(envPtr->localLitTable);
LiteralEntry *localPtr;
int objIndex;
-
+
objIndex = TclAddLiteralObj(envPtr, globalPtr->objPtr, &localPtr);
/*
@@ -654,22 +651,25 @@ AddLocalLiteralEntry(envPtr, globalPtr, localHash)
{
char *bytes;
int length, found, i;
+
found = 0;
- for (i = 0; i < localTablePtr->numBuckets; i++) {
- for (localPtr = localTablePtr->buckets[i];
- localPtr != NULL; localPtr = localPtr->nextPtr) {
+ for (i=0 ; i<localTablePtr->numBuckets ; i++) {
+ for (localPtr=localTablePtr->buckets[i] ; localPtr!=NULL ;
+ localPtr=localPtr->nextPtr) {
if (localPtr->objPtr == globalPtr->objPtr) {
found = 1;
}
}
}
+
if (!found) {
bytes = Tcl_GetStringFromObj(globalPtr->objPtr, &length);
Tcl_Panic("AddLocalLiteralEntry: literal \"%.*s\" wasn't found locally",
- (length>60? 60 : length), bytes);
+ (length>60? 60 : length), bytes);
}
}
#endif /*TCL_COMPILE_DEBUG*/
+
return objIndex;
}
@@ -678,30 +678,29 @@ AddLocalLiteralEntry(envPtr, globalPtr, localHash)
*
* ExpandLocalLiteralArray --
*
- * Procedure that uses malloc to allocate more storage for a
- * CompileEnv's local literal array.
+ * Procedure that uses malloc to allocate more storage for a CompileEnv's
+ * local literal array.
*
* Results:
* None.
*
* Side effects:
- * The literal array in *envPtr is reallocated to a new array of
- * double the size, and if envPtr->mallocedLiteralArray is non-zero
- * the old array is freed. Entries are copied from the old array
- * to the new one. The local literal table is updated to refer to
- * the new entries.
+ * The literal array in *envPtr is reallocated to a new array of double
+ * the size, and if envPtr->mallocedLiteralArray is non-zero the old
+ * array is freed. Entries are copied from the old array to the new one.
+ * The local literal table is updated to refer to the new entries.
*
*----------------------------------------------------------------------
*/
static void
ExpandLocalLiteralArray(envPtr)
- register CompileEnv *envPtr; /* Points to the CompileEnv whose object
- * array must be enlarged. */
+ register CompileEnv *envPtr;/* Points to the CompileEnv whose object array
+ * must be enlarged. */
{
/*
- * The current allocated local literal entries are stored between
- * elements 0 and (envPtr->literalArrayNext - 1) [inclusive].
+ * The current allocated local literal entries are stored between elements
+ * 0 and (envPtr->literalArrayNext - 1) [inclusive].
*/
LiteralTable *localTablePtr = &(envPtr->localLitTable);
@@ -711,33 +710,33 @@ ExpandLocalLiteralArray(envPtr)
register LiteralEntry *newArrayPtr =
(LiteralEntry *) ckalloc((unsigned) (2 * currBytes));
int i;
-
+
/*
* Copy from the old literal array to the new, then update the local
* literal table's bucket array.
*/
memcpy((VOID *) newArrayPtr, (VOID *) currArrayPtr, currBytes);
- for (i = 0; i < currElems; i++) {
+ for (i=0 ; i<currElems ; i++) {
if (currArrayPtr[i].nextPtr == NULL) {
newArrayPtr[i].nextPtr = NULL;
} else {
- newArrayPtr[i].nextPtr = newArrayPtr
- + (currArrayPtr[i].nextPtr - currArrayPtr);
+ newArrayPtr[i].nextPtr =
+ newArrayPtr + (currArrayPtr[i].nextPtr - currArrayPtr);
}
}
- for (i = 0; i < localTablePtr->numBuckets; i++) {
+ for (i=0 ; i<localTablePtr->numBuckets ; i++) {
if (localTablePtr->buckets[i] != NULL) {
- localTablePtr->buckets[i] = newArrayPtr
- + (localTablePtr->buckets[i] - currArrayPtr);
+ localTablePtr->buckets[i] =
+ newArrayPtr + (localTablePtr->buckets[i] - currArrayPtr);
}
}
/*
- * Free the old literal array if needed, and mark the new literal
- * array as malloced.
+ * Free the old literal array if needed, and mark the new literal array as
+ * malloced.
*/
-
+
if (envPtr->mallocedLiteralArray) {
ckfree((char *) currArrayPtr);
}
@@ -752,25 +751,25 @@ ExpandLocalLiteralArray(envPtr)
* TclReleaseLiteral --
*
* This procedure releases a reference to one of the shared Tcl objects
- * that hold literals. It is called to release the literals referenced
- * by a ByteCode that is being destroyed, and it is also called by
+ * that hold literals. It is called to release the literals referenced by
+ * a ByteCode that is being destroyed, and it is also called by
* TclDeleteLiteralTable.
*
* Results:
* None.
*
* Side effects:
- * The reference count for the global LiteralTable entry that
- * corresponds to the literal is decremented. If no other reference
- * to a global literal object remains, it is freed.
+ * The reference count for the global LiteralTable entry that corresponds
+ * to the literal is decremented. If no other reference to a global
+ * literal object remains, it is freed.
*
*----------------------------------------------------------------------
*/
void
TclReleaseLiteral(interp, objPtr)
- Tcl_Interp *interp; /* Interpreter for which objPtr was created
- * to hold a literal. */
+ Tcl_Interp *interp; /* Interpreter for which objPtr was created to
+ * hold a literal. */
register Tcl_Obj *objPtr; /* Points to a literal object that was
* previously created by a call to
* TclRegisterLiteral. */
@@ -785,9 +784,9 @@ TclReleaseLiteral(interp, objPtr)
index = (HashString(bytes, length) & globalTablePtr->mask);
/*
- * Check to see if the object is in the global literal table and
- * remove this reference. The object may not be in the table if
- * it is a hidden local literal.
+ * Check to see if the object is in the global literal table and remove
+ * this reference. The object may not be in the table if it is a hidden
+ * local literal.
*/
for (prevPtr = NULL, entryPtr = globalTablePtr->buckets[index];
@@ -797,12 +796,11 @@ TclReleaseLiteral(interp, objPtr)
entryPtr->refCount--;
/*
- * If the literal is no longer being used by any ByteCode,
- * delete the entry then remove the reference corresponding
- * to the global literal table entry (decrement the ref count
- * of the object).
+ * If the literal is no longer being used by any ByteCode, delete
+ * the entry then remove the reference corresponding to the global
+ * literal table entry (decrement the ref count of the object).
*/
-
+
if (entryPtr->refCount == 0) {
if (prevPtr == NULL) {
globalTablePtr->buckets[index] = entryPtr->nextPtr;
@@ -823,8 +821,7 @@ TclReleaseLiteral(interp, objPtr)
}
/*
- * Remove the reference corresponding to the local literal table
- * entry.
+ * Remove the reference corresponding to the local literal table entry.
*/
Tcl_DecrRefCount(objPtr);
@@ -835,12 +832,11 @@ TclReleaseLiteral(interp, objPtr)
*
* HashString --
*
- * Compute a one-word summary of a text string, which can be
- * used to generate a hash index.
+ * Compute a one-word summary of a text string, which can be used to
+ * generate a hash index.
*
* Results:
- * The return value is a one-word summary of the information in
- * string.
+ * The return value is a one-word summary of the information in string.
*
* Side effects:
* None.
@@ -850,27 +846,26 @@ TclReleaseLiteral(interp, objPtr)
static unsigned int
HashString(bytes, length)
- register CONST char *bytes; /* String for which to compute hash
- * value. */
+ register CONST char *bytes; /* String for which to compute hash value. */
int length; /* Number of bytes in the string. */
{
register unsigned int result;
register int i;
/*
- * I tried a zillion different hash functions and asked many other
- * people for advice. Many people had their own favorite functions,
- * all different, but no-one had much idea why they were good ones.
- * I chose the one below (multiply by 9 and add new character)
- * because of the following reasons:
+ * I tried a zillion different hash functions and asked many other people
+ * for advice. Many people had their own favorite functions, all
+ * different, but no-one had much idea why they were good ones. I chose
+ * the one below (multiply by 9 and add new character) because of the
+ * following reasons:
*
- * 1. Multiplying by 10 is perfect for keys that are decimal strings,
- * and multiplying by 9 is just about as good.
+ * 1. Multiplying by 10 is perfect for keys that are decimal strings, and
+ * multiplying by 9 is just about as good.
* 2. Times-9 is (shift-left-3) plus (old). This means that each
- * character's bits hang around in the low-order bits of the
- * hash value for ever, plus they spread fairly rapidly up to
- * the high-order bits to fill out the hash value. This seems
- * works well both for decimal and non-decimal strings.
+ * character's bits hang around in the low-order bits of the hash value
+ * for ever, plus they spread fairly rapidly up to the high-order bits
+ * to fill out the hash value. This seems works well both for decimal
+ * and non-decimal strings.
*/
result = 0;
@@ -886,8 +881,8 @@ HashString(bytes, length)
* RebuildLiteralTable --
*
* This procedure is invoked when the ratio of entries to hash buckets
- * becomes too large in a local or global literal table. It allocates
- * a larger bucket array and moves the entries into the new buckets.
+ * becomes too large in a local or global literal table. It allocates a
+ * larger bucket array and moves the entries into the new buckets.
*
* Results:
* None.
@@ -900,7 +895,8 @@ HashString(bytes, length)
static void
RebuildLiteralTable(tablePtr)
- register LiteralTable *tablePtr; /* Local or global table to enlarge. */
+ register LiteralTable *tablePtr;
+ /* Local or global table to enlarge. */
{
LiteralEntry **oldBuckets;
register LiteralEntry **oldChainPtr, **newChainPtr;
@@ -913,8 +909,8 @@ RebuildLiteralTable(tablePtr)
oldBuckets = tablePtr->buckets;
/*
- * Allocate and initialize the new bucket array, and set up
- * hashing constants for new array size.
+ * Allocate and initialize the new bucket array, and set up hashing
+ * constants for new array size.
*/
tablePtr->numBuckets *= 4;
@@ -932,14 +928,11 @@ RebuildLiteralTable(tablePtr)
* Rehash all of the existing entries into the new bucket array.
*/
- for (oldChainPtr = oldBuckets;
- oldSize > 0;
- oldSize--, oldChainPtr++) {
- for (entryPtr = *oldChainPtr; entryPtr != NULL;
- entryPtr = *oldChainPtr) {
+ for (oldChainPtr=oldBuckets ; oldSize>0 ; oldSize--,oldChainPtr++) {
+ for (entryPtr=*oldChainPtr ; entryPtr!=NULL ; entryPtr=*oldChainPtr) {
bytes = Tcl_GetStringFromObj(entryPtr->objPtr, &length);
index = (HashString(bytes, length) & tablePtr->mask);
-
+
*oldChainPtr = entryPtr->nextPtr;
bucketPtr = &(tablePtr->buckets[index]);
entryPtr->nextPtr = *bucketPtr;
@@ -962,13 +955,12 @@ RebuildLiteralTable(tablePtr)
*
* TclLiteralStats --
*
- * Return statistics describing the layout of the hash table
- * in its hash buckets.
+ * Return statistics describing the layout of the hash table in its hash
+ * buckets.
*
* Results:
- * The return value is a malloc-ed string containing information
- * about tablePtr. It is the caller's responsibility to free
- * this string.
+ * The return value is a malloc-ed string containing information about
+ * tablePtr. It is the caller's responsibility to free this string.
*
* Side effects:
* None.
@@ -987,8 +979,8 @@ TclLiteralStats(tablePtr)
char *result, *p;
/*
- * Compute a histogram of bucket usage. For each bucket chain i,
- * j is the number of entries in the chain.
+ * Compute a histogram of bucket usage. For each bucket chain i, j is the
+ * number of entries in the chain.
*/
for (i = 0; i < NUM_COUNTERS; i++) {
@@ -999,7 +991,7 @@ TclLiteralStats(tablePtr)
for (i = 0; i < tablePtr->numBuckets; i++) {
j = 0;
for (entryPtr = tablePtr->buckets[i]; entryPtr != NULL;
- entryPtr = entryPtr->nextPtr) {
+ entryPtr = entryPtr->nextPtr) {
j++;
}
if (j < NUM_COUNTERS) {
@@ -1051,8 +1043,8 @@ TclLiteralStats(tablePtr)
void
TclVerifyLocalLiteralTable(envPtr)
- CompileEnv *envPtr; /* Points to CompileEnv whose literal
- * table is to be validated. */
+ CompileEnv *envPtr; /* Points to CompileEnv whose literal table is
+ * to be validated. */
{
register LiteralTable *localTablePtr = &(envPtr->localLitTable);
register LiteralEntry *localPtr;
@@ -1063,19 +1055,18 @@ TclVerifyLocalLiteralTable(envPtr)
count = 0;
for (i = 0; i < localTablePtr->numBuckets; i++) {
for (localPtr = localTablePtr->buckets[i];
- localPtr != NULL; localPtr = localPtr->nextPtr) {
+ localPtr != NULL; localPtr = localPtr->nextPtr) {
count++;
if (localPtr->refCount != -1) {
bytes = Tcl_GetStringFromObj(localPtr->objPtr, &length);
Tcl_Panic("TclVerifyLocalLiteralTable: local literal \"%.*s\" had bad refCount %d",
- (length>60? 60 : length), bytes,
- localPtr->refCount);
+ (length>60? 60 : length), bytes, localPtr->refCount);
}
if (TclLookupLiteralEntry((Tcl_Interp *) envPtr->iPtr,
localPtr->objPtr) == NULL) {
bytes = Tcl_GetStringFromObj(localPtr->objPtr, &length);
Tcl_Panic("TclVerifyLocalLiteralTable: local literal \"%.*s\" is not global",
- (length>60? 60 : length), bytes);
+ (length>60? 60 : length), bytes);
}
if (localPtr->objPtr->bytes == NULL) {
Tcl_Panic("TclVerifyLocalLiteralTable: literal has NULL string rep");
@@ -1084,7 +1075,7 @@ TclVerifyLocalLiteralTable(envPtr)
}
if (count != localTablePtr->numEntries) {
Tcl_Panic("TclVerifyLocalLiteralTable: local literal table had %d entries, should be %d",
- count, localTablePtr->numEntries);
+ count, localTablePtr->numEntries);
}
}
@@ -1106,8 +1097,8 @@ TclVerifyLocalLiteralTable(envPtr)
void
TclVerifyGlobalLiteralTable(iPtr)
- Interp *iPtr; /* Points to interpreter whose global
- * literal table is to be validated. */
+ Interp *iPtr; /* Points to interpreter whose global literal
+ * table is to be validated. */
{
register LiteralTable *globalTablePtr = &(iPtr->literalTable);
register LiteralEntry *globalPtr;
@@ -1118,13 +1109,12 @@ TclVerifyGlobalLiteralTable(iPtr)
count = 0;
for (i = 0; i < globalTablePtr->numBuckets; i++) {
for (globalPtr = globalTablePtr->buckets[i];
- globalPtr != NULL; globalPtr = globalPtr->nextPtr) {
+ globalPtr != NULL; globalPtr = globalPtr->nextPtr) {
count++;
if (globalPtr->refCount < 1) {
bytes = Tcl_GetStringFromObj(globalPtr->objPtr, &length);
Tcl_Panic("TclVerifyGlobalLiteralTable: global literal \"%.*s\" had bad refCount %d",
- (length>60? 60 : length), bytes,
- globalPtr->refCount);
+ (length>60? 60 : length), bytes, globalPtr->refCount);
}
if (globalPtr->objPtr->bytes == NULL) {
Tcl_Panic("TclVerifyGlobalLiteralTable: literal has NULL string rep");
@@ -1133,7 +1123,15 @@ TclVerifyGlobalLiteralTable(iPtr)
}
if (count != globalTablePtr->numEntries) {
Tcl_Panic("TclVerifyGlobalLiteralTable: global literal table had %d entries, should be %d",
- count, globalTablePtr->numEntries);
+ count, globalTablePtr->numEntries);
}
}
#endif /*TCL_COMPILE_DEBUG*/
+
+/*
+ * Local Variables:
+ * mode: c
+ * c-basic-offset: 4
+ * fill-column: 78
+ * End:
+ */