From abfc885079aef8cecf0235265ff173db22172ea5 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 24 May 1999 14:51:05 -0300 Subject: [PATCH] when debugging, move and erase old blocks to realloc. --- lmem.c | 80 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/lmem.c b/lmem.c index 556f3a8a..1c334b64 100644 --- a/lmem.c +++ b/lmem.c @@ -1,5 +1,5 @@ /* -** $Id: lmem.c,v 1.15 1999/05/11 14:18:40 roberto Exp roberto $ +** $Id: lmem.c,v 1.16 1999/05/20 20:43:06 roberto Exp roberto $ ** Interface to Memory Manager ** See Copyright Notice in lua.h */ @@ -26,8 +26,6 @@ -#ifndef DEBUG - static unsigned long power2 (unsigned long n) { unsigned long p = MINSIZE; @@ -48,6 +46,8 @@ void *luaM_growaux (void *block, unsigned long nelems, int inc, int size, } +#ifndef DEBUG + /* ** generic allocation routine. */ @@ -73,33 +73,38 @@ void *luaM_realloc (void *block, unsigned long size) { #include -void *luaM_growaux (void *block, unsigned long nelems, int inc, int size, - char *errormsg, unsigned long limit) { - unsigned long newn = nelems+inc; - if (newn >= limit) - lua_error(errormsg); - return luaM_realloc(block, newn*size); -} - - #define HEADER (sizeof(double)) -#define MARKSIZE 32 +#define MARKSIZE 16 #define MARK 55 + +#define blocksize(b) ((unsigned long *)((char *)(b) - HEADER)) + unsigned long numblocks = 0; unsigned long totalmem = 0; static void *checkblock (void *block) { - unsigned long *b = (unsigned long *)((char *)block - HEADER); - unsigned long size = *b; - int i; - for (i=0;i size) oldsize = size; + memcpy(newblock+HEADER, block, oldsize); + freeblock(block); /* erase (and check) old copy */ } - free(block); - return NULL; + if (newblock == NULL) + lua_error(memEM); + totalmem += size; + numblocks++; + *(unsigned long *)newblock = size; + for (i=0;i