diff options
Diffstat (limited to 'ltests.c')
-rw-r--r-- | ltests.c | 26 |
1 files changed, 18 insertions, 8 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.91 2010/03/29 17:43:14 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.92 2010/04/12 12:42:07 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -92,7 +92,8 @@ static int tpanic (lua_State *L) { | |||
92 | #define fillmem(mem,size) /* empty */ | 92 | #define fillmem(mem,size) /* empty */ |
93 | #endif | 93 | #endif |
94 | 94 | ||
95 | Memcontrol l_memcontrol = {0L, 0L, 0L, 0L, {0L, 0L, 0L, 0L, 0L}}; | 95 | Memcontrol l_memcontrol = |
96 | {0L, 0L, 0L, 0L, {0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L}}; | ||
96 | 97 | ||
97 | 98 | ||
98 | static void *checkblock (void *block, size_t size) { | 99 | static void *checkblock (void *block, size_t size) { |
@@ -119,8 +120,8 @@ static void freeblock (Memcontrol *mc, void *block, size_t size) { | |||
119 | void *debug_realloc (void *ud, void *block, size_t oldsize, size_t size) { | 120 | void *debug_realloc (void *ud, void *block, size_t oldsize, size_t size) { |
120 | Memcontrol *mc = cast(Memcontrol *, ud); | 121 | Memcontrol *mc = cast(Memcontrol *, ud); |
121 | if (block == NULL) { | 122 | if (block == NULL) { |
122 | if (LUA_TSTRING <= oldsize && oldsize <= LUA_TTHREAD) | 123 | if (oldsize < LUA_NUMTAGS) |
123 | mc->objcount[oldsize - LUA_TSTRING]++; | 124 | mc->objcount[oldsize]++; |
124 | oldsize = 0; | 125 | oldsize = 0; |
125 | } | 126 | } |
126 | lua_assert((oldsize == 0) ? block == NULL : | 127 | lua_assert((oldsize == 0) ? block == NULL : |
@@ -505,17 +506,26 @@ static int get_limits (lua_State *L) { | |||
505 | 506 | ||
506 | static int mem_query (lua_State *L) { | 507 | static int mem_query (lua_State *L) { |
507 | if (lua_isnone(L, 1)) { | 508 | if (lua_isnone(L, 1)) { |
508 | int i; | ||
509 | lua_pushinteger(L, l_memcontrol.total); | 509 | lua_pushinteger(L, l_memcontrol.total); |
510 | lua_pushinteger(L, l_memcontrol.numblocks); | 510 | lua_pushinteger(L, l_memcontrol.numblocks); |
511 | lua_pushinteger(L, l_memcontrol.maxmem); | 511 | lua_pushinteger(L, l_memcontrol.maxmem); |
512 | for (i = 0; i < 5; i++) lua_pushinteger(L, l_memcontrol.objcount[i]); | 512 | return 3; |
513 | return 3 + 5; | ||
514 | } | 513 | } |
515 | else { | 514 | else if (lua_isnumber(L, 1)) { |
516 | l_memcontrol.memlimit = luaL_checkint(L, 1); | 515 | l_memcontrol.memlimit = luaL_checkint(L, 1); |
517 | return 0; | 516 | return 0; |
518 | } | 517 | } |
518 | else { | ||
519 | const char *t = luaL_checkstring(L, 1); | ||
520 | int i; | ||
521 | for (i = LUA_NUMTAGS - 1; i >= 0; i--) { | ||
522 | if (strcmp(t, typename(i)) == 0) { | ||
523 | lua_pushinteger(L, l_memcontrol.objcount[i]); | ||
524 | return 1; | ||
525 | } | ||
526 | } | ||
527 | return luaL_error(L, "unkown type '%s'", t); | ||
528 | } | ||
519 | } | 529 | } |
520 | 530 | ||
521 | 531 | ||