new ANSI C does not assure that realloc(p,0) == free(p)
This commit is contained in:
19
lmem.c
19
lmem.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lmem.c,v 1.56 2002/06/11 16:23:47 roberto Exp roberto $
|
** $Id: lmem.c,v 1.57 2002/06/18 15:19:27 roberto Exp roberto $
|
||||||
** Interface to Memory Manager
|
** Interface to Memory Manager
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -18,15 +18,22 @@
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** definition for realloc function. It must assure that
|
** definition for realloc function. It must assure that l_realloc(NULL,
|
||||||
** l_realloc(block, x, 0) frees the block, and l_realloc(NULL, 0, x)
|
** 0, x) allocates a new block (ANSI C assures that). (`os' is the old
|
||||||
** allocates a new block (ANSI C assures that).
|
** block size; some allocators may use that.)
|
||||||
** (`os' is the old block size; some allocators may use that.)
|
|
||||||
*/
|
*/
|
||||||
#ifndef l_realloc
|
#ifndef l_realloc
|
||||||
#define l_realloc(b,os,s) realloc(b,s)
|
#define l_realloc(b,os,s) realloc(b,s)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
** definition for free function. (`os' is the old block size; some
|
||||||
|
** allocators may use that.)
|
||||||
|
*/
|
||||||
|
#ifndef l_free
|
||||||
|
#define l_free(b,os) free(b)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define MINSIZEARRAY 4
|
#define MINSIZEARRAY 4
|
||||||
|
|
||||||
@@ -56,7 +63,7 @@ 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) {
|
void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) {
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
if (block != NULL) {
|
if (block != NULL) {
|
||||||
l_realloc(block, oldsize, size);
|
l_free(block, oldsize);
|
||||||
block = NULL;
|
block = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
3
ltests.h
3
ltests.h
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: ltests.h,v 1.14 2002/06/13 13:45:31 roberto Exp roberto $
|
** $Id: ltests.h,v 1.15 2002/07/17 16:25:13 roberto Exp roberto $
|
||||||
** Internal Header for Debugging of the Lua Implementation
|
** Internal Header for Debugging of the Lua Implementation
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -34,6 +34,7 @@ extern unsigned long memdebug_memlimit;
|
|||||||
|
|
||||||
|
|
||||||
#define l_realloc(b, os, s) debug_realloc(b, os, s)
|
#define l_realloc(b, os, s) debug_realloc(b, os, s)
|
||||||
|
#define l_free(b, os) debug_realloc(b, os, 0)
|
||||||
|
|
||||||
void *debug_realloc (void *block, size_t oldsize, size_t size);
|
void *debug_realloc (void *block, size_t oldsize, size_t size);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user