diff options
Diffstat (limited to 'generic/tclCkalloc.c')
| -rw-r--r-- | generic/tclCkalloc.c | 102 |
1 files changed, 56 insertions, 46 deletions
diff --git a/generic/tclCkalloc.c b/generic/tclCkalloc.c index 5b5a0d6..5263e82 100644 --- a/generic/tclCkalloc.c +++ b/generic/tclCkalloc.c @@ -20,12 +20,6 @@ #define FALSE 0 #define TRUE 1 -#undef Tcl_Alloc -#undef Tcl_Free -#undef Tcl_Realloc -#undef Tcl_AttemptAlloc -#undef Tcl_AttemptRealloc - #ifdef TCL_MEM_DEBUG /* @@ -36,12 +30,12 @@ typedef struct MemTag { int refCount; /* Number of mem_headers referencing this * tag. */ - char string[1]; /* Actual size of string will be as large as + char string[4]; /* Actual size of string will be as large as * needed for actual tag. This must be the * last field in the structure. */ } MemTag; -#define TAG_SIZE(bytesInString) ((unsigned) ((TclOffset(MemTag, string) + 1) + bytesInString)) +#define TAG_SIZE(bytesInString) ((unsigned) sizeof(MemTag) + bytesInString - 3) static MemTag *curTagPtr = NULL;/* Tag to use in all future mem_headers (set * by "memory tag" command). */ @@ -58,7 +52,7 @@ struct mem_header { struct mem_header *blink; MemTag *tagPtr; /* Tag from "memory tag" command; may be * NULL. */ - const char *file; + CONST char *file; long length; int line; unsigned char low_guard[LOW_GUARD_SIZE]; @@ -132,11 +126,11 @@ static int ckallocInit = 0; */ static int CheckmemCmd(ClientData clientData, Tcl_Interp *interp, - int argc, const char *argv[]); + int argc, CONST char *argv[]); static int MemoryCmd(ClientData clientData, Tcl_Interp *interp, - int argc, const char *argv[]); + int argc, CONST char *argv[]); static void ValidateMemory(struct mem_header *memHeaderP, - const char *file, int line, int nukeGuards); + CONST char *file, int line, int nukeGuards); /* *---------------------------------------------------------------------- @@ -156,6 +150,10 @@ TclInitDbCkalloc(void) if (!ckallocInit) { ckallocInit = 1; ckallocMutexPtr = Tcl_GetAllocMutex(); +#ifndef TCL_THREADS + /* Silence compiler warning */ + (void)ckallocMutexPtr; +#endif } } @@ -189,7 +187,7 @@ TclDumpMemoryInfo(ClientData clientData, int flags) maximum_malloc_packets, (unsigned long)maximum_bytes_malloced); if (flags == 0) { - fprintf((FILE *)clientData, "%s", buf); + fprintf((FILE *)clientData, buf); } else { /* Assume objPtr to append to */ Tcl_AppendToObj((Tcl_Obj *) clientData, buf, -1); @@ -218,7 +216,7 @@ static void ValidateMemory( struct mem_header *memHeaderP, /* Memory chunk to validate */ - const char *file, /* File containing the call to + CONST char *file, /* File containing the call to * Tcl_ValidateAllMemory */ int line, /* Line number of call to * Tcl_ValidateAllMemory */ @@ -244,7 +242,7 @@ ValidateMemory( if (guard_failed) { TclDumpMemoryInfo((ClientData) stderr, 0); fprintf(stderr, "low guard failed at %lx, %s %d\n", - (long unsigned) memHeaderP->body, file, line); + (long unsigned int) memHeaderP->body, file, line); fflush(stderr); /* In case name pointer is bad. */ fprintf(stderr, "%ld bytes allocated at (%s %d)\n", memHeaderP->length, memHeaderP->file, memHeaderP->line); @@ -266,7 +264,7 @@ ValidateMemory( if (guard_failed) { TclDumpMemoryInfo((ClientData) stderr, 0); fprintf(stderr, "high guard failed at %lx, %s %d\n", - (long unsigned) memHeaderP->body, file, line); + (long unsigned int) memHeaderP->body, file, line); fflush(stderr); /* In case name pointer is bad. */ fprintf(stderr, "%ld bytes allocated at (%s %d)\n", memHeaderP->length, memHeaderP->file, @@ -299,7 +297,7 @@ ValidateMemory( void Tcl_ValidateAllMemory( - const char *file, /* File from which Tcl_ValidateAllMemory was + CONST char *file, /* File from which Tcl_ValidateAllMemory was * called. */ int line) /* Line number of call to * Tcl_ValidateAllMemory */ @@ -333,7 +331,7 @@ Tcl_ValidateAllMemory( int Tcl_DumpActiveMemory( - const char *fileName) /* Name of the file to write info to */ + CONST char *fileName) /* Name of the file to write info to */ { FILE *fileP; struct mem_header *memScanP; @@ -350,10 +348,10 @@ Tcl_DumpActiveMemory( Tcl_MutexLock(ckallocMutexPtr); for (memScanP = allocHead; memScanP != NULL; memScanP = memScanP->flink) { - address = &memScanP->body[0]; + address = &memScanP->body [0]; fprintf(fileP, "%8lx - %8lx %7ld @ %s %d %s", - (long unsigned) address, - (long unsigned) address + memScanP->length - 1, + (long unsigned int) address, + (long unsigned int) address + memScanP->length - 1, memScanP->length, memScanP->file, memScanP->line, (memScanP->tagPtr == NULL) ? "" : memScanP->tagPtr->string); (void) fputc('\n', fileP); @@ -387,7 +385,7 @@ Tcl_DumpActiveMemory( char * Tcl_DbCkalloc( unsigned int size, - const char *file, + CONST char *file, int line) { struct mem_header *result = NULL; @@ -457,7 +455,11 @@ Tcl_DbCkalloc( if (break_on_malloc && (total_mallocs >= break_on_malloc)) { break_on_malloc = 0; (void) fflush(stdout); - Tcl_Panic("reached malloc break limit (%d)", total_mallocs); + fprintf(stderr,"reached malloc break limit (%d)\n", + total_mallocs); + fprintf(stderr, "program will now enter C debugger\n"); + (void) fflush(stderr); + abort(); } current_malloc_packets++; @@ -477,7 +479,7 @@ Tcl_DbCkalloc( char * Tcl_AttemptDbCkalloc( unsigned int size, - const char *file, + CONST char *file, int line) { struct mem_header *result = NULL; @@ -546,7 +548,11 @@ Tcl_AttemptDbCkalloc( if (break_on_malloc && (total_mallocs >= break_on_malloc)) { break_on_malloc = 0; (void) fflush(stdout); - Tcl_Panic("reached malloc break limit (%d)", total_mallocs); + fprintf(stderr,"reached malloc break limit (%d)\n", + total_mallocs); + fprintf(stderr, "program will now enter C debugger\n"); + (void) fflush(stderr); + abort(); } current_malloc_packets++; @@ -584,7 +590,7 @@ Tcl_AttemptDbCkalloc( void Tcl_DbCkfree( char *ptr, - const char *file, + CONST char *file, int line) { struct mem_header *memp; @@ -663,7 +669,7 @@ char * Tcl_DbCkrealloc( char *ptr, unsigned int size, - const char *file, + CONST char *file, int line) { char *newPtr; @@ -694,7 +700,7 @@ char * Tcl_AttemptDbCkrealloc( char *ptr, unsigned int size, - const char *file, + CONST char *file, int line) { char *newPtr; @@ -742,6 +748,12 @@ Tcl_AttemptDbCkrealloc( *---------------------------------------------------------------------- */ +#undef Tcl_Alloc +#undef Tcl_Free +#undef Tcl_Realloc +#undef Tcl_AttemptAlloc +#undef Tcl_AttemptRealloc + char * Tcl_Alloc( unsigned int size) @@ -806,9 +818,9 @@ MemoryCmd( ClientData clientData, Tcl_Interp *interp, int argc, - const char *argv[]) + CONST char *argv[]) { - const char *fileName; + CONST char *fileName; FILE *fileP; Tcl_DString buffer; int result; @@ -830,7 +842,7 @@ MemoryCmd( if (fileName == NULL) { return TCL_ERROR; } - result = Tcl_DumpActiveMemory(fileName); + result = Tcl_DumpActiveMemory (fileName); Tcl_DStringFree(&buffer); if (result != TCL_OK) { Tcl_AppendResult(interp, "error accessing ", argv[2], NULL); @@ -852,9 +864,9 @@ MemoryCmd( "%-25s %10d\n%-25s %10d\n%-25s %10d\n%-25s %10lu\n%-25s %10d\n%-25s %10lu\n", "total mallocs", total_mallocs, "total frees", total_frees, "current packets allocated", current_malloc_packets, - "current bytes allocated", (unsigned long)current_bytes_malloced, + "current bytes allocated", current_bytes_malloced, "maximum packets allocated", maximum_malloc_packets, - "maximum bytes allocated", (unsigned long)maximum_bytes_malloced)); + "maximum bytes allocated", maximum_bytes_malloced)); return TCL_OK; } if (strcmp(argv[1],"init") == 0) { @@ -940,7 +952,7 @@ MemoryCmd( } Tcl_AppendResult(interp, "bad option \"", argv[1], - "\": should be active, break_on_malloc, info, init, objs, onexit, " + "\": should be active, break_on_malloc, info, init, onexit, " "tag, trace, trace_on_at_malloc, or validate", NULL); return TCL_ERROR; @@ -978,7 +990,7 @@ CheckmemCmd( ClientData clientData, /* Not used. */ Tcl_Interp *interp, /* Interpreter for evaluation. */ int argc, /* Number of arguments. */ - const char *argv[]) /* String values of arguments. */ + CONST char *argv[]) /* String values of arguments. */ { if (argc != 2) { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], @@ -1012,8 +1024,8 @@ Tcl_InitMemory( * added */ { TclInitDbCkalloc(); - Tcl_CreateCommand(interp, "memory", MemoryCmd, NULL, NULL); - Tcl_CreateCommand(interp, "checkmem", CheckmemCmd, NULL, NULL); + Tcl_CreateCommand(interp, "memory", MemoryCmd, (ClientData) NULL, NULL); + Tcl_CreateCommand(interp, "checkmem", CheckmemCmd, (ClientData) 0, NULL); } @@ -1064,7 +1076,7 @@ Tcl_Alloc( char * Tcl_DbCkalloc( unsigned int size, - const char *file, + CONST char *file, int line) { char *result; @@ -1102,7 +1114,7 @@ Tcl_AttemptAlloc( char * Tcl_AttemptDbCkalloc( unsigned int size, - const char *file, + CONST char *file, int line) { char *result; @@ -1141,7 +1153,7 @@ char * Tcl_DbCkrealloc( char *ptr, unsigned int size, - const char *file, + CONST char *file, int line) { char *result; @@ -1181,7 +1193,7 @@ char * Tcl_AttemptDbCkrealloc( char *ptr, unsigned int size, - const char *file, + CONST char *file, int line) { char *result; @@ -1212,7 +1224,7 @@ Tcl_Free( void Tcl_DbCkfree( char *ptr, - const char *file, + CONST char *file, int line) { TclpFree(ptr); @@ -1237,14 +1249,14 @@ Tcl_InitMemory( int Tcl_DumpActiveMemory( - const char *fileName) + CONST char *fileName) { return TCL_OK; } void Tcl_ValidateAllMemory( - const char *file, + CONST char *file, int line) { } @@ -1307,7 +1319,5 @@ TclFinalizeMemorySubsystem(void) * mode: c * c-basic-offset: 4 * fill-column: 78 - * tab-width: 8 - * indent-tabs-mode: nil * End: */ |
