summaryrefslogtreecommitdiffstats
path: root/generic/tclCkalloc.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2004-10-06 13:05:02 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2004-10-06 13:05:02 (GMT)
commit0a6a0021d3f0743256e44066515c6ab1af8b9f56 (patch)
tree059adbf2651c56114ea9f67329772a5c8827fbd9 /generic/tclCkalloc.c
parent9361f8f6e2dcb015cc85b4113f7ea781891abb6f (diff)
downloadtcl-0a6a0021d3f0743256e44066515c6ab1af8b9f56.zip
tcl-0a6a0021d3f0743256e44066515c6ab1af8b9f56.tar.gz
tcl-0a6a0021d3f0743256e44066515c6ab1af8b9f56.tar.bz2
Minor style guide issues (e.g. making sure all 'if' bodies have braces
around them)
Diffstat (limited to 'generic/tclCkalloc.c')
-rw-r--r--generic/tclCkalloc.c183
1 files changed, 100 insertions, 83 deletions
diff --git a/generic/tclCkalloc.c b/generic/tclCkalloc.c
index 794372d..dbae0fd 100644
--- a/generic/tclCkalloc.c
+++ b/generic/tclCkalloc.c
@@ -13,7 +13,7 @@
*
* This code contributed by Karl Lehenbauer and Mark Diekhans
*
- * RCS: @(#) $Id: tclCkalloc.c,v 1.21 2004/04/06 22:25:48 dgp Exp $
+ * RCS: @(#) $Id: tclCkalloc.c,v 1.22 2004/10/06 13:05:02 dkf Exp $
*/
#include "tclInt.h"
@@ -144,6 +144,7 @@ static void ValidateMemory _ANSI_ARGS_((
*
*----------------------------------------------------------------------
*/
+
void
TclInitDbCkalloc()
{
@@ -161,6 +162,7 @@ TclInitDbCkalloc()
*
*----------------------------------------------------------------------
*/
+
void
TclDumpMemoryInfo(outFile)
FILE *outFile;
@@ -179,7 +181,6 @@ TclDumpMemoryInfo(outFile)
maximum_bytes_malloced);
}
-
/*
*----------------------------------------------------------------------
*
@@ -200,17 +201,17 @@ TclDumpMemoryInfo(outFile)
static void
ValidateMemory(memHeaderP, file, line, nukeGuards)
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
+ int line; /* Line number of call to
* Tcl_ValidateAllMemory */
- int nukeGuards; /* If non-zero, indicates that the
+ int nukeGuards; /* If non-zero, indicates that the
* memory guards are to be reset to 0
* after they have been printed */
{
unsigned char *hiPtr;
- int idx;
- int guard_failed = FALSE;
+ int idx;
+ int guard_failed = FALSE;
int byte;
for (idx = 0; idx < LOW_GUARD_SIZE; idx++) {
@@ -238,7 +239,7 @@ ValidateMemory(memHeaderP, file, line, nukeGuards)
byte = *(hiPtr + idx);
if (byte != GUARD_VALUE) {
guard_failed = TRUE;
- fflush (stdout);
+ fflush(stdout);
byte &= 0xff;
fprintf(stderr, "hi guard byte %d is 0x%x \t%c\n", idx, byte,
(isprint(UCHAR(byte)) ? byte : ' ')); /* INTL: bytes */
@@ -246,7 +247,7 @@ ValidateMemory(memHeaderP, file, line, nukeGuards)
}
if (guard_failed) {
- TclDumpMemoryInfo (stderr);
+ TclDumpMemoryInfo(stderr);
fprintf(stderr, "high guard failed at %lx, %s %d\n",
(long unsigned int) memHeaderP->body, file, line);
fflush(stderr); /* In case name pointer is bad. */
@@ -257,8 +258,8 @@ ValidateMemory(memHeaderP, file, line, nukeGuards)
}
if (nukeGuards) {
- memset ((char *) memHeaderP->low_guard, 0, LOW_GUARD_SIZE);
- memset ((char *) hiPtr, 0, HIGH_GUARD_SIZE);
+ memset((char *) memHeaderP->low_guard, 0, LOW_GUARD_SIZE);
+ memset((char *) hiPtr, 0, HIGH_GUARD_SIZE);
}
}
@@ -278,10 +279,11 @@ ValidateMemory(memHeaderP, file, line, nukeGuards)
*
*----------------------------------------------------------------------
*/
+
void
-Tcl_ValidateAllMemory (file, line)
- CONST char *file; /* File from which Tcl_ValidateAllMemory was called */
- int line; /* Line number of call to Tcl_ValidateAllMemory */
+Tcl_ValidateAllMemory(file, line)
+ CONST char *file; /* File from which Tcl_ValidateAllMemory was called */
+ int line; /* Line number of call to Tcl_ValidateAllMemory */
{
struct mem_header *memScanP;
@@ -308,13 +310,14 @@ Tcl_ValidateAllMemory (file, line)
* will have the file error number left in it.
*----------------------------------------------------------------------
*/
+
int
Tcl_DumpActiveMemory (fileName)
CONST char *fileName; /* Name of the file to write info to */
{
- FILE *fileP;
+ FILE *fileP;
struct mem_header *memScanP;
- char *address;
+ char *address;
if (fileName == NULL) {
fileP = stderr;
@@ -330,15 +333,15 @@ Tcl_DumpActiveMemory (fileName)
address = &memScanP->body [0];
fprintf(fileP, "%8lx - %8lx %7ld @ %s %d %s",
(long unsigned int) address,
- (long unsigned int) address + memScanP->length - 1,
- memScanP->length, memScanP->file, memScanP->line,
- (memScanP->tagPtr == NULL) ? "" : memScanP->tagPtr->string);
+ (long unsigned int) address + memScanP->length - 1,
+ memScanP->length, memScanP->file, memScanP->line,
+ (memScanP->tagPtr == NULL) ? "" : memScanP->tagPtr->string);
(void) fputc('\n', fileP);
}
Tcl_MutexUnlock(ckallocMutexPtr);
if (fileP != stderr) {
- fclose (fileP);
+ fclose(fileP);
}
return TCL_OK;
}
@@ -361,19 +364,21 @@ Tcl_DumpActiveMemory (fileName)
*
*----------------------------------------------------------------------
*/
+
char *
Tcl_DbCkalloc(size, file, line)
unsigned int size;
- CONST char *file;
- int line;
+ CONST char *file;
+ int line;
{
struct mem_header *result;
- if (validate_memory)
- Tcl_ValidateAllMemory (file, line);
+ if (validate_memory) {
+ Tcl_ValidateAllMemory(file, line);
+ }
result = (struct mem_header *) TclpAlloc((unsigned)size +
- sizeof(struct mem_header) + HIGH_GUARD_SIZE);
+ sizeof(struct mem_header) + HIGH_GUARD_SIZE);
if (result == NULL) {
fflush(stdout);
TclDumpMemoryInfo(stderr);
@@ -386,11 +391,11 @@ Tcl_DbCkalloc(size, file, line)
* Link into allocated list.
*/
if (init_malloced_bodies) {
- memset ((VOID *) result, GUARD_VALUE,
+ memset((VOID *) result, GUARD_VALUE,
size + sizeof(struct mem_header) + HIGH_GUARD_SIZE);
} else {
- memset ((char *) result->low_guard, GUARD_VALUE, LOW_GUARD_SIZE);
- memset (result->body + size, GUARD_VALUE, HIGH_GUARD_SIZE);
+ memset((char *) result->low_guard, GUARD_VALUE, LOW_GUARD_SIZE);
+ memset(result->body + size, GUARD_VALUE, HIGH_GUARD_SIZE);
}
if (!ckallocInit) {
TclInitDbCkalloc();
@@ -406,13 +411,14 @@ Tcl_DbCkalloc(size, file, line)
result->flink = allocHead;
result->blink = NULL;
- if (allocHead != NULL)
+ if (allocHead != NULL) {
allocHead->blink = result;
+ }
allocHead = result;
total_mallocs++;
if (trace_on_at_malloc && (total_mallocs >= trace_on_at_malloc)) {
- (void) fflush(stdout);
+ (void) fflush(stdout);
fprintf(stderr, "reached malloc trace enable point (%d)\n",
total_mallocs);
fflush(stderr);
@@ -420,26 +426,29 @@ Tcl_DbCkalloc(size, file, line)
trace_on_at_malloc = 0;
}
- if (alloc_tracing)
+ if (alloc_tracing) {
fprintf(stderr,"ckalloc %lx %u %s %d\n",
(long unsigned int) result->body, size, file, line);
+ }
if (break_on_malloc && (total_mallocs >= break_on_malloc)) {
break_on_malloc = 0;
- (void) fflush(stdout);
+ (void) fflush(stdout);
fprintf(stderr,"reached malloc break limit (%d)\n",
total_mallocs);
fprintf(stderr, "program will now enter C debugger\n");
- (void) fflush(stderr);
+ (void) fflush(stderr);
abort();
}
current_malloc_packets++;
- if (current_malloc_packets > maximum_malloc_packets)
+ if (current_malloc_packets > maximum_malloc_packets) {
maximum_malloc_packets = current_malloc_packets;
+ }
current_bytes_malloced += size;
- if (current_bytes_malloced > maximum_bytes_malloced)
+ if (current_bytes_malloced > maximum_bytes_malloced) {
maximum_bytes_malloced = current_bytes_malloced;
+ }
Tcl_MutexUnlock(ckallocMutexPtr);
@@ -449,16 +458,17 @@ Tcl_DbCkalloc(size, file, line)
char *
Tcl_AttemptDbCkalloc(size, file, line)
unsigned int size;
- CONST char *file;
- int line;
+ CONST char *file;
+ int line;
{
struct mem_header *result;
- if (validate_memory)
- Tcl_ValidateAllMemory (file, line);
+ if (validate_memory) {
+ Tcl_ValidateAllMemory(file, line);
+ }
result = (struct mem_header *) TclpAlloc((unsigned)size +
- sizeof(struct mem_header) + HIGH_GUARD_SIZE);
+ sizeof(struct mem_header) + HIGH_GUARD_SIZE);
if (result == NULL) {
fflush(stdout);
TclDumpMemoryInfo(stderr);
@@ -471,11 +481,11 @@ Tcl_AttemptDbCkalloc(size, file, line)
* Link into allocated list.
*/
if (init_malloced_bodies) {
- memset ((VOID *) result, GUARD_VALUE,
+ memset((VOID *) result, GUARD_VALUE,
size + sizeof(struct mem_header) + HIGH_GUARD_SIZE);
} else {
- memset ((char *) result->low_guard, GUARD_VALUE, LOW_GUARD_SIZE);
- memset (result->body + size, GUARD_VALUE, HIGH_GUARD_SIZE);
+ memset((char *) result->low_guard, GUARD_VALUE, LOW_GUARD_SIZE);
+ memset(result->body + size, GUARD_VALUE, HIGH_GUARD_SIZE);
}
if (!ckallocInit) {
TclInitDbCkalloc();
@@ -491,13 +501,14 @@ Tcl_AttemptDbCkalloc(size, file, line)
result->flink = allocHead;
result->blink = NULL;
- if (allocHead != NULL)
+ if (allocHead != NULL) {
allocHead->blink = result;
+ }
allocHead = result;
total_mallocs++;
if (trace_on_at_malloc && (total_mallocs >= trace_on_at_malloc)) {
- (void) fflush(stdout);
+ (void) fflush(stdout);
fprintf(stderr, "reached malloc trace enable point (%d)\n",
total_mallocs);
fflush(stderr);
@@ -505,32 +516,34 @@ Tcl_AttemptDbCkalloc(size, file, line)
trace_on_at_malloc = 0;
}
- if (alloc_tracing)
+ if (alloc_tracing) {
fprintf(stderr,"ckalloc %lx %u %s %d\n",
(long unsigned int) result->body, size, file, line);
+ }
if (break_on_malloc && (total_mallocs >= break_on_malloc)) {
break_on_malloc = 0;
- (void) fflush(stdout);
+ (void) fflush(stdout);
fprintf(stderr,"reached malloc break limit (%d)\n",
total_mallocs);
fprintf(stderr, "program will now enter C debugger\n");
- (void) fflush(stderr);
+ (void) fflush(stderr);
abort();
}
current_malloc_packets++;
- if (current_malloc_packets > maximum_malloc_packets)
+ if (current_malloc_packets > maximum_malloc_packets) {
maximum_malloc_packets = current_malloc_packets;
+ }
current_bytes_malloced += size;
- if (current_bytes_malloced > maximum_bytes_malloced)
+ if (current_bytes_malloced > maximum_bytes_malloced) {
maximum_bytes_malloced = current_bytes_malloced;
+ }
Tcl_MutexUnlock(ckallocMutexPtr);
return result->body;
}
-
/*
*----------------------------------------------------------------------
@@ -553,9 +566,9 @@ Tcl_AttemptDbCkalloc(size, file, line)
int
Tcl_DbCkfree(ptr, file, line)
- char *ptr;
+ char *ptr;
CONST char *file;
- int line;
+ int line;
{
struct mem_header *memp;
@@ -602,12 +615,15 @@ Tcl_DbCkfree(ptr, file, line)
/*
* Delink from allocated list
*/
- if (memp->flink != NULL)
+ if (memp->flink != NULL) {
memp->flink->blink = memp->blink;
- if (memp->blink != NULL)
+ }
+ if (memp->blink != NULL) {
memp->blink->flink = memp->flink;
- if (allocHead == memp)
+ }
+ if (allocHead == memp) {
allocHead = memp->flink;
+ }
TclpFree((char *) memp);
Tcl_MutexUnlock(ckallocMutexPtr);
@@ -626,12 +642,13 @@ Tcl_DbCkfree(ptr, file, line)
*
*--------------------------------------------------------------------
*/
+
char *
Tcl_DbCkrealloc(ptr, size, file, line)
- char *ptr;
+ char *ptr;
unsigned int size;
- CONST char *file;
- int line;
+ CONST char *file;
+ int line;
{
char *new;
unsigned int copySize;
@@ -660,10 +677,10 @@ Tcl_DbCkrealloc(ptr, size, file, line)
char *
Tcl_AttemptDbCkrealloc(ptr, size, file, line)
- char *ptr;
+ char *ptr;
unsigned int size;
- CONST char *file;
- int line;
+ CONST char *file;
+ int line;
{
char *new;
unsigned int copySize;
@@ -776,11 +793,11 @@ Tcl_AttemptRealloc(ptr, size)
*/
/* ARGSUSED */
static int
-MemoryCmd (clientData, interp, argc, argv)
- ClientData clientData;
+MemoryCmd(clientData, interp, argc, argv)
+ ClientData clientData;
Tcl_Interp *interp;
- int argc;
- CONST char **argv;
+ int argc;
+ CONST char **argv;
{
CONST char *fileName;
Tcl_DString buffer;
@@ -966,7 +983,7 @@ Tcl_InitMemory(interp)
Tcl_Interp *interp; /* Interpreter in which commands should be added */
{
TclInitDbCkalloc();
- Tcl_CreateCommand (interp, "memory", MemoryCmd, (ClientData) NULL,
+ Tcl_CreateCommand(interp, "memory", MemoryCmd, (ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
Tcl_CreateCommand(interp, "checkmem", CheckmemCmd, (ClientData) 0,
(Tcl_CmdDeleteProc *) NULL);
@@ -993,7 +1010,7 @@ Tcl_InitMemory(interp)
*/
char *
-Tcl_Alloc (size)
+Tcl_Alloc(size)
unsigned int size;
{
char *result;
@@ -1017,8 +1034,8 @@ Tcl_Alloc (size)
char *
Tcl_DbCkalloc(size, file, line)
unsigned int size;
- CONST char *file;
- int line;
+ CONST char *file;
+ int line;
{
char *result;
@@ -1042,7 +1059,7 @@ Tcl_DbCkalloc(size, file, line)
*/
char *
-Tcl_AttemptAlloc (size)
+Tcl_AttemptAlloc(size)
unsigned int size;
{
char *result;
@@ -1054,8 +1071,8 @@ Tcl_AttemptAlloc (size)
char *
Tcl_AttemptDbCkalloc(size, file, line)
unsigned int size;
- CONST char *file;
- int line;
+ CONST char *file;
+ int line;
{
char *result;
@@ -1091,10 +1108,10 @@ Tcl_Realloc(ptr, size)
char *
Tcl_DbCkrealloc(ptr, size, file, line)
- char *ptr;
+ char *ptr;
unsigned int size;
- CONST char *file;
- int line;
+ CONST char *file;
+ int line;
{
char *result;
@@ -1130,10 +1147,10 @@ Tcl_AttemptRealloc(ptr, size)
char *
Tcl_AttemptDbCkrealloc(ptr, size, file, line)
- char *ptr;
+ char *ptr;
unsigned int size;
- CONST char *file;
- int line;
+ CONST char *file;
+ int line;
{
char *result;
@@ -1153,7 +1170,7 @@ Tcl_AttemptDbCkrealloc(ptr, size, file, line)
*/
void
-Tcl_Free (ptr)
+Tcl_Free(ptr)
char *ptr;
{
TclpFree(ptr);
@@ -1161,9 +1178,9 @@ Tcl_Free (ptr)
int
Tcl_DbCkfree(ptr, file, line)
- char *ptr;
+ char *ptr;
CONST char *file;
- int line;
+ int line;
{
TclpFree(ptr);
return 0;
@@ -1195,7 +1212,7 @@ Tcl_DumpActiveMemory(fileName)
void
Tcl_ValidateAllMemory(file, line)
CONST char *file;
- int line;
+ int line;
{
}