summaryrefslogtreecommitdiff
path: root/lmem.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-06-11 13:26:12 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-06-11 13:26:12 -0300
commit6b8cdc9cdd545508af85d1de2013ea0fc64792b0 (patch)
tree11a82496526f13e7937230fcc86775ed7eac56a0 /lmem.c
parent000d081fd0966ba8f39178186d30319df37d631f (diff)
downloadlua-github-6b8cdc9cdd545508af85d1de2013ea0fc64792b0.tar.gz
Lua now uses only `realloc' for all its memory management
Diffstat (limited to 'lmem.c')
-rw-r--r--lmem.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/lmem.c b/lmem.c
index 99b0dafc..00c7253b 100644
--- a/lmem.c
+++ b/lmem.c
@@ -1,5 +1,5 @@
/*
-** $Id: lmem.c,v 1.54 2002/05/01 20:40:42 roberto Exp roberto $
+** $Id: lmem.c,v 1.55 2002/05/15 18:57:44 roberto Exp roberto $
** Interface to Memory Manager
** See Copyright Notice in lua.h
*/
@@ -17,9 +17,14 @@
+/*
+** definition for realloc function. It must assure that
+** l_realloc(block, x, 0) frees the block, and l_realloc(NULL, 0, x)
+** allocates a new block (ANSI C assures that).
+** (`os' is the old block size; some allocators may use that.)
+*/
#ifndef l_realloc
#define l_realloc(b,os,s) realloc(b,s)
-#define l_free(b,s) free(b)
#endif
@@ -50,8 +55,10 @@ void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems,
*/
void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) {
if (size == 0) {
- l_free(block, oldsize); /* block may be NULL; that is OK for free */
- block = NULL;
+ if (block != NULL) {
+ l_realloc(block, oldsize, size);
+ block = NULL;
+ }
}
else if (size >= MAX_SIZET)
luaG_runerror(L, "memory allocation error: block too big");