aboutsummaryrefslogtreecommitdiff
path: root/lmem.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-02-26 12:50:10 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-02-26 12:50:10 -0300
commit038848eccdf8c829664a3c0c3a158db10d78559d (patch)
tree650d8dbb624d4273e651957e3ddbb1d731ca31e1 /lmem.c
parentb678e465a1108ccb665744b9e637ccb218859fe6 (diff)
downloadlua-038848eccdf8c829664a3c0c3a158db10d78559d.tar.gz
lua-038848eccdf8c829664a3c0c3a158db10d78559d.tar.bz2
lua-038848eccdf8c829664a3c0c3a158db10d78559d.zip
better control of vector when DEBUGing
Diffstat (limited to 'lmem.c')
-rw-r--r--lmem.c26
1 files 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 @@
1/* 1/*
2** $Id: lmem.c,v 1.11 1999/02/25 15:16:26 roberto Exp roberto $ 2** $Id: lmem.c,v 1.12 1999/02/25 21:07:26 roberto Exp roberto $
3** Interface to Memory Manager 3** Interface to Memory Manager
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -13,9 +13,8 @@
13 13
14 14
15/* 15/*
16** real ANSI systems do not need some of these tests, 16** real ANSI systems do not need these tests;
17** since realloc(NULL, s)==malloc(s). 17** but some systems (Sun OS) are not that ANSI...
18** But some systems (Sun OS) are not that ANSI...
19*/ 18*/
20#ifdef OLD_ANSI 19#ifdef OLD_ANSI
21#define realloc(b,s) ((b) == NULL ? malloc(s) : (realloc)(b, s)) 20#define realloc(b,s) ((b) == NULL ? malloc(s) : (realloc)(b, s))
@@ -26,6 +25,10 @@
26#define MINSIZE 16 /* minimum size for "growing" vectors */ 25#define MINSIZE 16 /* minimum size for "growing" vectors */
27 26
28 27
28
29#ifndef DEBUG
30
31
29static unsigned long power2 (unsigned long n) { 32static unsigned long power2 (unsigned long n) {
30 unsigned long p = MINSIZE; 33 unsigned long p = MINSIZE;
31 while (p<=n) p<<=1; 34 while (p<=n) p<<=1;
@@ -44,15 +47,11 @@ void *luaM_growaux (void *block, unsigned long nelems, int inc, int size,
44 newn = limit; 47 newn = limit;
45 return luaM_realloc(block, newn*size); 48 return luaM_realloc(block, newn*size);
46 } 49 }
47 else { 50 else
48 LUA_ASSERT(power2(nelems) == power2(newn), "bad arithmetic");
49 return block; 51 return block;
50 }
51} 52}
52 53
53 54
54#ifndef DEBUG
55
56/* 55/*
57** generic allocation routine. 56** generic allocation routine.
58*/ 57*/
@@ -78,6 +77,15 @@ void *luaM_realloc (void *block, unsigned long size) {
78#include <string.h> 77#include <string.h>
79 78
80 79
80void *luaM_growaux (void *block, unsigned long nelems, int inc, int size,
81 char *errormsg, unsigned long limit) {
82 unsigned long newn = nelems+inc;
83 if (newn >= limit)
84 lua_error(errormsg);
85 return luaM_realloc(block, newn*size);
86}
87
88
81#define HEADER (sizeof(double)) 89#define HEADER (sizeof(double))
82 90
83#define MARK 55 91#define MARK 55