Index: generic/tcl.decls ================================================================== --- generic/tcl.decls +++ generic/tcl.decls @@ -130,11 +130,11 @@ const char *file, int line) } declare 29 { Tcl_Obj *Tcl_DuplicateObj(Tcl_Obj *objPtr) } -declare 30 { +declare 30 {deprecated {Kept only for deployed refcounting macros}} { void TclFreeObj(Tcl_Obj *objPtr) } declare 31 { int Tcl_GetBoolean(Tcl_Interp *interp, const char *src, int *boolPtr) } @@ -2362,10 +2362,24 @@ const Tcl_ObjIntRep *irPtr) } declare 640 { int Tcl_HasStringRep(Tcl_Obj *objPtr) } + +# TIP #506 +declare 641 { + void Tcl_IncrRefCount(Tcl_Obj *objPtr) +} + +declare 642 { + void Tcl_DecrRefCount(Tcl_Obj *objPtr) +} + +declare 643 { + int Tcl_IsShared(Tcl_Obj *objPtr) +} + # ----- BASELINE -- FOR -- 8.7.0 ----- # ############################################################################## # Define the platform specific public Tcl interface. These functions are only Index: generic/tcl.h ================================================================== --- generic/tcl.h +++ generic/tcl.h @@ -799,21 +799,10 @@ * internal rep. NULL indicates the object has * no internal rep (has no type). */ Tcl_ObjIntRep internalRep; /* The internal representation: */ } Tcl_Obj; -/* - * Macros to increment and decrement a Tcl_Obj's reference count, and to test - * whether an object is shared (i.e. has reference count > 1). Note: clients - * should use Tcl_DecrRefCount() when they are finished using an object, and - * should never call TclFreeObj() directly. TclFreeObj() is only defined and - * made public in tcl.h to support Tcl_DecrRefCount's macro definition. - */ - -void Tcl_IncrRefCount(Tcl_Obj *objPtr); -void Tcl_DecrRefCount(Tcl_Obj *objPtr); -int Tcl_IsShared(Tcl_Obj *objPtr); /* *---------------------------------------------------------------------------- * The following structure contains the state needed by Tcl_SaveResult. No-one * outside of Tcl should access any of these fields. This structure is @@ -2483,32 +2472,19 @@ # define Tcl_ValidateAllMemory(x,y) #endif /* !TCL_MEM_DEBUG */ #ifdef TCL_MEM_DEBUG +# undef Tcl_IncrRefCount # define Tcl_IncrRefCount(objPtr) \ Tcl_DbIncrRefCount(objPtr, __FILE__, __LINE__) +# undef Tcl_DecrRefCount # define Tcl_DecrRefCount(objPtr) \ Tcl_DbDecrRefCount(objPtr, __FILE__, __LINE__) +# undef Tcl_IsShared # define Tcl_IsShared(objPtr) \ Tcl_DbIsShared(objPtr, __FILE__, __LINE__) -#else -# define Tcl_IncrRefCount(objPtr) \ - ++(objPtr)->refCount - /* - * Use do/while0 idiom for optimum correctness without compiler warnings. - * http://c2.com/cgi/wiki?TrivialDoWhileLoop - */ -# define Tcl_DecrRefCount(objPtr) \ - do { \ - Tcl_Obj *_objPtr = (objPtr); \ - if ((_objPtr)->refCount-- <= 1) { \ - TclFreeObj(_objPtr); \ - } \ - } while(0) -# define Tcl_IsShared(objPtr) \ - ((objPtr)->refCount > 1) #endif /* * Macros and definitions that help to debug the use of Tcl objects. When * TCL_MEM_DEBUG is defined, the Tcl_New declarations are overridden to call Index: generic/tclDecls.h ================================================================== --- generic/tclDecls.h +++ generic/tclDecls.h @@ -141,11 +141,12 @@ EXTERN Tcl_Obj * Tcl_DbNewStringObj(const char *bytes, int length, const char *file, int line); /* 29 */ EXTERN Tcl_Obj * Tcl_DuplicateObj(Tcl_Obj *objPtr); /* 30 */ -EXTERN void TclFreeObj(Tcl_Obj *objPtr); +TCL_DEPRECATED("Kept only for deployed refcounting macros") +void TclFreeObj(Tcl_Obj *objPtr); /* 31 */ EXTERN int Tcl_GetBoolean(Tcl_Interp *interp, const char *src, int *boolPtr); /* 32 */ EXTERN int Tcl_GetBooleanFromObj(Tcl_Interp *interp, @@ -1887,10 +1888,16 @@ EXTERN void Tcl_StoreIntRep(Tcl_Obj *objPtr, const Tcl_ObjType *typePtr, const Tcl_ObjIntRep *irPtr); /* 640 */ EXTERN int Tcl_HasStringRep(Tcl_Obj *objPtr); +/* 641 */ +EXTERN void Tcl_IncrRefCount(Tcl_Obj *objPtr); +/* 642 */ +EXTERN void Tcl_DecrRefCount(Tcl_Obj *objPtr); +/* 643 */ +EXTERN int Tcl_IsShared(Tcl_Obj *objPtr); typedef struct { const struct TclPlatStubs *tclPlatStubs; const struct TclIntStubs *tclIntStubs; const struct TclIntPlatStubs *tclIntPlatStubs; @@ -1944,11 +1951,11 @@ Tcl_Obj * (*tcl_DbNewListObj) (int objc, Tcl_Obj *const *objv, const char *file, int line); /* 25 */ TCL_DEPRECATED_API("No longer in use, changed to macro") Tcl_Obj * (*tcl_DbNewLongObj) (long longValue, const char *file, int line); /* 26 */ Tcl_Obj * (*tcl_DbNewObj) (const char *file, int line); /* 27 */ Tcl_Obj * (*tcl_DbNewStringObj) (const char *bytes, int length, const char *file, int line); /* 28 */ Tcl_Obj * (*tcl_DuplicateObj) (Tcl_Obj *objPtr); /* 29 */ - void (*tclFreeObj) (Tcl_Obj *objPtr); /* 30 */ + TCL_DEPRECATED_API("Kept only for deployed refcounting macros") void (*tclFreeObj) (Tcl_Obj *objPtr); /* 30 */ int (*tcl_GetBoolean) (Tcl_Interp *interp, const char *src, int *boolPtr); /* 31 */ int (*tcl_GetBooleanFromObj) (Tcl_Interp *interp, Tcl_Obj *objPtr, int *boolPtr); /* 32 */ unsigned char * (*tcl_GetByteArrayFromObj) (Tcl_Obj *objPtr, int *lengthPtr); /* 33 */ int (*tcl_GetDouble) (Tcl_Interp *interp, const char *src, double *doublePtr); /* 34 */ int (*tcl_GetDoubleFromObj) (Tcl_Interp *interp, Tcl_Obj *objPtr, double *doublePtr); /* 35 */ @@ -2563,10 +2570,13 @@ void (*tcl_FreeIntRep) (Tcl_Obj *objPtr); /* 636 */ char * (*tcl_InitStringRep) (Tcl_Obj *objPtr, const char *bytes, unsigned int numBytes); /* 637 */ Tcl_ObjIntRep * (*tcl_FetchIntRep) (Tcl_Obj *objPtr, const Tcl_ObjType *typePtr); /* 638 */ void (*tcl_StoreIntRep) (Tcl_Obj *objPtr, const Tcl_ObjType *typePtr, const Tcl_ObjIntRep *irPtr); /* 639 */ int (*tcl_HasStringRep) (Tcl_Obj *objPtr); /* 640 */ + void (*tcl_IncrRefCount) (Tcl_Obj *objPtr); /* 641 */ + void (*tcl_DecrRefCount) (Tcl_Obj *objPtr); /* 642 */ + int (*tcl_IsShared) (Tcl_Obj *objPtr); /* 643 */ } TclStubs; extern const TclStubs *tclStubsPtr; #ifdef __cplusplus @@ -3875,10 +3885,16 @@ (tclStubsPtr->tcl_FetchIntRep) /* 638 */ #define Tcl_StoreIntRep \ (tclStubsPtr->tcl_StoreIntRep) /* 639 */ #define Tcl_HasStringRep \ (tclStubsPtr->tcl_HasStringRep) /* 640 */ +#define Tcl_IncrRefCount \ + (tclStubsPtr->tcl_IncrRefCount) /* 641 */ +#define Tcl_DecrRefCount \ + (tclStubsPtr->tcl_DecrRefCount) /* 642 */ +#define Tcl_IsShared \ + (tclStubsPtr->tcl_IsShared) /* 643 */ #endif /* defined(USE_TCL_STUBS) */ /* !END!: Do not edit above this line. */ Index: generic/tclObj.c ================================================================== --- generic/tclObj.c +++ generic/tclObj.c @@ -3853,10 +3853,72 @@ } } while (TCL_OK == TclParseNumber(interp, objPtr, "number", NULL, -1, NULL, 0)); return TCL_ERROR; } + +/* + *---------------------------------------------------------------------- + * + * Tcl_IncrRefCount -- + * + * Increments the reference count of the object. + * + * Results: + * None. + * + *---------------------------------------------------------------------- + */ + +void +Tcl_IncrRefCount( + Tcl_Obj *objPtr) /* The object we are registering a reference to. */ +{ + ++(objPtr)->refCount; +} + +/* + *---------------------------------------------------------------------- + * + * Tcl_DecrRefCount -- + * + * Decrements the reference count of the object. + * + * Results: + * None. + * + *---------------------------------------------------------------------- + */ + +void +Tcl_DecrRefCount( + Tcl_Obj *objPtr) /* The object we are releasing a reference to. */ +{ + if (objPtr->refCount-- <= 1) { + TclFreeObj(objPtr); + } +} + +/* + *---------------------------------------------------------------------- + * + * Tcl_IsShared -- + * + * Tests if the object has a ref count greater than one. + * + * Results: + * Boolean value that is the result of the test. + * + *---------------------------------------------------------------------- + */ + +int +Tcl_IsShared( + Tcl_Obj *objPtr) /* The object to test for being shared. */ +{ + return ((objPtr)->refCount > 1); +} /* *---------------------------------------------------------------------- * * Tcl_DbIncrRefCount -- Index: generic/tclStubInit.c ================================================================== --- generic/tclStubInit.c +++ generic/tclStubInit.c @@ -1584,8 +1584,11 @@ Tcl_FreeIntRep, /* 636 */ Tcl_InitStringRep, /* 637 */ Tcl_FetchIntRep, /* 638 */ Tcl_StoreIntRep, /* 639 */ Tcl_HasStringRep, /* 640 */ + Tcl_IncrRefCount, /* 641 */ + Tcl_DecrRefCount, /* 642 */ + Tcl_IsShared, /* 643 */ }; /* !END!: Do not edit above this line. */