commit 038848eccdf8c829664a3c0c3a158db10d78559d
parent b678e465a1108ccb665744b9e637ccb218859fe6
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Fri, 26 Feb 1999 12:49:48 -0300
better control of vector when DEBUGing
Diffstat:
M | lmem.c | | | 26 | +++++++++++++++++--------- |
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git 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 <string.h>
+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