summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclObj.c255
1 files changed, 122 insertions, 133 deletions
diff --git a/generic/tclObj.c b/generic/tclObj.c
index 4f993ba..c043562 100644
--- a/generic/tclObj.c
+++ b/generic/tclObj.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclObj.c,v 1.67 2004/09/27 19:59:38 kennykb Exp $
+ * RCS: @(#) $Id: tclObj.c,v 1.68 2004/09/27 21:57:10 dkf Exp $
*/
#include "tclInt.h"
@@ -330,8 +330,8 @@ TclFinalizeCompExecEnv()
{
Tcl_MutexLock(&tableMutex);
if (typeTableInitialized) {
- Tcl_DeleteHashTable(&typeTable);
- typeTableInitialized = 0;
+ Tcl_DeleteHashTable(&typeTable);
+ typeTableInitialized = 0;
}
Tcl_MutexUnlock(&tableMutex);
Tcl_MutexLock(&tclObjMutex);
@@ -376,7 +376,7 @@ Tcl_RegisterObjType(typePtr)
Tcl_MutexLock(&tableMutex);
hPtr = Tcl_FindHashEntry(&typeTable, typePtr->name);
if (hPtr != (Tcl_HashEntry *) NULL) {
- Tcl_DeleteHashEntry(hPtr);
+ Tcl_DeleteHashEntry(hPtr);
}
/*
@@ -434,9 +434,9 @@ Tcl_AppendAllObjTypes(interp, objPtr)
Tcl_MutexLock(&tableMutex);
for (hPtr = Tcl_FirstHashEntry(&typeTable, &search);
hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
- typePtr = (Tcl_ObjType *) Tcl_GetHashValue(hPtr);
+ typePtr = (Tcl_ObjType *) Tcl_GetHashValue(hPtr);
result = Tcl_ListObjAppendElement(interp, objPtr,
- Tcl_NewStringObj(typePtr->name, -1));
+ Tcl_NewStringObj(typePtr->name, -1));
if (result == TCL_ERROR) {
Tcl_MutexUnlock(&tableMutex);
return result;
@@ -474,7 +474,7 @@ Tcl_GetObjType(typeName)
Tcl_MutexLock(&tableMutex);
hPtr = Tcl_FindHashEntry(&typeTable, typeName);
if (hPtr != (Tcl_HashEntry *) NULL) {
- typePtr = (Tcl_ObjType *) Tcl_GetHashValue(hPtr);
+ typePtr = (Tcl_ObjType *) Tcl_GetHashValue(hPtr);
Tcl_MutexUnlock(&tableMutex);
return typePtr;
}
@@ -552,22 +552,22 @@ void TclDbInitNewObj(objPtr)
* was allocated by the currently executing thread.
*/
if (!TclInExit()) {
- Tcl_HashEntry *hPtr;
- Tcl_HashTable *tablePtr;
- int new;
- ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
+ Tcl_HashEntry *hPtr;
+ Tcl_HashTable *tablePtr;
+ int new;
+ ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
- if (tsdPtr->objThreadMap == NULL) {
- tsdPtr->objThreadMap = (Tcl_HashTable *)
+ if (tsdPtr->objThreadMap == NULL) {
+ tsdPtr->objThreadMap = (Tcl_HashTable *)
ckalloc(sizeof(Tcl_HashTable));
- Tcl_InitHashTable(tsdPtr->objThreadMap, TCL_ONE_WORD_KEYS);
- }
- tablePtr = tsdPtr->objThreadMap;
- hPtr = Tcl_CreateHashEntry(tablePtr, (char *) objPtr, &new);
- if (!new) {
- Tcl_Panic("expected to create new entry for object map");
- }
- Tcl_SetHashValue(hPtr, NULL);
+ Tcl_InitHashTable(tsdPtr->objThreadMap, TCL_ONE_WORD_KEYS);
+ }
+ tablePtr = tsdPtr->objThreadMap;
+ hPtr = Tcl_CreateHashEntry(tablePtr, (char *) objPtr, &new);
+ if (!new) {
+ Tcl_Panic("expected to create new entry for object map");
+ }
+ Tcl_SetHashValue(hPtr, NULL);
}
# endif /* TCL_THREADS */
}
@@ -986,7 +986,7 @@ Tcl_GetStringFromObj(objPtr, lengthPtr)
void
Tcl_InvalidateStringRep(objPtr)
- register Tcl_Obj *objPtr; /* Object whose string rep byte pointer
+ register Tcl_Obj *objPtr; /* Object whose string rep byte pointer
* should be freed. */
{
if (objPtr->bytes != NULL) {
@@ -1641,7 +1641,7 @@ Tcl_GetDoubleFromObj(interp, objPtr, dblPtr)
if (objPtr->typePtr == &tclDoubleType) {
*dblPtr = objPtr->internalRep.doubleValue;
return TCL_OK;
- } else if ( objPtr->typePtr == &tclIntType ) {
+ } else if (objPtr->typePtr == &tclIntType) {
*dblPtr = objPtr->internalRep.longValue;
return TCL_OK;
}
@@ -1914,22 +1914,20 @@ Tcl_GetIntFromObj(interp, objPtr, intPtr)
* convert it to one.
*/
- if ( objPtr->typePtr != &tclIntType
- && objPtr->typePtr != &tclWideIntType ) {
- result = SetIntOrWideFromAny( interp, objPtr );
- if ( result != TCL_OK ) {
+ if (objPtr->typePtr != &tclIntType
+ && objPtr->typePtr != &tclWideIntType) {
+ result = SetIntOrWideFromAny(interp, objPtr);
+ if (result != TCL_OK) {
return result;
}
}
/* Object should now be either int or wide. Get its value. */
- if ( objPtr->typePtr == &tclIntType ) {
+ if (objPtr->typePtr == &tclIntType) {
l = objPtr->internalRep.longValue;
- } else if ( objPtr->typePtr == &tclWideIntType ) {
-
+ } else if (objPtr->typePtr == &tclWideIntType) {
#ifndef TCL_WIDE_INT_IS_LONG
-
/*
* If the object is already a wide integer, don't convert it.
* This code allows for any integer in the range -ULONG_MAX to
@@ -1939,21 +1937,17 @@ Tcl_GetIntFromObj(interp, objPtr, intPtr)
* wide integers to 32-bit ones in the internal rep.
*/
Tcl_WideInt w = objPtr->internalRep.wideValue;
- if ( w >= -(Tcl_WideInt)(ULONG_MAX)
- && w <= (Tcl_WideInt)(ULONG_MAX) ) {
- l = Tcl_WideAsLong( w );
+ if (w >= -(Tcl_WideInt)(ULONG_MAX)
+ && w <= (Tcl_WideInt)(ULONG_MAX)) {
+ l = Tcl_WideAsLong(w);
} else {
goto tooBig;
}
-
#else
-
l = objPtr->internalRep.longValue;
-
#endif
-
} else {
- Tcl_Panic( "string->integer conversion failed to convert the obj." );
+ Tcl_Panic("string->integer conversion failed to convert the obj.");
}
if (((long)((int)l)) == l) {
@@ -2369,17 +2363,16 @@ Tcl_GetLongFromObj(interp, objPtr, longPtr)
{
register int result;
- if ( objPtr->typePtr != &tclIntType
- && objPtr->typePtr != &tclWideIntType ) {
- result = SetIntOrWideFromAny( interp, objPtr );
- if ( result != TCL_OK ) {
+ if (objPtr->typePtr != &tclIntType
+ && objPtr->typePtr != &tclWideIntType) {
+ result = SetIntOrWideFromAny(interp, objPtr);
+ if (result != TCL_OK) {
return result;
}
}
#ifndef TCL_WIDE_INT_IS_LONG
-
- if ( objPtr->typePtr == &tclWideIntType ) {
+ if (objPtr->typePtr == &tclWideIntType) {
/*
* If the object is already a wide integer, don't convert it.
* This code allows for any integer in the range -ULONG_MAX to
@@ -2389,9 +2382,9 @@ Tcl_GetLongFromObj(interp, objPtr, longPtr)
* wide integers to 32-bit ones in the internal rep.
*/
Tcl_WideInt w = objPtr->internalRep.wideValue;
- if ( w >= -(Tcl_WideInt)(ULONG_MAX)
- && w <= (Tcl_WideInt)(ULONG_MAX) ) {
- *longPtr = Tcl_WideAsLong( w );
+ if (w >= -(Tcl_WideInt)(ULONG_MAX)
+ && w <= (Tcl_WideInt)(ULONG_MAX)) {
+ *longPtr = Tcl_WideAsLong(w);
return TCL_OK;
} else {
if (interp != NULL) {
@@ -2402,7 +2395,6 @@ Tcl_GetLongFromObj(interp, objPtr, longPtr)
return TCL_ERROR;
}
}
-
#endif
*longPtr = objPtr->internalRep.longValue;
@@ -2815,21 +2807,20 @@ Tcl_DbIncrRefCount(objPtr, file, line)
* since thread local storage can be finalized before the
* last Tcl_Obj is freed.
*/
- if (!TclInExit())
- {
- Tcl_HashTable *tablePtr;
- Tcl_HashEntry *hPtr;
- ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
- tablePtr = tsdPtr->objThreadMap;
- if (!tablePtr) {
- Tcl_Panic("object table not initialized");
- }
- hPtr = Tcl_FindHashEntry(tablePtr, (char *) objPtr);
- if (!hPtr) {
- Tcl_Panic("%s%s",
- "Trying to incr ref count of ",
- "Tcl_Obj allocated in another thread");
- }
+ if (!TclInExit()) {
+ Tcl_HashTable *tablePtr;
+ Tcl_HashEntry *hPtr;
+ ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
+ tablePtr = tsdPtr->objThreadMap;
+ if (!tablePtr) {
+ Tcl_Panic("object table not initialized");
+ }
+ hPtr = Tcl_FindHashEntry(tablePtr, (char *) objPtr);
+ if (!hPtr) {
+ Tcl_Panic("%s%s",
+ "Trying to incr ref count of ",
+ "Tcl_Obj allocated in another thread");
+ }
}
# endif
#endif
@@ -2879,26 +2870,25 @@ Tcl_DbDecrRefCount(objPtr, file, line)
* since thread local storage can be finalized before the
* last Tcl_Obj is freed.
*/
- if (!TclInExit())
- {
- Tcl_HashTable *tablePtr;
- Tcl_HashEntry *hPtr;
- ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
- tablePtr = tsdPtr->objThreadMap;
- if (!tablePtr) {
- Tcl_Panic("object table not initialized");
- }
- hPtr = Tcl_FindHashEntry(tablePtr, (char *) objPtr);
- if (!hPtr) {
- Tcl_Panic("%s%s",
- "Trying to decr ref count of",
- "Tcl_Obj allocated in another thread");
- }
-
- /* If the Tcl_Obj is going to be deleted, remove the entry */
- if ((((objPtr)->refCount) - 1) <= 0) {
- Tcl_DeleteHashEntry(hPtr);
- }
+ if (!TclInExit()) {
+ Tcl_HashTable *tablePtr;
+ Tcl_HashEntry *hPtr;
+ ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
+ tablePtr = tsdPtr->objThreadMap;
+ if (!tablePtr) {
+ Tcl_Panic("object table not initialized");
+ }
+ hPtr = Tcl_FindHashEntry(tablePtr, (char *) objPtr);
+ if (!hPtr) {
+ Tcl_Panic("%s%s",
+ "Trying to decr ref count of",
+ "Tcl_Obj allocated in another thread");
+ }
+
+ /* If the Tcl_Obj is going to be deleted, remove the entry */
+ if ((((objPtr)->refCount) - 1) <= 0) {
+ Tcl_DeleteHashEntry(hPtr);
+ }
}
# endif
#endif
@@ -2949,21 +2939,20 @@ Tcl_DbIsShared(objPtr, file, line)
* since thread local storage can be finalized before the
* last Tcl_Obj is freed.
*/
- if (!TclInExit())
- {
- Tcl_HashTable *tablePtr;
- Tcl_HashEntry *hPtr;
- ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
- tablePtr = tsdPtr->objThreadMap;
- if (!tablePtr) {
- Tcl_Panic("object table not initialized");
- }
- hPtr = Tcl_FindHashEntry(tablePtr, (char *) objPtr);
- if (!hPtr) {
- Tcl_Panic("%s%s",
- "Trying to check shared status of",
- "Tcl_Obj allocated in another thread");
- }
+ if (!TclInExit()) {
+ Tcl_HashTable *tablePtr;
+ Tcl_HashEntry *hPtr;
+ ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
+ tablePtr = tsdPtr->objThreadMap;
+ if (!tablePtr) {
+ Tcl_Panic("object table not initialized");
+ }
+ hPtr = Tcl_FindHashEntry(tablePtr, (char *) objPtr);
+ if (!hPtr) {
+ Tcl_Panic("%s%s",
+ "Trying to check shared status of",
+ "Tcl_Obj allocated in another thread");
+ }
}
# endif
#endif
@@ -3234,11 +3223,11 @@ Tcl_GetCommandFromObj(interp, objPtr)
*/
if (objPtr->typePtr != &tclCmdNameType) {
- result = tclCmdNameType.setFromAnyProc(interp, objPtr);
- if (result != TCL_OK) {
+ result = tclCmdNameType.setFromAnyProc(interp, objPtr);
+ if (result != TCL_OK) {
iPtr->varFramePtr = savedFramePtr;
- return (Tcl_Command) NULL;
- }
+ return (Tcl_Command) NULL;
+ }
}
resPtr = (ResolvedCmdName *) objPtr->internalRep.twoPtrValue.ptr1;
@@ -3267,22 +3256,22 @@ Tcl_GetCommandFromObj(interp, objPtr)
&& (resPtr->refNsPtr == currNsPtr)
&& (resPtr->refNsId == currNsPtr->nsId)
&& (resPtr->refNsCmdEpoch == currNsPtr->cmdRefEpoch)) {
- cmdPtr = resPtr->cmdPtr;
- if (cmdPtr->cmdEpoch != resPtr->cmdEpoch) {
- cmdPtr = NULL;
- }
+ cmdPtr = resPtr->cmdPtr;
+ if (cmdPtr->cmdEpoch != resPtr->cmdEpoch) {
+ cmdPtr = NULL;
+ }
}
if (cmdPtr == NULL) {
- result = tclCmdNameType.setFromAnyProc(interp, objPtr);
- if (result != TCL_OK) {
+ result = tclCmdNameType.setFromAnyProc(interp, objPtr);
+ if (result != TCL_OK) {
iPtr->varFramePtr = savedFramePtr;
- return (Tcl_Command) NULL;
- }
- resPtr = (ResolvedCmdName *) objPtr->internalRep.twoPtrValue.ptr1;
- if (resPtr != NULL) {
- cmdPtr = resPtr->cmdPtr;
- }
+ return (Tcl_Command) NULL;
+ }
+ resPtr = (ResolvedCmdName *) objPtr->internalRep.twoPtrValue.ptr1;
+ if (resPtr != NULL) {
+ cmdPtr = resPtr->cmdPtr;
+ }
}
iPtr->varFramePtr = savedFramePtr;
return (Tcl_Command) cmdPtr;
@@ -3388,18 +3377,18 @@ FreeCmdNameInternalRep(objPtr)
* If there are no more uses, free the ResolvedCmdName structure.
*/
- resPtr->refCount--;
- if (resPtr->refCount == 0) {
- /*
+ resPtr->refCount--;
+ if (resPtr->refCount == 0) {
+ /*
* Now free the cached command, unless it is still in its
- * hash table or if there are other references to it
- * from other cmdName objects.
+ * hash table or if there are other references to it
+ * from other cmdName objects.
*/
- Command *cmdPtr = resPtr->cmdPtr;
- TclCleanupCommand(cmdPtr);
- ckfree((char *) resPtr);
- }
+ Command *cmdPtr = resPtr->cmdPtr;
+ TclCleanupCommand(cmdPtr);
+ ckfree((char *) resPtr);
+ }
}
}
@@ -3429,12 +3418,12 @@ DupCmdNameInternalRep(srcPtr, copyPtr)
register Tcl_Obj *copyPtr; /* Object with internal rep to set. */
{
register ResolvedCmdName *resPtr =
- (ResolvedCmdName *) srcPtr->internalRep.twoPtrValue.ptr1;
+ (ResolvedCmdName *) srcPtr->internalRep.twoPtrValue.ptr1;
copyPtr->internalRep.twoPtrValue.ptr1 = (VOID *) resPtr;
copyPtr->internalRep.twoPtrValue.ptr2 = NULL;
if (resPtr != NULL) {
- resPtr->refCount++;
+ resPtr->refCount++;
}
copyPtr->typePtr = &tclCmdNameType;
}
@@ -3504,13 +3493,13 @@ SetCmdNameFromAny(interp, objPtr)
}
cmdPtr->refCount++;
- resPtr = (ResolvedCmdName *) ckalloc(sizeof(ResolvedCmdName));
- resPtr->cmdPtr = cmdPtr;
- resPtr->refNsPtr = currNsPtr;
- resPtr->refNsId = currNsPtr->nsId;
- resPtr->refNsCmdEpoch = currNsPtr->cmdRefEpoch;
- resPtr->cmdEpoch = cmdPtr->cmdEpoch;
- resPtr->refCount = 1;
+ resPtr = (ResolvedCmdName *) ckalloc(sizeof(ResolvedCmdName));
+ resPtr->cmdPtr = cmdPtr;
+ resPtr->refNsPtr = currNsPtr;
+ resPtr->refNsId = currNsPtr->nsId;
+ resPtr->refNsCmdEpoch = currNsPtr->cmdRefEpoch;
+ resPtr->cmdEpoch = cmdPtr->cmdEpoch;
+ resPtr->refCount = 1;
} else {
resPtr = NULL; /* no command named "name" was found */
}