Lua now uses only `realloc' for all its memory management
This commit is contained in:
15
lmem.c
15
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
|
** Interface to Memory Manager
|
||||||
** See Copyright Notice in lua.h
|
** 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
|
#ifndef l_realloc
|
||||||
#define l_realloc(b,os,s) realloc(b,s)
|
#define l_realloc(b,os,s) realloc(b,s)
|
||||||
#define l_free(b,s) free(b)
|
|
||||||
#endif
|
#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) {
|
void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) {
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
l_free(block, oldsize); /* block may be NULL; that is OK for free */
|
if (block != NULL) {
|
||||||
block = NULL;
|
l_realloc(block, oldsize, size);
|
||||||
|
block = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (size >= MAX_SIZET)
|
else if (size >= MAX_SIZET)
|
||||||
luaG_runerror(L, "memory allocation error: block too big");
|
luaG_runerror(L, "memory allocation error: block too big");
|
||||||
|
|||||||
7
ltests.c
7
ltests.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: ltests.c,v 1.122 2002/05/16 14:59:49 roberto Exp roberto $
|
** $Id: ltests.c,v 1.123 2002/06/03 20:11:41 roberto Exp roberto $
|
||||||
** Internal Module for Debugging of the Lua Implementation
|
** Internal Module for Debugging of the Lua Implementation
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -96,7 +96,10 @@ static void freeblock (void *block) {
|
|||||||
|
|
||||||
|
|
||||||
void *debug_realloc (void *block, size_t oldsize, size_t size) {
|
void *debug_realloc (void *block, size_t oldsize, size_t size) {
|
||||||
lua_assert((oldsize == 0) ? block == NULL : oldsize == *blocksize(block));
|
lua_assert((oldsize == 0) == (block == NULL));
|
||||||
|
lua_assert(oldsize == 0 || oldsize == *blocksize(block));
|
||||||
|
/* ISO does not specify what realloc(NULL, 0) does */
|
||||||
|
lua_assert(block != NULL || size > 0);
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
freeblock(block);
|
freeblock(block);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
4
ltests.h
4
ltests.h
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: ltests.h,v 1.11 2002/01/11 20:23:57 roberto Exp roberto $
|
** $Id: ltests.h,v 1.12 2002/03/08 19:17:59 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
|
||||||
*/
|
*/
|
||||||
@@ -32,9 +32,7 @@ extern unsigned long memdebug_maxmem;
|
|||||||
extern unsigned long memdebug_memlimit;
|
extern unsigned long memdebug_memlimit;
|
||||||
|
|
||||||
|
|
||||||
#define l_malloc(s) debug_realloc(NULL, 0, s)
|
|
||||||
#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, s) debug_realloc(b, s, 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