From 7fd0b15aeb39ec0c839dfd6079fa676971cf1183 Mon Sep 17 00:00:00 2001 From: hobbs Date: Fri, 19 Oct 2001 23:47:57 +0000 Subject: added -DPURIFY object allocation option FossilOrigin-Name: 864588f58dd761967f3026ff4bb3f4eb1726fbb6 --- generic/tclInt.h | 33 ++++++++++++++++++++++++++++++++- generic/tclObj.c | 9 ++++++--- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/generic/tclInt.h b/generic/tclInt.h index 887c7fc..f2e5b8d 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -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: tclInt.h,v 1.42.2.2 2001/09/01 23:06:28 davygrvy Exp $ + * RCS: @(#) $Id: tclInt.h,v 1.42.2.3 2001/10/19 23:47:57 hobbs Exp $ */ #ifndef _TCLINT @@ -2101,6 +2101,37 @@ EXTERN int TclCompileWhileCmd _ANSI_ARGS_((Tcl_Interp *interp, TclIncrObjsFreed(); \ } +#elif defined(PURIFY) + +/* + * The PURIFY mode is like the regular mode, but instead of doing block + * Tcl_Obj allocation and keeping a freed list for efficiency, it always + * allocates and frees a single Tcl_Obj so that tools like Purify can + * better track memory leaks + */ + +# define TclNewObj(objPtr) \ + (objPtr) = (Tcl_Obj *) Tcl_Ckalloc(sizeof(Tcl_Obj)); \ + (objPtr)->refCount = 0; \ + (objPtr)->bytes = tclEmptyStringRep; \ + (objPtr)->length = 0; \ + (objPtr)->typePtr = NULL; \ + TclIncrObjsAllocated(); + +# define TclDecrRefCount(objPtr) \ + if (--(objPtr)->refCount <= 0) { \ + if (((objPtr)->bytes != NULL) \ + && ((objPtr)->bytes != tclEmptyStringRep)) { \ + ckfree((char *) (objPtr)->bytes); \ + } \ + if (((objPtr)->typePtr != NULL) \ + && ((objPtr)->typePtr->freeIntRepProc != NULL)) { \ + (objPtr)->typePtr->freeIntRepProc(objPtr); \ + } \ + ckfree((char *) (objPtr)); \ + TclIncrObjsFreed(); \ + } + #else /* not TCL_MEM_DEBUG */ #ifdef TCL_THREADS diff --git a/generic/tclObj.c b/generic/tclObj.c index b00207b..58e2dd2 100644 --- a/generic/tclObj.c +++ b/generic/tclObj.c @@ -10,7 +10,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.12.2.4 2001/10/09 20:42:54 msofer Exp $ + * RCS: @(#) $Id: tclObj.c,v 1.12.2.5 2001/10/19 23:47:57 hobbs Exp $ */ #include "tclInt.h" @@ -400,12 +400,15 @@ Tcl_NewObj() */ Tcl_MutexLock(&tclObjMutex); +#ifdef PURIFY + objPtr = (Tcl_Obj *) Tcl_Ckalloc(sizeof(Tcl_Obj)); +#else if (tclFreeObjList == NULL) { TclAllocateFreeObjects(); } objPtr = tclFreeObjList; tclFreeObjList = (Tcl_Obj *) tclFreeObjList->internalRep.otherValuePtr; - +#endif objPtr->refCount = 0; objPtr->bytes = tclEmptyStringRep; objPtr->length = 0; @@ -582,7 +585,7 @@ TclFreeObj(objPtr) */ Tcl_MutexLock(&tclObjMutex); -#ifdef TCL_MEM_DEBUG +#if defined(TCL_MEM_DEBUG) || defined(PURIFY) ckfree((char *) objPtr); #else objPtr->internalRep.otherValuePtr = (VOID *) tclFreeObjList; -- cgit v0.12