Skip to content
Tcl Source Code Artifact [9d4c6487d0]
Login

Artifact [9d4c6487d0]

Artifact 9d4c6487d05e4f714bdd08fb05dd38cf03866c37:

Attachment "signalDeletion.patch" to ticket [1512138fff] added by msofer on 2006-06-25 21:25:46.
Index: generic/tclInt.h
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclInt.h,v
retrieving revision 1.271
diff -u -r1.271 tclInt.h
--- generic/tclInt.h	16 Jun 2006 18:35:55 -0000	1.271
+++ generic/tclInt.h	25 Jun 2006 14:02:10 -0000
@@ -2625,15 +2625,20 @@
     (objPtr)->length   = 0; \
     (objPtr)->typePtr  = NULL
 
+/* Invalidate the string rep first so we can use the bytes value \
+ * for our pointer chain, and signal an obj deletion (as opposed \
+ * to shimmering) with 'length == -1' */ \
+
 # define TclDecrRefCount(objPtr) \
     if (--(objPtr)->refCount <= 0) { \
+	if ((objPtr)->bytes \
+	        && ((objPtr)->bytes != tclEmptyStringRep)) { \
+	    ckfree((char *) (objPtr)->bytes); \
+	} \
+        (objPtr)->length = -1; \
 	if ((objPtr)->typePtr && (objPtr)->typePtr->freeIntRepProc) { \
 	    TclFreeObj(objPtr); \
 	} else { \
-	    if ((objPtr)->bytes \
-		    && ((objPtr)->bytes != tclEmptyStringRep)) { \
-		ckfree((char *) (objPtr)->bytes); \
-	    } \
 	    TclFreeObjStorage(objPtr); \
 	    TclIncrObjsFreed(); \
 	} \
Index: generic/tclObj.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclObj.c,v
retrieving revision 1.108
diff -u -r1.108 tclObj.c
--- generic/tclObj.c	21 Jun 2006 03:10:39 -0000	1.108
+++ generic/tclObj.c	25 Jun 2006 14:02:12 -0000
@@ -111,13 +111,8 @@
 #define ObjDeletePending(contextPtr)	((contextPtr)->deletionCount > 0)
 #define ObjOnStack(contextPtr)		((contextPtr)->deletionStack != NULL)
 #define PushObjToDelete(contextPtr,objPtr) \
-    /* Invalidate the string rep first so we can use the bytes value \
-     * for our pointer chain. */ \
-    if (((objPtr)->bytes != NULL) \
-	    && ((objPtr)->bytes != tclEmptyStringRep)) { \
-	ckfree((char *) (objPtr)->bytes); \
-    } \
-    /* Now push onto the head of the stack. */ \
+    /* The string rep is already invalidated so we can use the bytes value \
+     * for our pointer chain: push onto the head of the stack. */ \
     (objPtr)->bytes = (char *) ((contextPtr)->deletionStack); \
     (contextPtr)->deletionStack = (objPtr)
 #define PopObjToDelete(contextPtr,objPtrVar) \
@@ -849,6 +844,13 @@
 	Tcl_Panic("Reference count for %lx was negative", objPtr);
     }
 
+    /* Invalidate the string rep first so we can use the bytes value 
+     * for our pointer chain, and signal an obj deletion (as opposed
+     * to shimmering) with 'length == -1' */ 
+    
+    TclInvalidateStringRep(objPtr);
+    objPtr->length = -1;
+
     if (ObjDeletePending(context)) {
 	PushObjToDelete(context, objPtr);
     } else {
@@ -857,7 +859,6 @@
 	    typePtr->freeIntRepProc(objPtr);
 	    ObjDeletionUnlock(context);
 	}
-	TclInvalidateStringRep(objPtr);
 
 	Tcl_MutexLock(&tclObjMutex);
 	ckfree((char *) objPtr);
@@ -923,9 +924,6 @@
 	    objPtr->typePtr->freeIntRepProc(objPtr);
 	    ObjDeletionUnlock(context);
 
-	    if (objPtr->bytes && (objPtr->bytes != tclEmptyStringRep)) {
-		ckfree((char *) objPtr->bytes);
-	    }
 	    TclFreeObjStorage(objPtr);
 	    TclIncrObjsFreed();
 	    ObjDeletionLock(context);