From 0bbdddc86b1353fec36ae886b4142986f3c4713f Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 17 Dec 2009 13:46:44 -0200 Subject: allocator function receives the tag of object being allocated in 'osize' when 'ptr' is NULL. --- ltests.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'ltests.c') diff --git a/ltests.c b/ltests.c index 0e1c9226..7114a175 100644 --- a/ltests.c +++ b/ltests.c @@ -1,5 +1,5 @@ /* -** $Id: ltests.c,v 2.82 2009/12/10 18:21:28 roberto Exp roberto $ +** $Id: ltests.c,v 2.83 2009/12/11 19:14:59 roberto Exp roberto $ ** Internal Module for Debugging of the Lua Implementation ** See Copyright Notice in lua.h */ @@ -92,8 +92,7 @@ static int tpanic (lua_State *L) { #define fillmem(mem,size) /* empty */ #endif - -Memcontrol l_memcontrol = {0L, 0L, 0L, 0L}; +Memcontrol l_memcontrol = {0L, 0L, 0L, 0L, {0L, 0L, 0L, 0L, 0L}}; static void *checkblock (void *block, size_t size) { @@ -119,6 +118,11 @@ static void freeblock (Memcontrol *mc, void *block, size_t size) { void *debug_realloc (void *ud, void *block, size_t oldsize, size_t size) { Memcontrol *mc = cast(Memcontrol *, ud); + if (block == NULL) { + if (LUA_TSTRING <= oldsize && oldsize <= LUA_TTHREAD) + mc->objcount[oldsize - LUA_TSTRING]++; + oldsize = 0; + } lua_assert((oldsize == 0) ? block == NULL : block && checkblocksize(block, oldsize)); if (mc->memlimit == 0) { /* first time? */ @@ -506,10 +510,12 @@ static int get_limits (lua_State *L) { static int mem_query (lua_State *L) { if (lua_isnone(L, 1)) { + int i; lua_pushinteger(L, l_memcontrol.total); lua_pushinteger(L, l_memcontrol.numblocks); lua_pushinteger(L, l_memcontrol.maxmem); - return 3; + for (i = 0; i < 5; i++) lua_pushinteger(L, l_memcontrol.objcount[i]); + return 3 + 5; } else { l_memcontrol.memlimit = luaL_checkint(L, 1); -- cgit v1.2.3-55-g6feb