diff options
Diffstat (limited to '')
| -rw-r--r-- | lmem.c | 15 |
1 files changed, 11 insertions, 4 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmem.c,v 1.54 2002/05/01 20:40:42 roberto Exp roberto $ | 2 | ** $Id: lmem.c,v 1.55 2002/05/15 18:57:44 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 | */ |
| @@ -17,9 +17,14 @@ | |||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | /* | ||
| 21 | ** definition for realloc function. It must assure that | ||
| 22 | ** l_realloc(block, x, 0) frees the block, and l_realloc(NULL, 0, x) | ||
| 23 | ** allocates a new block (ANSI C assures that). | ||
| 24 | ** (`os' is the old block size; some allocators may use that.) | ||
| 25 | */ | ||
| 20 | #ifndef l_realloc | 26 | #ifndef l_realloc |
| 21 | #define l_realloc(b,os,s) realloc(b,s) | 27 | #define l_realloc(b,os,s) realloc(b,s) |
| 22 | #define l_free(b,s) free(b) | ||
| 23 | #endif | 28 | #endif |
| 24 | 29 | ||
| 25 | 30 | ||
| @@ -50,8 +55,10 @@ void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems, | |||
| 50 | */ | 55 | */ |
| 51 | void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) { | 56 | void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) { |
| 52 | if (size == 0) { | 57 | if (size == 0) { |
| 53 | l_free(block, oldsize); /* block may be NULL; that is OK for free */ | 58 | if (block != NULL) { |
| 54 | block = NULL; | 59 | l_realloc(block, oldsize, size); |
| 60 | block = NULL; | ||
| 61 | } | ||
| 55 | } | 62 | } |
| 56 | else if (size >= MAX_SIZET) | 63 | else if (size >= MAX_SIZET) |
| 57 | luaG_runerror(L, "memory allocation error: block too big"); | 64 | luaG_runerror(L, "memory allocation error: block too big"); |
