diff options
| -rw-r--r-- | lmem.c | 26 |
1 files changed, 17 insertions, 9 deletions
| @@ -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 | |||
| 29 | static unsigned long power2 (unsigned long n) { | 32 | static 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 | ||
| 80 | void *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 |
