From 038848eccdf8c829664a3c0c3a158db10d78559d Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 26 Feb 1999 12:50:10 -0300 Subject: [PATCH] better control of vector when DEBUGing --- lmem.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/lmem.c b/lmem.c index 82159876..2f23bafc 100644 --- a/lmem.c +++ b/lmem.c @@ -1,5 +1,5 @@ /* -** $Id: lmem.c,v 1.11 1999/02/25 15:16:26 roberto Exp roberto $ +** $Id: lmem.c,v 1.12 1999/02/25 21:07:26 roberto Exp roberto $ ** Interface to Memory Manager ** See Copyright Notice in lua.h */ @@ -13,9 +13,8 @@ /* -** real ANSI systems do not need some of these tests, -** since realloc(NULL, s)==malloc(s). -** But some systems (Sun OS) are not that ANSI... +** real ANSI systems do not need these tests; +** but some systems (Sun OS) are not that ANSI... */ #ifdef OLD_ANSI #define realloc(b,s) ((b) == NULL ? malloc(s) : (realloc)(b, s)) @@ -26,6 +25,10 @@ #define MINSIZE 16 /* minimum size for "growing" vectors */ + +#ifndef DEBUG + + static unsigned long power2 (unsigned long n) { unsigned long p = MINSIZE; while (p<=n) p<<=1; @@ -44,15 +47,11 @@ void *luaM_growaux (void *block, unsigned long nelems, int inc, int size, newn = limit; return luaM_realloc(block, newn*size); } - else { - LUA_ASSERT(power2(nelems) == power2(newn), "bad arithmetic"); + else return block; - } } -#ifndef DEBUG - /* ** generic allocation routine. */ @@ -78,6 +77,15 @@ 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 MARK 55