summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiguel Sofer <miguel.sofer@gmail.com>2004-05-06 04:41:52 (GMT)
committerMiguel Sofer <miguel.sofer@gmail.com>2004-05-06 04:41:52 (GMT)
commitfcc10d4dd68b2d659c7554f1d07781320a75a74b (patch)
treeeb1d8657ba0059d390e61248cdb27928523dca9a
parentfb4ad76021c0fb42e1515cbabaec082a4704d394 (diff)
downloadtcl-fcc10d4dd68b2d659c7554f1d07781320a75a74b.zip
tcl-fcc10d4dd68b2d659c7554f1d07781320a75a74b.tar.gz
tcl-fcc10d4dd68b2d659c7554f1d07781320a75a74b.tar.bz2
* generic/tclInt.h:
* generic/tclObj.c (TclFreeObj): made TclFreeObj use the new macro TclFreeObjMacro(), so that the allocation and freeing of Tcl_Obj is defined in a single spot (the macros in tclInt.h), with the exception of the TCL_MEM_DEBUG case. The #ifdef logic for the corresponding macros has been reformulated to make it clearer.
-rw-r--r--ChangeLog10
-rw-r--r--generic/tclInt.h68
-rw-r--r--generic/tclObj.c30
3 files changed, 56 insertions, 52 deletions
diff --git a/ChangeLog b/ChangeLog
index 8505790..137651f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2004-05-06 Miguel Sofer <msofer@users.sf.net>
+
+ * generic/tclInt.h:
+ * generic/tclObj.c (TclFreeObj): made TclFreeObj use the new macro
+ TclFreeObjMacro(), so that the allocation and freeing of Tcl_Obj
+ is defined in a single spot (the macros in tclInt.h), with the
+ exception of the TCL_MEM_DEBUG case.
+ The #ifdef logic for the corresponding macros has been reformulated
+ to make it clearer.
+
2004-05-05 Donal K. Fellows <donal.k.fellows@man.ac.uk>
* doc/break.n, doc/continue.n, doc/for.n, doc/while.n: More examples.
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 361a7ea..4b74c7b 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclInt.h,v 1.157 2004/05/04 20:09:33 dgp Exp $
+ * RCS: @(#) $Id: tclInt.h,v 1.158 2004/05/06 04:41:53 msofer Exp $
*/
#ifndef _TCLINT
@@ -2139,39 +2139,22 @@ EXTERN Tcl_Obj *TclPtrIncrWideVar _ANSI_ARGS_((Tcl_Interp *interp, Var *varPtr,
# define TclDecrRefCount(objPtr) \
if (--(objPtr)->refCount <= 0) { \
- if (((objPtr)->typePtr != NULL) \
- && ((objPtr)->typePtr->freeIntRepProc != NULL)) { \
- (objPtr)->typePtr->freeIntRepProc(objPtr); \
- } \
- if (((objPtr)->bytes != NULL) \
- && ((objPtr)->bytes != tclEmptyStringRep)) { \
- ckfree((char *) (objPtr)->bytes); \
- } \
- TclFreeObjStorage(objPtr); \
- TclIncrObjsFreed(); \
- }
-#endif /* TCL_MEM_DEBUG */
-
-#ifdef TCL_MEM_DEBUG
-EXTERN void TclDbInitNewObj _ANSI_ARGS_((Tcl_Obj *objPtr));
-
-# define TclDbNewObj(objPtr, file, line) \
- TclIncrObjsAllocated(); \
- (objPtr) = (Tcl_Obj *) Tcl_DbCkalloc(sizeof(Tcl_Obj), (file), (line)); \
- TclDbInitNewObj(objPtr);
+ TclFreeObjMacro(objPtr); \
+ }
-# define TclNewObj(objPtr) \
- TclDbNewObj(objPtr, __FILE__, __LINE__);
-
-# define TclDecrRefCount(objPtr) \
- Tcl_DbDecrRefCount(objPtr, __FILE__, __LINE__)
-
-# define TclNewListObjDirect(objc, objv) \
- TclDbNewListObjDirect(objc, objv, __FILE__, __LINE__)
-
-#undef USE_THREAD_ALLOC
+#define TclFreeObjMacro(objPtr) \
+ if (((objPtr)->typePtr != NULL) \
+ && ((objPtr)->typePtr->freeIntRepProc != NULL)) { \
+ (objPtr)->typePtr->freeIntRepProc(objPtr); \
+ } \
+ if (((objPtr)->bytes != NULL) \
+ && ((objPtr)->bytes != tclEmptyStringRep)) { \
+ ckfree((char *) (objPtr)->bytes); \
+ } \
+ TclFreeObjStorage(objPtr); \
+ TclIncrObjsFreed()
-#elif defined(PURIFY)
+#if defined(PURIFY)
/*
* The PURIFY mode is like the regular mode, but instead of doing block
@@ -2205,7 +2188,7 @@ EXTERN void TclpSetAllocCache _ANSI_ARGS_((void *));
# define TclFreeObjStorage(objPtr) \
TclThreadFreeObj((objPtr))
-#else /* not TCL_MEM_DEBUG */
+#else /* not PURIFY or USE_THREAD_ALLOC */
#ifdef TCL_THREADS
/* declared in tclObj.c */
@@ -2227,7 +2210,26 @@ extern Tcl_Mutex tclObjMutex;
(objPtr)->internalRep.otherValuePtr = (VOID *) tclFreeObjList; \
tclFreeObjList = (objPtr); \
Tcl_MutexUnlock(&tclObjMutex)
+#endif
+
+#else /* TCL_MEM_DEBUG */
+EXTERN void TclDbInitNewObj _ANSI_ARGS_((Tcl_Obj *objPtr));
+
+# define TclDbNewObj(objPtr, file, line) \
+ TclIncrObjsAllocated(); \
+ (objPtr) = (Tcl_Obj *) Tcl_DbCkalloc(sizeof(Tcl_Obj), (file), (line)); \
+ TclDbInitNewObj(objPtr);
+
+# define TclNewObj(objPtr) \
+ TclDbNewObj(objPtr, __FILE__, __LINE__);
+
+# define TclDecrRefCount(objPtr) \
+ Tcl_DbDecrRefCount(objPtr, __FILE__, __LINE__)
+# define TclNewListObjDirect(objc, objv) \
+ TclDbNewListObjDirect(objc, objv, __FILE__, __LINE__)
+
+#undef USE_THREAD_ALLOC
#endif /* TCL_MEM_DEBUG */
/*
diff --git a/generic/tclObj.c b/generic/tclObj.c
index f207268..d4b790e 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.58 2004/04/19 18:40:59 kennykb Exp $
+ * RCS: @(#) $Id: tclObj.c,v 1.59 2004/05/06 04:41:53 msofer Exp $
*/
#include "tclInt.h"
@@ -733,46 +733,38 @@ TclAllocateFreeObjects()
*----------------------------------------------------------------------
*/
+#ifdef TCL_MEM_DEBUG
void
TclFreeObj(objPtr)
register Tcl_Obj *objPtr; /* The object to be freed. */
{
register Tcl_ObjType *typePtr = objPtr->typePtr;
-#ifdef TCL_MEM_DEBUG
if ((objPtr)->refCount < -1) {
Tcl_Panic("Reference count for %lx was negative", objPtr);
}
-#endif /* TCL_MEM_DEBUG */
if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
typePtr->freeIntRepProc(objPtr);
}
Tcl_InvalidateStringRep(objPtr);
- /*
- * If debugging Tcl's memory usage, deallocate the object using ckfree.
- * Otherwise, deallocate it by adding it onto the list of free
- * Tcl_Obj structs we maintain.
- */
-
-#if defined(TCL_MEM_DEBUG) || defined(PURIFY)
Tcl_MutexLock(&tclObjMutex);
ckfree((char *) objPtr);
Tcl_MutexUnlock(&tclObjMutex);
-#elif defined(TCL_THREADS) && defined(USE_THREAD_ALLOC)
- TclThreadFreeObj(objPtr);
-#else
- Tcl_MutexLock(&tclObjMutex);
- objPtr->internalRep.otherValuePtr = (VOID *) tclFreeObjList;
- tclFreeObjList = objPtr;
- Tcl_MutexUnlock(&tclObjMutex);
-#endif /* TCL_MEM_DEBUG */
-
#ifdef TCL_COMPILE_STATS
tclObjsFreed++;
#endif /* TCL_COMPILE_STATS */
}
+#else /* TCL_MEM_DEBUG */
+
+void
+TclFreeObj(objPtr)
+ register Tcl_Obj *objPtr; /* The object to be freed. */
+{
+ TclFreeObjMacro(objPtr);
+}
+#endif
/*
*----------------------------------------------------------------------