diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-10-08 15:45:07 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-10-08 15:45:07 -0300 |
| commit | 02afc892d5ce5d85e88faac443d7294589ee697a (patch) | |
| tree | 2875c957c65249f85ed8ec3b3408219e2ca91650 | |
| parent | fa2f1ec7bae81d43e6edd1b29ecd610e24ebb301 (diff) | |
| download | lua-02afc892d5ce5d85e88faac443d7294589ee697a.tar.gz lua-02afc892d5ce5d85e88faac443d7294589ee697a.tar.bz2 lua-02afc892d5ce5d85e88faac443d7294589ee697a.zip | |
new ANSI C does not assure that realloc(p,0) == free(p)
| -rw-r--r-- | lmem.c | 19 | ||||
| -rw-r--r-- | ltests.h | 3 |
2 files changed, 15 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmem.c,v 1.56 2002/06/11 16:23:47 roberto Exp roberto $ | 2 | ** $Id: lmem.c,v 1.57 2002/06/18 15:19:27 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 | */ |
| @@ -18,15 +18,22 @@ | |||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | /* | 20 | /* |
| 21 | ** definition for realloc function. It must assure that | 21 | ** definition for realloc function. It must assure that l_realloc(NULL, |
| 22 | ** l_realloc(block, x, 0) frees the block, and l_realloc(NULL, 0, x) | 22 | ** 0, x) allocates a new block (ANSI C assures that). (`os' is the old |
| 23 | ** allocates a new block (ANSI C assures that). | 23 | ** block size; some allocators may use that.) |
| 24 | ** (`os' is the old block size; some allocators may use that.) | ||
| 25 | */ | 24 | */ |
| 26 | #ifndef l_realloc | 25 | #ifndef l_realloc |
| 27 | #define l_realloc(b,os,s) realloc(b,s) | 26 | #define l_realloc(b,os,s) realloc(b,s) |
| 28 | #endif | 27 | #endif |
| 29 | 28 | ||
| 29 | /* | ||
| 30 | ** definition for free function. (`os' is the old block size; some | ||
| 31 | ** allocators may use that.) | ||
| 32 | */ | ||
| 33 | #ifndef l_free | ||
| 34 | #define l_free(b,os) free(b) | ||
| 35 | #endif | ||
| 36 | |||
| 30 | 37 | ||
| 31 | #define MINSIZEARRAY 4 | 38 | #define MINSIZEARRAY 4 |
| 32 | 39 | ||
| @@ -56,7 +63,7 @@ void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems, | |||
| 56 | void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) { | 63 | void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) { |
| 57 | if (size == 0) { | 64 | if (size == 0) { |
| 58 | if (block != NULL) { | 65 | if (block != NULL) { |
| 59 | l_realloc(block, oldsize, size); | 66 | l_free(block, oldsize); |
| 60 | block = NULL; | 67 | block = NULL; |
| 61 | } | 68 | } |
| 62 | } | 69 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.h,v 1.14 2002/06/13 13:45:31 roberto Exp roberto $ | 2 | ** $Id: ltests.h,v 1.15 2002/07/17 16:25:13 roberto Exp roberto $ |
| 3 | ** Internal Header for Debugging of the Lua Implementation | 3 | ** Internal Header for Debugging of the Lua Implementation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -34,6 +34,7 @@ extern unsigned long memdebug_memlimit; | |||
| 34 | 34 | ||
| 35 | 35 | ||
| 36 | #define l_realloc(b, os, s) debug_realloc(b, os, s) | 36 | #define l_realloc(b, os, s) debug_realloc(b, os, s) |
| 37 | #define l_free(b, os) debug_realloc(b, os, 0) | ||
| 37 | 38 | ||
| 38 | void *debug_realloc (void *block, size_t oldsize, size_t size); | 39 | void *debug_realloc (void *block, size_t oldsize, size_t size); |
| 39 | 40 | ||
