summaryrefslogtreecommitdiffstats
path: root/generic/tcl.h
diff options
context:
space:
mode:
authormdejong <mdejong>2003-07-22 00:59:57 (GMT)
committermdejong <mdejong>2003-07-22 00:59:57 (GMT)
commitce198068acc4ff17e7c6d6b2ab4278ee933ec117 (patch)
treed3afea75fc0d6fc2565a51ce9f8b3e99ce8d3dc6 /generic/tcl.h
parent2fef44444804c9b45a356ef18edc4254a7805b6f (diff)
downloadtcl-ce198068acc4ff17e7c6d6b2ab4278ee933ec117.zip
tcl-ce198068acc4ff17e7c6d6b2ab4278ee933ec117.tar.gz
tcl-ce198068acc4ff17e7c6d6b2ab4278ee933ec117.tar.bz2
Check that the thread incrementing or decrementing
the ref count of a Tcl_Obj is the thread that originally allocated the thread. This fail fast behavior will catch programming errors that allow a single Tcl_Obj to be accessed from multiple threads. * generic/tcl.h (Tcl_Obj): Add allocThread member to Tcl_Obj. This member records the thread id the Tcl_Obj was allocated. It is used to check that any future ref count incr or decr is done from the same thread that allocated the Tcl_Obj. This member is defined only when threads and mem debug are enabled. * generic/tclInt.h (TclNewObj, TclDbNewObj, TclDecrRefCount): Define TclNewObj and TclDbNewObj using TclDbInitNewObj when mem debug is enabled. This fixes a problem where TclNewObj calls did not work the same as TclDbNewObj when mem debug was enabled. * generic/tclObj.c (TclDbInitNewObj, Tcl_DbIncrRefCount, Tcl_DbDecrRefCount): Add new helper to init Tcl_Obj members when mem debug is enabled. Init the allocThread member in TclDbInitNewObj and check it in Tcl_DbIncrRefCount and Tcl_DbDecrRefCount to make sure a Tcl_Obj allocated in one thread is not being acted upon in another thread.
Diffstat (limited to 'generic/tcl.h')
-rw-r--r--generic/tcl.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/generic/tcl.h b/generic/tcl.h
index 48a6c15..bbe13a7 100644
--- a/generic/tcl.h
+++ b/generic/tcl.h
@@ -13,7 +13,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tcl.h,v 1.160 2003/07/18 02:02:02 das Exp $
+ * RCS: @(#) $Id: tcl.h,v 1.161 2003/07/22 00:59:58 mdejong Exp $
*/
#ifndef _TCL
@@ -778,6 +778,15 @@ typedef struct Tcl_Obj {
VOID *ptr2;
} twoPtrValue;
} internalRep;
+
+ /*
+ * Thread id used to check that calls to Tcl_IncrRefCount,
+ * Tcl_DecrRefCount, and Tcl_IsShared are being made
+ * from the thread that originally allocated the Tcl_Obj.
+ */
+#if defined(TCL_MEM_DEBUG) && defined(TCL_THREADS)
+ Tcl_ThreadId allocThread;
+#endif
} Tcl_Obj;