Commit a79bdf2e authored by monty@narttu.mysql.fi's avatar monty@narttu.mysql.fi

Indentation

parent d640ff4a
/* Copyright (C) 2000 MySQL AB /* Copyright (C) 2000-2003 MySQL AB
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
#include "my_static.h" #include "my_static.h"
#include "mysys_err.h" #include "mysys_err.h"
ulonglong safemalloc_mem_limit = ~(ulonglong)0; ulonglong safemalloc_mem_limit= ~(ulonglong)0;
#define pNext tInt._pNext #define pNext tInt._pNext
#define pPrev tInt._pPrev #define pPrev tInt._pPrev
...@@ -84,7 +84,7 @@ ulonglong safemalloc_mem_limit = ~(ulonglong)0; ...@@ -84,7 +84,7 @@ ulonglong safemalloc_mem_limit = ~(ulonglong)0;
the linked list of blocks so that _sanity() will not fuss when it the linked list of blocks so that _sanity() will not fuss when it
is not supposed to is not supposed to
*/ */
static int sf_malloc_tampered = 0; static int sf_malloc_tampered= 0;
#endif #endif
...@@ -92,11 +92,11 @@ static int sf_malloc_tampered = 0; ...@@ -92,11 +92,11 @@ static int sf_malloc_tampered = 0;
static int check_ptr(const char *where, byte *ptr, const char *sFile, static int check_ptr(const char *where, byte *ptr, const char *sFile,
uint uLine); uint uLine);
static int _checkchunk(struct remember *pRec, const char *sFile, uint uLine); static int _checkchunk(struct irem *pRec, const char *sFile, uint uLine);
/* /*
Note: both these refer to the NEW'ed data only. They do not include Note: We only fill up the allocated block. This do not include
malloc() roundoff or the extra space required by the remember malloc() roundoff or the extra space required by the irem
structures. structures.
*/ */
...@@ -127,27 +127,25 @@ static int _checkchunk(struct remember *pRec, const char *sFile, uint uLine); ...@@ -127,27 +127,25 @@ static int _checkchunk(struct remember *pRec, const char *sFile, uint uLine);
/* Allocate some memory. */ /* Allocate some memory. */
gptr _mymalloc (uint uSize, const char *sFile, uint uLine, myf MyFlags) gptr _mymalloc(uint uSize, const char *sFile, uint uLine, myf MyFlags)
{ {
struct remember *pTmp; struct remember *pTmp;
DBUG_ENTER("_mymalloc"); DBUG_ENTER("_mymalloc");
DBUG_PRINT("enter",("Size: %u",uSize)); DBUG_PRINT("enter",("Size: %u",uSize));
if (!sf_malloc_quick) if (!sf_malloc_quick)
(void) _sanity (sFile, uLine); (void) _sanity (sFile, uLine);
if (uSize + lCurMemory > safemalloc_mem_limit) if (uSize + lCurMemory > safemalloc_mem_limit)
pTmp = 0; pTmp= 0;
else else
{ {
/* Allocate the physical memory */ /* Allocate the physical memory */
pTmp = (struct remember *) malloc ( pTmp= (struct remember *) malloc (ALIGN_SIZE(sizeof(struct irem)) +
ALIGN_SIZE(sizeof(struct irem)) /* remember data */ sf_malloc_prehunc +
+ sf_malloc_prehunc uSize + /* size requested */
+ uSize /* size requested */ 4 + /* overrun mark */
+ 4 /* overrun mark */ sf_malloc_endhunc
+ sf_malloc_endhunc
); );
} }
/* Check if there isn't anymore memory avaiable */ /* Check if there isn't anymore memory avaiable */
...@@ -174,43 +172,40 @@ gptr _mymalloc (uint uSize, const char *sFile, uint uLine, myf MyFlags) ...@@ -174,43 +172,40 @@ gptr _mymalloc (uint uSize, const char *sFile, uint uLine, myf MyFlags)
} }
/* Fill up the structure */ /* Fill up the structure */
*((long*) ((char*) &pTmp -> lSpecialValue+sf_malloc_prehunc)) = MAGICKEY; *((uint32*) ((char*) &pTmp->lSpecialValue+sf_malloc_prehunc))= MAGICKEY;
pTmp -> aData[uSize + sf_malloc_prehunc+0] = MAGICEND0; pTmp->aData[uSize + sf_malloc_prehunc+0]= MAGICEND0;
pTmp -> aData[uSize + sf_malloc_prehunc+1] = MAGICEND1; pTmp->aData[uSize + sf_malloc_prehunc+1]= MAGICEND1;
pTmp -> aData[uSize + sf_malloc_prehunc+2] = MAGICEND2; pTmp->aData[uSize + sf_malloc_prehunc+2]= MAGICEND2;
pTmp -> aData[uSize + sf_malloc_prehunc+3] = MAGICEND3; pTmp->aData[uSize + sf_malloc_prehunc+3]= MAGICEND3;
pTmp -> sFileName = (my_string) sFile; pTmp->sFileName= (my_string) sFile;
pTmp -> uLineNum = uLine; pTmp->uLineNum= uLine;
pTmp -> uDataSize = uSize; pTmp->uDataSize= uSize;
pTmp -> pPrev = NULL; pTmp->pPrev= NULL;
/* Add this remember structure to the linked list */ /* Add this remember structure to the linked list */
pthread_mutex_lock(&THR_LOCK_malloc); pthread_mutex_lock(&THR_LOCK_malloc);
if ((pTmp->pNext=pRememberRoot)) if ((pTmp->pNext= pRememberRoot))
{ pRememberRoot->pPrev= pTmp;
pRememberRoot -> pPrev = pTmp; pRememberRoot= pTmp;
}
pRememberRoot = pTmp;
/* Keep the statistics */ /* Keep the statistics */
lCurMemory += uSize; lCurMemory+= uSize;
if (lCurMemory > lMaxMemory) { if (lCurMemory > lMaxMemory)
lMaxMemory = lCurMemory; lMaxMemory= lCurMemory;
}
cNewCount++; cNewCount++;
pthread_mutex_unlock(&THR_LOCK_malloc); pthread_mutex_unlock(&THR_LOCK_malloc);
/* Set the memory to the aribtrary wierd value */ /* Set the memory to the aribtrary wierd value */
if ((MyFlags & MY_ZEROFILL) || !sf_malloc_quick) if ((MyFlags & MY_ZEROFILL) || !sf_malloc_quick)
bfill(&pTmp -> aData[sf_malloc_prehunc],uSize, bfill(&pTmp->aData[sf_malloc_prehunc],uSize,
(char) (MyFlags & MY_ZEROFILL ? 0 : ALLOC_VAL)); (char) (MyFlags & MY_ZEROFILL ? 0 : ALLOC_VAL));
/* Return a pointer to the real data */ /* Return a pointer to the real data */
DBUG_PRINT("exit",("ptr: %lx",&(pTmp -> aData[sf_malloc_prehunc]))); DBUG_PRINT("exit",("ptr: %lx",&(pTmp->aData[sf_malloc_prehunc])));
if (sf_min_adress > &(pTmp -> aData[sf_malloc_prehunc])) if (sf_min_adress > &(pTmp->aData[sf_malloc_prehunc]))
sf_min_adress = &(pTmp -> aData[sf_malloc_prehunc]); sf_min_adress= &(pTmp->aData[sf_malloc_prehunc]);
if (sf_max_adress < &(pTmp -> aData[sf_malloc_prehunc])) if (sf_max_adress < &(pTmp->aData[sf_malloc_prehunc]))
sf_max_adress = &(pTmp -> aData[sf_malloc_prehunc]); sf_max_adress= &(pTmp->aData[sf_malloc_prehunc]);
DBUG_RETURN ((gptr) &(pTmp -> aData[sf_malloc_prehunc])); DBUG_RETURN ((gptr) &(pTmp->aData[sf_malloc_prehunc]));
} }
/* /*
...@@ -218,7 +213,7 @@ gptr _mymalloc (uint uSize, const char *sFile, uint uLine, myf MyFlags) ...@@ -218,7 +213,7 @@ gptr _mymalloc (uint uSize, const char *sFile, uint uLine, myf MyFlags)
Free then old memoryblock Free then old memoryblock
*/ */
gptr _myrealloc (register gptr pPtr, register uint uSize, gptr _myrealloc(register gptr pPtr, register uint uSize,
const char *sFile, uint uLine, myf MyFlags) const char *sFile, uint uLine, myf MyFlags)
{ {
struct remember *pRec; struct remember *pRec;
...@@ -234,9 +229,9 @@ gptr _myrealloc (register gptr pPtr, register uint uSize, ...@@ -234,9 +229,9 @@ gptr _myrealloc (register gptr pPtr, register uint uSize,
if (check_ptr("Reallocating",(byte*) pPtr,sFile,uLine)) if (check_ptr("Reallocating",(byte*) pPtr,sFile,uLine))
DBUG_RETURN((gptr) NULL); DBUG_RETURN((gptr) NULL);
pRec = (struct remember *) ((char*) pPtr - ALIGN_SIZE(sizeof(struct irem))- pRec= (struct remember *) ((char*) pPtr - ALIGN_SIZE(sizeof(struct irem))-
sf_malloc_prehunc); sf_malloc_prehunc);
if (*((long*) ((char*) &pRec -> lSpecialValue+sf_malloc_prehunc)) if (*((uint32*) ((char*) &pRec->lSpecialValue+sf_malloc_prehunc))
!= MAGICKEY) != MAGICKEY)
{ {
fprintf(stderr, "Error: Reallocating unallocated data at line %d, '%s'\n", fprintf(stderr, "Error: Reallocating unallocated data at line %d, '%s'\n",
...@@ -266,7 +261,7 @@ gptr _myrealloc (register gptr pPtr, register uint uSize, ...@@ -266,7 +261,7 @@ gptr _myrealloc (register gptr pPtr, register uint uSize,
/* Deallocate some memory. */ /* Deallocate some memory. */
void _myfree (gptr pPtr, const char *sFile, uint uLine, myf myflags) void _myfree(gptr pPtr, const char *sFile, uint uLine, myf myflags)
{ {
struct remember *pRec; struct remember *pRec;
DBUG_ENTER("_myfree"); DBUG_ENTER("_myfree");
...@@ -280,7 +275,7 @@ void _myfree (gptr pPtr, const char *sFile, uint uLine, myf myflags) ...@@ -280,7 +275,7 @@ void _myfree (gptr pPtr, const char *sFile, uint uLine, myf myflags)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
/* Calculate the address of the remember structure */ /* Calculate the address of the remember structure */
pRec = (struct remember *) ((byte*) pPtr- ALIGN_SIZE(sizeof(struct irem))- pRec= (struct remember *) ((byte*) pPtr- ALIGN_SIZE(sizeof(struct irem))-
sf_malloc_prehunc); sf_malloc_prehunc);
/* /*
...@@ -292,7 +287,7 @@ void _myfree (gptr pPtr, const char *sFile, uint uLine, myf myflags) ...@@ -292,7 +287,7 @@ void _myfree (gptr pPtr, const char *sFile, uint uLine, myf myflags)
(4) A stray pointer hit this location (4) A stray pointer hit this location
*/ */
if (*((long*) ((char*) &pRec -> lSpecialValue+sf_malloc_prehunc)) if (*((uint32*) ((char*) &pRec->lSpecialValue+sf_malloc_prehunc))
!= MAGICKEY) != MAGICKEY)
{ {
fprintf(stderr, "Error: Freeing unallocated data at line %d, '%s'\n", fprintf(stderr, "Error: Freeing unallocated data at line %d, '%s'\n",
...@@ -304,16 +299,15 @@ void _myfree (gptr pPtr, const char *sFile, uint uLine, myf myflags) ...@@ -304,16 +299,15 @@ void _myfree (gptr pPtr, const char *sFile, uint uLine, myf myflags)
/* Remove this structure from the linked list */ /* Remove this structure from the linked list */
pthread_mutex_lock(&THR_LOCK_malloc); pthread_mutex_lock(&THR_LOCK_malloc);
if (pRec -> pPrev) { if (pRec->pPrev)
pRec -> pPrev -> pNext = pRec -> pNext; pRec->pPrev->pNext= pRec->pNext;
} else { else
pRememberRoot = pRec -> pNext; pRememberRoot= pRec->pNext;
}
if (pRec -> pNext) { if (pRec->pNext)
pRec -> pNext -> pPrev = pRec -> pPrev; pRec->pNext->pPrev= pRec->pPrev;
}
/* Handle the statistics */ /* Handle the statistics */
lCurMemory -= pRec -> uDataSize; lCurMemory -= pRec->uDataSize;
cNewCount--; cNewCount--;
pthread_mutex_unlock(&THR_LOCK_malloc); pthread_mutex_unlock(&THR_LOCK_malloc);
...@@ -322,7 +316,7 @@ void _myfree (gptr pPtr, const char *sFile, uint uLine, myf myflags) ...@@ -322,7 +316,7 @@ void _myfree (gptr pPtr, const char *sFile, uint uLine, myf myflags)
if (!sf_malloc_quick) if (!sf_malloc_quick)
bfill(&pRec->aData[sf_malloc_prehunc],pRec->uDataSize,(pchar) FREE_VAL); bfill(&pRec->aData[sf_malloc_prehunc],pRec->uDataSize,(pchar) FREE_VAL);
#endif #endif
*((long*) ((char*) &pRec -> lSpecialValue+sf_malloc_prehunc)) = ~MAGICKEY; *((uint32*) ((char*) &pRec->lSpecialValue+sf_malloc_prehunc))= ~MAGICKEY;
/* Actually free the memory */ /* Actually free the memory */
free ((my_string ) pRec); free ((my_string ) pRec);
...@@ -372,7 +366,7 @@ static int check_ptr(const char *where, byte *ptr, const char *sFile, ...@@ -372,7 +366,7 @@ static int check_ptr(const char *where, byte *ptr, const char *sFile,
free'ed as well as the statistics. free'ed as well as the statistics.
*/ */
void TERMINATE (FILE *file) void TERMINATE(FILE *file)
{ {
struct remember *pPtr; struct remember *pPtr;
DBUG_ENTER("TERMINATE"); DBUG_ENTER("TERMINATE");
...@@ -403,7 +397,8 @@ void TERMINATE (FILE *file) ...@@ -403,7 +397,8 @@ void TERMINATE (FILE *file)
{ {
if (file) if (file)
{ {
fprintf(file, "Warning: Memory that was not free'ed (%ld bytes):\n",lCurMemory); fprintf(file, "Warning: Memory that was not free'ed (%ld bytes):\n",
lCurMemory);
(void) fflush(file); (void) fflush(file);
} }
DBUG_PRINT("safe",("Memory that was not free'ed (%ld bytes):",lCurMemory)); DBUG_PRINT("safe",("Memory that was not free'ed (%ld bytes):",lCurMemory));
...@@ -413,17 +408,17 @@ void TERMINATE (FILE *file) ...@@ -413,17 +408,17 @@ void TERMINATE (FILE *file)
{ {
fprintf(file, fprintf(file,
"\t%6u bytes at 0x%09lx, allocated at line %4u in '%s'", "\t%6u bytes at 0x%09lx, allocated at line %4u in '%s'",
pPtr -> uDataSize, pPtr->uDataSize,
(ulong) &(pPtr -> aData[sf_malloc_prehunc]), (ulong) &(pPtr->aData[sf_malloc_prehunc]),
pPtr -> uLineNum, pPtr -> sFileName); pPtr->uLineNum, pPtr->sFileName);
fprintf(file, "\n"); fprintf(file, "\n");
(void) fflush(file); (void) fflush(file);
} }
DBUG_PRINT("safe", DBUG_PRINT("safe",
("%6u bytes at 0x%09lx, allocated at line %4d in '%s'", ("%6u bytes at 0x%09lx, allocated at line %4d in '%s'",
pPtr -> uDataSize, &(pPtr -> aData[sf_malloc_prehunc]), pPtr->uDataSize, &(pPtr->aData[sf_malloc_prehunc]),
pPtr -> uLineNum, pPtr -> sFileName)); pPtr->uLineNum, pPtr->sFileName));
pPtr = pPtr -> pNext; pPtr= pPtr->pNext;
} }
} }
/* Report the memory usage statistics */ /* Report the memory usage statistics */
...@@ -442,7 +437,7 @@ void TERMINATE (FILE *file) ...@@ -442,7 +437,7 @@ void TERMINATE (FILE *file)
/* Returns 0 if chunk is ok */ /* Returns 0 if chunk is ok */
static int _checkchunk (register struct remember *pRec, const char *sFile, static int _checkchunk(register struct remember *pRec, const char *sFile,
uint uLine) uint uLine)
{ {
reg1 uint uSize; reg1 uint uSize;
...@@ -450,36 +445,36 @@ static int _checkchunk (register struct remember *pRec, const char *sFile, ...@@ -450,36 +445,36 @@ static int _checkchunk (register struct remember *pRec, const char *sFile,
reg3 int flag=0; reg3 int flag=0;
/* Check for a possible underrun */ /* Check for a possible underrun */
if (*((long*) ((char*) &pRec -> lSpecialValue+sf_malloc_prehunc)) if (*((uint32*) ((char*) &pRec->lSpecialValue+sf_malloc_prehunc))
!= MAGICKEY) != MAGICKEY)
{ {
fprintf(stderr, "Error: Memory allocated at %s:%d was underrun,", fprintf(stderr, "Error: Memory allocated at %s:%d was underrun,",
pRec -> sFileName, pRec -> uLineNum); pRec->sFileName, pRec->uLineNum);
fprintf(stderr, " discovered at %s:%d\n", sFile, uLine); fprintf(stderr, " discovered at %s:%d\n", sFile, uLine);
(void) fflush(stderr); (void) fflush(stderr);
DBUG_PRINT("safe",("Underrun at %lx, allocated at %s:%d", DBUG_PRINT("safe",("Underrun at %lx, allocated at %s:%d",
&(pRec -> aData[sf_malloc_prehunc]), &(pRec->aData[sf_malloc_prehunc]),
pRec -> sFileName, pRec->sFileName,
pRec -> uLineNum)); pRec->uLineNum));
flag=1; flag=1;
} }
/* Check for a possible overrun */ /* Check for a possible overrun */
uSize = pRec -> uDataSize; uSize= pRec->uDataSize;
magicp = &(pRec -> aData[uSize+sf_malloc_prehunc]); magicp= &(pRec->aData[uSize+sf_malloc_prehunc]);
if (*magicp++ != MAGICEND0 || if (*magicp++ != MAGICEND0 ||
*magicp++ != MAGICEND1 || *magicp++ != MAGICEND1 ||
*magicp++ != MAGICEND2 || *magicp++ != MAGICEND2 ||
*magicp++ != MAGICEND3) *magicp++ != MAGICEND3)
{ {
fprintf(stderr, "Error: Memory allocated at %s:%d was overrun,", fprintf(stderr, "Error: Memory allocated at %s:%d was overrun,",
pRec -> sFileName, pRec -> uLineNum); pRec->sFileName, pRec->uLineNum);
fprintf(stderr, " discovered at '%s:%d'\n", sFile, uLine); fprintf(stderr, " discovered at '%s:%d'\n", sFile, uLine);
(void) fflush(stderr); (void) fflush(stderr);
DBUG_PRINT("safe",("Overrun at %lx, allocated at %s:%d", DBUG_PRINT("safe",("Overrun at %lx, allocated at %s:%d",
&(pRec -> aData[sf_malloc_prehunc]), &(pRec->aData[sf_malloc_prehunc]),
pRec -> sFileName, pRec->sFileName,
pRec -> uLineNum)); pRec->uLineNum));
flag=1; flag=1;
} }
return(flag); return(flag);
...@@ -488,7 +483,7 @@ static int _checkchunk (register struct remember *pRec, const char *sFile, ...@@ -488,7 +483,7 @@ static int _checkchunk (register struct remember *pRec, const char *sFile,
/* Returns how many wrong chunks */ /* Returns how many wrong chunks */
int _sanity (const char *sFile, uint uLine) int _sanity(const char *sFile, uint uLine)
{ {
reg1 struct remember *pTmp; reg1 struct remember *pTmp;
reg2 int flag=0; reg2 int flag=0;
...@@ -500,8 +495,8 @@ int _sanity (const char *sFile, uint uLine) ...@@ -500,8 +495,8 @@ int _sanity (const char *sFile, uint uLine)
cNewCount=0; cNewCount=0;
#endif #endif
count=cNewCount; count=cNewCount;
for (pTmp = pRememberRoot; pTmp != NULL && count-- ; pTmp = pTmp -> pNext) for (pTmp= pRememberRoot; pTmp != NULL && count-- ; pTmp= pTmp->pNext)
flag+=_checkchunk (pTmp, sFile, uLine); flag+= _checkchunk (pTmp, sFile, uLine);
pthread_mutex_unlock(&THR_LOCK_malloc); pthread_mutex_unlock(&THR_LOCK_malloc);
if (count || pTmp) if (count || pTmp)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment