summaryrefslogtreecommitdiff
path: root/lmem.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-10-08 15:45:07 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-10-08 15:45:07 -0300
commit02afc892d5ce5d85e88faac443d7294589ee697a (patch)
tree2875c957c65249f85ed8ec3b3408219e2ca91650 /lmem.c
parentfa2f1ec7bae81d43e6edd1b29ecd610e24ebb301 (diff)
downloadlua-02afc892d5ce5d85e88faac443d7294589ee697a.tar.gz
lua-02afc892d5ce5d85e88faac443d7294589ee697a.tar.bz2
lua-02afc892d5ce5d85e88faac443d7294589ee697a.zip
new ANSI C does not assure that realloc(p,0) == free(p)
Diffstat (limited to 'lmem.c')
-rw-r--r--lmem.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/lmem.c b/lmem.c
index 369b1812..158a4023 100644
--- a/lmem.c
+++ b/lmem.c
@@ -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,
56void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) { 63void *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 }