diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-12-17 13:46:44 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-12-17 13:46:44 -0200 |
commit | 0bbdddc86b1353fec36ae886b4142986f3c4713f (patch) | |
tree | 9eb933c8123911f9477e8b8b55344035c8077c01 /lmem.c | |
parent | b3b8dfaaea2dba7e7b4b898a5f767a80f36319f1 (diff) | |
download | lua-github-0bbdddc86b1353fec36ae886b4142986f3c4713f.tar.gz |
allocator function receives the tag of object being allocated in 'osize'
when 'ptr' is NULL.
Diffstat (limited to 'lmem.c')
-rw-r--r-- | lmem.c | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -1,5 +1,5 @@ /* -** $Id: lmem.c,v 1.72 2006/09/14 12:59:06 roberto Exp roberto $ +** $Id: lmem.c,v 1.73 2006/09/14 18:42:28 roberto Exp roberto $ ** Interface to Memory Manager ** See Copyright Notice in lua.h */ @@ -26,12 +26,11 @@ ** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); ** (`osize' is the old size, `nsize' is the new size) ** -** Lua ensures that (ptr == NULL) iff (osize == 0). -** -** * frealloc(ud, NULL, 0, x) creates a new block of size `x' +** * frealloc(ud, NULL, x, s) creates a new block of size `s' (no +** matter 'x'). ** ** * frealloc(ud, p, x, 0) frees the block `p' -** (in this specific case, frealloc must return NULL). +** (in this specific case, frealloc must return NULL); ** particularly, frealloc(ud, NULL, 0, 0) does nothing ** (which is equivalent to free(NULL) in ANSI C) ** @@ -77,14 +76,15 @@ void *luaM_toobig (lua_State *L) { void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { void *newblock; global_State *g = G(L); - lua_assert((osize == 0) == (block == NULL)); + size_t realosize = (block) ? osize : 0; + lua_assert((realosize == 0) == (block == NULL)); #if defined(HARDMEMTESTS) - if (nsize > osize && g->GCthreshold != MAX_LUMEM) + if (nsize > realosize && g->GCthreshold != MAX_LUMEM) luaC_fullgc(L, 1); /* force a GC whenever possible */ #endif newblock = (*g->frealloc)(g->ud, block, osize, nsize); if (newblock == NULL && nsize > 0) { - lua_assert(nsize > osize); /* cannot fail when shrinking a block */ + lua_assert(nsize > realosize); /* cannot fail when shrinking a block */ if (g->GCthreshold != MAX_LUMEM) { luaC_fullgc(L, 1); /* try to free some memory... */ newblock = (*g->frealloc)(g->ud, block, osize, nsize); /* try again */ @@ -93,7 +93,7 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { luaD_throw(L, LUA_ERRMEM); } lua_assert((nsize == 0) == (newblock == NULL)); - g->totalbytes = (g->totalbytes - osize) + nsize; + g->totalbytes = (g->totalbytes - realosize) + nsize; return newblock; } |