From 4ff4072eaa5652ad04b711a62839002a865b6358 Mon Sep 17 00:00:00 2001 From: dgp Date: Wed, 12 Dec 2012 05:01:04 +0000 Subject: Rename the memory routines so that Tcl_Alloc/Tcl_Free/etc become the recommended things for extensions and embedders to call, instead of ckalloc/ckfree/etc. Tcl_Alloc, etc. are macros that can be configured for memory debuggin, as ckalloc, etc. have been and continue to be. --- generic/tcl.decls | 10 +++++----- generic/tcl.h | 18 ++++++++++++------ generic/tclCkalloc.c | 30 ++++++++++++++---------------- generic/tclDecls.h | 40 ++++++++++++++++++++-------------------- generic/tclInt.h | 6 +++--- generic/tclInterp.c | 2 +- generic/tclStubInit.c | 16 ++++++++-------- win/tclAppInit.c | 2 +- 8 files changed, 64 insertions(+), 60 deletions(-) diff --git a/generic/tcl.decls b/generic/tcl.decls index ad725f5..88567e3 100644 --- a/generic/tcl.decls +++ b/generic/tcl.decls @@ -40,13 +40,13 @@ declare 2 { void Tcl_Panic(const char *format, ...) } declare 3 { - char *Tcl_Alloc(unsigned int size) + char *Tcl_MemAlloc(unsigned int size) } declare 4 { - void Tcl_Free(char *ptr) + void Tcl_MemFree(char *ptr) } declare 5 { - char *Tcl_Realloc(char *ptr, unsigned int size) + char *Tcl_MemRealloc(char *ptr, unsigned int size) } declare 6 { char *Tcl_DbCkalloc(unsigned int size, const char *file, int line) @@ -1527,13 +1527,13 @@ declare 427 { int flags, Tcl_CommandTraceProc *proc, ClientData clientData) } declare 428 { - char *Tcl_AttemptAlloc(unsigned int size) + char *Tcl_AttemptMemAlloc(unsigned int size) } declare 429 { char *Tcl_AttemptDbCkalloc(unsigned int size, const char *file, int line) } declare 430 { - char *Tcl_AttemptRealloc(char *ptr, unsigned int size) + char *Tcl_AttemptMemRealloc(char *ptr, unsigned int size) } declare 431 { char *Tcl_AttemptDbCkrealloc(char *ptr, unsigned int size, diff --git a/generic/tcl.h b/generic/tcl.h index 162983b..121ab5c 100644 --- a/generic/tcl.h +++ b/generic/tcl.h @@ -2255,6 +2255,12 @@ TCLAPI void Tcl_GetMemoryInfo(Tcl_DString *dsPtr); * defined in tclCkalloc.c. */ +#define Tcl_Alloc(x) ckalloc(x) +#define Tcl_Free(x) ckfree(x) +#define Tcl_Realloc(x, y) ckrealloc(x, y) +#define Tcl_AttemptAlloc(x) attemptckalloc(x) +#define Tcl_AttemptRealloc(x, y) attemptckrealloc(x, y) + #ifdef TCL_MEM_DEBUG # define ckalloc(x) \ @@ -2271,21 +2277,21 @@ TCLAPI void Tcl_GetMemoryInfo(Tcl_DString *dsPtr); #else /* !TCL_MEM_DEBUG */ /* - * If we are not using the debugging allocator, we should call the Tcl_Alloc, + * If we are not using the debugging allocator, we should call the Tcl_MemAlloc, * et al. routines in order to guarantee that every module is using the same * memory allocator both inside and outside of the Tcl library. */ # define ckalloc(x) \ - ((void *) Tcl_Alloc((unsigned)(x))) + ((void *) Tcl_MemAlloc((unsigned)(x))) # define ckfree(x) \ - Tcl_Free((char *)(x)) + Tcl_MemFree((char *)(x)) # define ckrealloc(x,y) \ - ((void *) Tcl_Realloc((char *)(x), (unsigned)(y))) + ((void *) Tcl_MemRealloc((char *)(x), (unsigned)(y))) # define attemptckalloc(x) \ - ((void *) Tcl_AttemptAlloc((unsigned)(x))) + ((void *) Tcl_AttemptMemAlloc((unsigned)(x))) # define attemptckrealloc(x,y) \ - ((void *) Tcl_AttemptRealloc((char *)(x), (unsigned)(y))) + ((void *) Tcl_AttemptMemRealloc((char *)(x), (unsigned)(y))) # undef Tcl_InitMemory # define Tcl_InitMemory(x) # undef Tcl_DumpActiveMemory diff --git a/generic/tclCkalloc.c b/generic/tclCkalloc.c index ab977cb..71dc45d 100644 --- a/generic/tclCkalloc.c +++ b/generic/tclCkalloc.c @@ -20,11 +20,9 @@ #define FALSE 0 #define TRUE 1 -#undef Tcl_Alloc -#undef Tcl_Free -#undef Tcl_Realloc -#undef Tcl_AttemptAlloc -#undef Tcl_AttemptRealloc +#undef Tcl_MemFree +#undef Tcl_AttemptMemAlloc +#undef Tcl_AttemptMemRealloc #ifdef TCL_MEM_DEBUG @@ -747,35 +745,35 @@ Tcl_AttemptDbCkrealloc( */ char * -Tcl_Alloc( +Tcl_MemAlloc( unsigned int size) { return Tcl_DbCkalloc(size, "unknown", 0); } char * -Tcl_AttemptAlloc( +Tcl_AttemptMemAlloc( unsigned int size) { return Tcl_AttemptDbCkalloc(size, "unknown", 0); } void -Tcl_Free( +Tcl_MemFree( char *ptr) { Tcl_DbCkfree(ptr, "unknown", 0); } char * -Tcl_Realloc( +Tcl_MemRealloc( char *ptr, unsigned int size) { return Tcl_DbCkrealloc(ptr, size, "unknown", 0); } char * -Tcl_AttemptRealloc( +Tcl_AttemptMemRealloc( char *ptr, unsigned int size) { @@ -1038,7 +1036,7 @@ Tcl_InitMemory( /* *---------------------------------------------------------------------- * - * Tcl_Alloc -- + * Tcl_MemAlloc -- * * Interface to TclpAlloc when TCL_MEM_DEBUG is disabled. It does check * that memory was actually allocated. @@ -1047,7 +1045,7 @@ Tcl_InitMemory( */ char * -Tcl_Alloc( +Tcl_MemAlloc( unsigned int size) { char *result; @@ -1099,7 +1097,7 @@ Tcl_DbCkalloc( */ char * -Tcl_AttemptAlloc( +Tcl_AttemptMemAlloc( unsigned int size) { char *result; @@ -1132,7 +1130,7 @@ Tcl_AttemptDbCkalloc( */ char * -Tcl_Realloc( +Tcl_MemRealloc( char *ptr, unsigned int size) { @@ -1176,7 +1174,7 @@ Tcl_DbCkrealloc( */ char * -Tcl_AttemptRealloc( +Tcl_AttemptMemRealloc( char *ptr, unsigned int size) { @@ -1212,7 +1210,7 @@ Tcl_AttemptDbCkrealloc( */ void -Tcl_Free( +Tcl_MemFree( char *ptr) { TclpFree(ptr); diff --git a/generic/tclDecls.h b/generic/tclDecls.h index d38296d..cf75bb6 100644 --- a/generic/tclDecls.h +++ b/generic/tclDecls.h @@ -35,11 +35,11 @@ TCLAPI const char * Tcl_PkgRequireEx(Tcl_Interp *interp, /* 2 */ TCLAPI void Tcl_Panic(const char *format, ...) TCL_FORMAT_PRINTF(1, 2); /* 3 */ -TCLAPI char * Tcl_Alloc(unsigned int size); +TCLAPI char * Tcl_MemAlloc(unsigned int size); /* 4 */ -TCLAPI void Tcl_Free(char *ptr); +TCLAPI void Tcl_MemFree(char *ptr); /* 5 */ -TCLAPI char * Tcl_Realloc(char *ptr, unsigned int size); +TCLAPI char * Tcl_MemRealloc(char *ptr, unsigned int size); /* 6 */ TCLAPI char * Tcl_DbCkalloc(unsigned int size, const char *file, int line); @@ -1201,12 +1201,12 @@ TCLAPI void Tcl_UntraceCommand(Tcl_Interp *interp, Tcl_CommandTraceProc *proc, ClientData clientData); /* 428 */ -TCLAPI char * Tcl_AttemptAlloc(unsigned int size); +TCLAPI char * Tcl_AttemptMemAlloc(unsigned int size); /* 429 */ TCLAPI char * Tcl_AttemptDbCkalloc(unsigned int size, const char *file, int line); /* 430 */ -TCLAPI char * Tcl_AttemptRealloc(char *ptr, unsigned int size); +TCLAPI char * Tcl_AttemptMemRealloc(char *ptr, unsigned int size); /* 431 */ TCLAPI char * Tcl_AttemptDbCkrealloc(char *ptr, unsigned int size, const char *file, int line); @@ -1782,9 +1782,9 @@ typedef struct TclStubs { int (*tcl_PkgProvideEx) (Tcl_Interp *interp, const char *name, const char *version, const void *clientData); /* 0 */ const char * (*tcl_PkgRequireEx) (Tcl_Interp *interp, const char *name, const char *version, int exact, void *clientDataPtr); /* 1 */ void (*tcl_Panic) (const char *format, ...) TCL_FORMAT_PRINTF(1, 2); /* 2 */ - char * (*tcl_Alloc) (unsigned int size); /* 3 */ - void (*tcl_Free) (char *ptr); /* 4 */ - char * (*tcl_Realloc) (char *ptr, unsigned int size); /* 5 */ + char * (*tcl_MemAlloc) (unsigned int size); /* 3 */ + void (*tcl_MemFree) (char *ptr); /* 4 */ + char * (*tcl_MemRealloc) (char *ptr, unsigned int size); /* 5 */ char * (*tcl_DbCkalloc) (unsigned int size, const char *file, int line); /* 6 */ void (*tcl_DbCkfree) (char *ptr, const char *file, int line); /* 7 */ char * (*tcl_DbCkrealloc) (char *ptr, unsigned int size, const char *file, int line); /* 8 */ @@ -2231,9 +2231,9 @@ typedef struct TclStubs { ClientData (*tcl_CommandTraceInfo) (Tcl_Interp *interp, const char *varName, int flags, Tcl_CommandTraceProc *procPtr, ClientData prevClientData); /* 425 */ int (*tcl_TraceCommand) (Tcl_Interp *interp, const char *varName, int flags, Tcl_CommandTraceProc *proc, ClientData clientData); /* 426 */ void (*tcl_UntraceCommand) (Tcl_Interp *interp, const char *varName, int flags, Tcl_CommandTraceProc *proc, ClientData clientData); /* 427 */ - char * (*tcl_AttemptAlloc) (unsigned int size); /* 428 */ + char * (*tcl_AttemptMemAlloc) (unsigned int size); /* 428 */ char * (*tcl_AttemptDbCkalloc) (unsigned int size, const char *file, int line); /* 429 */ - char * (*tcl_AttemptRealloc) (char *ptr, unsigned int size); /* 430 */ + char * (*tcl_AttemptMemRealloc) (char *ptr, unsigned int size); /* 430 */ char * (*tcl_AttemptDbCkrealloc) (char *ptr, unsigned int size, const char *file, int line); /* 431 */ int (*tcl_AttemptSetObjLength) (Tcl_Obj *objPtr, int length); /* 432 */ Tcl_ThreadId (*tcl_GetChannelThread) (Tcl_Channel channel); /* 433 */ @@ -2456,12 +2456,12 @@ extern const TclStubs *tclStubsPtr; (tclStubsPtr->tcl_PkgRequireEx) /* 1 */ #define Tcl_Panic \ (tclStubsPtr->tcl_Panic) /* 2 */ -#define Tcl_Alloc \ - (tclStubsPtr->tcl_Alloc) /* 3 */ -#define Tcl_Free \ - (tclStubsPtr->tcl_Free) /* 4 */ -#define Tcl_Realloc \ - (tclStubsPtr->tcl_Realloc) /* 5 */ +#define Tcl_MemAlloc \ + (tclStubsPtr->tcl_MemAlloc) /* 3 */ +#define Tcl_MemFree \ + (tclStubsPtr->tcl_MemFree) /* 4 */ +#define Tcl_MemRealloc \ + (tclStubsPtr->tcl_MemRealloc) /* 5 */ #define Tcl_DbCkalloc \ (tclStubsPtr->tcl_DbCkalloc) /* 6 */ #define Tcl_DbCkfree \ @@ -3311,12 +3311,12 @@ extern const TclStubs *tclStubsPtr; (tclStubsPtr->tcl_TraceCommand) /* 426 */ #define Tcl_UntraceCommand \ (tclStubsPtr->tcl_UntraceCommand) /* 427 */ -#define Tcl_AttemptAlloc \ - (tclStubsPtr->tcl_AttemptAlloc) /* 428 */ +#define Tcl_AttemptMemAlloc \ + (tclStubsPtr->tcl_AttemptMemAlloc) /* 428 */ #define Tcl_AttemptDbCkalloc \ (tclStubsPtr->tcl_AttemptDbCkalloc) /* 429 */ -#define Tcl_AttemptRealloc \ - (tclStubsPtr->tcl_AttemptRealloc) /* 430 */ +#define Tcl_AttemptMemRealloc \ + (tclStubsPtr->tcl_AttemptMemRealloc) /* 430 */ #define Tcl_AttemptDbCkrealloc \ (tclStubsPtr->tcl_AttemptDbCkrealloc) /* 431 */ #define Tcl_AttemptSetObjLength \ diff --git a/generic/tclInt.h b/generic/tclInt.h index 0efb1b6..eeb685a 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -4776,9 +4776,9 @@ typedef struct NRE_callback { #include "tclTomMathDecls.h" #if !defined(USE_TCL_STUBS) && !defined(TCL_MEM_DEBUG) -#define Tcl_AttemptAlloc(size) TclpAlloc(size) -#define Tcl_AttemptRealloc(ptr, size) TclpRealloc((ptr), (size)) -#define Tcl_Free(ptr) TclpFree(ptr) +#define Tcl_AttemptMemAlloc(size) TclpAlloc(size) +#define Tcl_AttemptMemRealloc(ptr, size) TclpRealloc((ptr), (size)) +#define Tcl_MemFree(ptr) TclpFree(ptr) #endif #endif /* _TCLINT */ diff --git a/generic/tclInterp.c b/generic/tclInterp.c index 0b0f652..f1faccd 100644 --- a/generic/tclInterp.c +++ b/generic/tclInterp.c @@ -3466,7 +3466,7 @@ Tcl_LimitAddHandler( */ if (deleteProc == (Tcl_LimitHandlerDeleteProc *) TCL_DYNAMIC) { - deleteProc = (Tcl_LimitHandlerDeleteProc *) Tcl_Free; + deleteProc = (Tcl_LimitHandlerDeleteProc *) Tcl_MemFree; } if (deleteProc == (Tcl_LimitHandlerDeleteProc *) TCL_STATIC) { deleteProc = NULL; diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c index c836f45..d78d7f1 100644 --- a/generic/tclStubInit.c +++ b/generic/tclStubInit.c @@ -22,9 +22,9 @@ * Remove macros that will interfere with the definitions below. */ -#undef Tcl_Alloc -#undef Tcl_Free -#undef Tcl_Realloc +#undef Tcl_MemAlloc +#undef Tcl_MemFree +#undef Tcl_MemRealloc #undef Tcl_NewBooleanObj #undef Tcl_NewByteArrayObj #undef Tcl_NewDoubleObj @@ -625,9 +625,9 @@ const TclStubs tclStubs = { Tcl_PkgProvideEx, /* 0 */ Tcl_PkgRequireEx, /* 1 */ Tcl_Panic, /* 2 */ - Tcl_Alloc, /* 3 */ - Tcl_Free, /* 4 */ - Tcl_Realloc, /* 5 */ + Tcl_MemAlloc, /* 3 */ + Tcl_MemFree, /* 4 */ + Tcl_MemRealloc, /* 5 */ Tcl_DbCkalloc, /* 6 */ Tcl_DbCkfree, /* 7 */ Tcl_DbCkrealloc, /* 8 */ @@ -1074,9 +1074,9 @@ const TclStubs tclStubs = { Tcl_CommandTraceInfo, /* 425 */ Tcl_TraceCommand, /* 426 */ Tcl_UntraceCommand, /* 427 */ - Tcl_AttemptAlloc, /* 428 */ + Tcl_AttemptMemAlloc, /* 428 */ Tcl_AttemptDbCkalloc, /* 429 */ - Tcl_AttemptRealloc, /* 430 */ + Tcl_AttemptMemRealloc, /* 430 */ Tcl_AttemptDbCkrealloc, /* 431 */ Tcl_AttemptSetObjLength, /* 432 */ Tcl_GetChannelThread, /* 433 */ diff --git a/win/tclAppInit.c b/win/tclAppInit.c index 5ecebea..917cf00 100644 --- a/win/tclAppInit.c +++ b/win/tclAppInit.c @@ -255,7 +255,7 @@ setargv( } /* Make sure we don't call ckalloc through the (not yet initialized) stub table */ - #undef Tcl_Alloc + #undef Tcl_MemAlloc #undef Tcl_DbCkalloc argSpace = ckalloc(size * sizeof(char *) -- cgit v0.12