diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-06-11 13:26:12 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-06-11 13:26:12 -0300 |
commit | 6b8cdc9cdd545508af85d1de2013ea0fc64792b0 (patch) | |
tree | 11a82496526f13e7937230fcc86775ed7eac56a0 | |
parent | 000d081fd0966ba8f39178186d30319df37d631f (diff) | |
download | lua-6b8cdc9cdd545508af85d1de2013ea0fc64792b0.tar.gz lua-6b8cdc9cdd545508af85d1de2013ea0fc64792b0.tar.bz2 lua-6b8cdc9cdd545508af85d1de2013ea0fc64792b0.zip |
Lua now uses only `realloc' for all its memory management
-rw-r--r-- | lmem.c | 15 | ||||
-rw-r--r-- | ltests.c | 7 | ||||
-rw-r--r-- | ltests.h | 4 |
3 files changed, 17 insertions, 9 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"); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 1.122 2002/05/16 14:59:49 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.123 2002/06/03 20:11:41 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -96,7 +96,10 @@ static void freeblock (void *block) { | |||
96 | 96 | ||
97 | 97 | ||
98 | void *debug_realloc (void *block, size_t oldsize, size_t size) { | 98 | void *debug_realloc (void *block, size_t oldsize, size_t size) { |
99 | lua_assert((oldsize == 0) ? block == NULL : oldsize == *blocksize(block)); | 99 | lua_assert((oldsize == 0) == (block == NULL)); |
100 | lua_assert(oldsize == 0 || oldsize == *blocksize(block)); | ||
101 | /* ISO does not specify what realloc(NULL, 0) does */ | ||
102 | lua_assert(block != NULL || size > 0); | ||
100 | if (size == 0) { | 103 | if (size == 0) { |
101 | freeblock(block); | 104 | freeblock(block); |
102 | return NULL; | 105 | return NULL; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.h,v 1.11 2002/01/11 20:23:57 roberto Exp roberto $ | 2 | ** $Id: ltests.h,v 1.12 2002/03/08 19:17:59 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 | */ |
@@ -32,9 +32,7 @@ extern unsigned long memdebug_maxmem; | |||
32 | extern unsigned long memdebug_memlimit; | 32 | extern unsigned long memdebug_memlimit; |
33 | 33 | ||
34 | 34 | ||
35 | #define l_malloc(s) debug_realloc(NULL, 0, s) | ||
36 | #define l_realloc(b, os, s) debug_realloc(b, os, s) | 35 | #define l_realloc(b, os, s) debug_realloc(b, os, s) |
37 | #define l_free(b, s) debug_realloc(b, s, 0) | ||
38 | 36 | ||
39 | void *debug_realloc (void *block, size_t oldsize, size_t size); | 37 | void *debug_realloc (void *block, size_t oldsize, size_t size); |
40 | 38 | ||