diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2006-07-11 12:53:29 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2006-07-11 12:53:29 -0300 |
| commit | 3ca9af51a4f060cf2178901a67a21f8269af3224 (patch) | |
| tree | 4f1bb541280aa8b4960b16d0925eca60adb2b1a8 /ltests.c | |
| parent | c7b89dd28097296bbc14d9b47b4cea72514b2b76 (diff) | |
| download | lua-3ca9af51a4f060cf2178901a67a21f8269af3224.tar.gz lua-3ca9af51a4f060cf2178901a67a21f8269af3224.tar.bz2 lua-3ca9af51a4f060cf2178901a67a21f8269af3224.zip | |
emergency garbage collector (core forces a GC when allocation fails)
Diffstat (limited to 'ltests.c')
| -rw-r--r-- | ltests.c | 19 |
1 files changed, 13 insertions, 6 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 2.36 2006/01/10 13:13:06 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.37 2006/06/05 19:35:57 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 | */ |
| @@ -55,6 +55,12 @@ static void setnameval (lua_State *L, const char *name, int val) { | |||
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | 57 | ||
| 58 | static void pushobject (lua_State *L, const TValue *o) { | ||
| 59 | setobj2s(L, L->top, o); | ||
| 60 | api_incr_top(L); | ||
| 61 | } | ||
| 62 | |||
| 63 | |||
| 58 | /* | 64 | /* |
| 59 | ** {====================================================================== | 65 | ** {====================================================================== |
| 60 | ** Controlled version for realloc. | 66 | ** Controlled version for realloc. |
| @@ -108,7 +114,8 @@ static void freeblock (Memcontrol *mc, void *block, size_t size) { | |||
| 108 | 114 | ||
| 109 | void *debug_realloc (void *ud, void *block, size_t oldsize, size_t size) { | 115 | void *debug_realloc (void *ud, void *block, size_t oldsize, size_t size) { |
| 110 | Memcontrol *mc = cast(Memcontrol *, ud); | 116 | Memcontrol *mc = cast(Memcontrol *, ud); |
| 111 | lua_assert(oldsize == 0 || checkblocksize(block, oldsize)); | 117 | lua_assert((oldsize == 0) ? block == NULL : |
| 118 | block && checkblocksize(block, oldsize)); | ||
| 112 | if (mc->memlimit == 0) { /* first time? */ | 119 | if (mc->memlimit == 0) { /* first time? */ |
| 113 | char *limit = getenv("MEMLIMIT"); /* initialize memory limit */ | 120 | char *limit = getenv("MEMLIMIT"); /* initialize memory limit */ |
| 114 | mc->memlimit = limit ? strtoul(limit, NULL, 10) : ULONG_MAX; | 121 | mc->memlimit = limit ? strtoul(limit, NULL, 10) : ULONG_MAX; |
| @@ -447,7 +454,7 @@ static int listk (lua_State *L) { | |||
| 447 | p = clvalue(obj_at(L, 1))->l.p; | 454 | p = clvalue(obj_at(L, 1))->l.p; |
| 448 | lua_createtable(L, p->sizek, 0); | 455 | lua_createtable(L, p->sizek, 0); |
| 449 | for (i=0; i<p->sizek; i++) { | 456 | for (i=0; i<p->sizek; i++) { |
| 450 | luaA_pushobject(L, p->k+i); | 457 | pushobject(L, p->k+i); |
| 451 | lua_rawseti(L, -2, i+1); | 458 | lua_rawseti(L, -2, i+1); |
| 452 | } | 459 | } |
| 453 | return 1; | 460 | return 1; |
| @@ -573,18 +580,18 @@ static int table_query (lua_State *L) { | |||
| 573 | } | 580 | } |
| 574 | else if (i < t->sizearray) { | 581 | else if (i < t->sizearray) { |
| 575 | lua_pushinteger(L, i); | 582 | lua_pushinteger(L, i); |
| 576 | luaA_pushobject(L, &t->array[i]); | 583 | pushobject(L, &t->array[i]); |
| 577 | lua_pushnil(L); | 584 | lua_pushnil(L); |
| 578 | } | 585 | } |
| 579 | else if ((i -= t->sizearray) < sizenode(t)) { | 586 | else if ((i -= t->sizearray) < sizenode(t)) { |
| 580 | if (!ttisnil(gval(gnode(t, i))) || | 587 | if (!ttisnil(gval(gnode(t, i))) || |
| 581 | ttisnil(gkey(gnode(t, i))) || | 588 | ttisnil(gkey(gnode(t, i))) || |
| 582 | ttisnumber(gkey(gnode(t, i)))) { | 589 | ttisnumber(gkey(gnode(t, i)))) { |
| 583 | luaA_pushobject(L, key2tval(gnode(t, i))); | 590 | pushobject(L, key2tval(gnode(t, i))); |
| 584 | } | 591 | } |
| 585 | else | 592 | else |
| 586 | lua_pushliteral(L, "<undef>"); | 593 | lua_pushliteral(L, "<undef>"); |
| 587 | luaA_pushobject(L, gval(gnode(t, i))); | 594 | pushobject(L, gval(gnode(t, i))); |
| 588 | if (gnext(&t->node[i])) | 595 | if (gnext(&t->node[i])) |
| 589 | lua_pushinteger(L, gnext(&t->node[i]) - t->node); | 596 | lua_pushinteger(L, gnext(&t->node[i]) - t->node); |
| 590 | else | 597 | else |
