diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-09-03 12:37:10 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-09-03 12:37:10 -0300 |
commit | aeff4f79fa10caef29617652aa49b77055f4045e (patch) | |
tree | 8f411b76c7c0b496c01224a36852ed38527dba3d /ltests.c | |
parent | 1bf4faec64aca03e1036235e72675f0617124140 (diff) | |
download | lua-aeff4f79fa10caef29617652aa49b77055f4045e.tar.gz lua-aeff4f79fa10caef29617652aa49b77055f4045e.tar.bz2 lua-aeff4f79fa10caef29617652aa49b77055f4045e.zip |
local collection now calls finalizers
Diffstat (limited to 'ltests.c')
-rw-r--r-- | ltests.c | 63 |
1 files changed, 30 insertions, 33 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.151 2013/08/27 20:04:00 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.152 2013/08/30 19:14:26 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 | */ |
@@ -202,17 +202,8 @@ static int testobjref2 (GCObject *f, GCObject *t) { | |||
202 | 202 | ||
203 | 203 | ||
204 | static void printobj (global_State *g, GCObject *o) { | 204 | static void printobj (global_State *g, GCObject *o) { |
205 | int i = 1; | 205 | printf("||%s(%p)-%s-%c(%02X)||", |
206 | GCObject *p; | 206 | ttypename(novariant(gch(o)->tt)), (void *)o, |
207 | for (p = g->allgc; p != o && p != NULL; p = gch(p)->next) i++; | ||
208 | if (p == NULL) { | ||
209 | i = 1; | ||
210 | for (p = g->finobj; p != o && p != NULL; p = gch(p)->next) i++; | ||
211 | if (p == NULL) i = 0; /* zero means 'not found' */ | ||
212 | else i = -i; /* negative means 'found in findobj list */ | ||
213 | } | ||
214 | printf("||%d:%s(%p)-%s-%c(%02X)||", | ||
215 | i, ttypename(novariant(gch(o)->tt)), (void *)o, | ||
216 | islocal(o)?"L":"NL", | 207 | islocal(o)?"L":"NL", |
217 | isdead(g,o)?'d':isblack(o)?'b':iswhite(o)?'w':'g', gch(o)->marked); | 208 | isdead(g,o)?'d':isblack(o)?'b':iswhite(o)?'w':'g', gch(o)->marked); |
218 | } | 209 | } |
@@ -344,9 +335,10 @@ static void checkstack (global_State *g, lua_State *L1) { | |||
344 | 335 | ||
345 | static void checkobject (global_State *g, GCObject *o, int maybedead) { | 336 | static void checkobject (global_State *g, GCObject *o, int maybedead) { |
346 | if (isdead(g, o)) | 337 | if (isdead(g, o)) |
347 | lua_assert(maybedead); | 338 | lua_assert(maybedead && issweepphase(g)); |
348 | else { | 339 | else { |
349 | lua_assert(g->gcstate != GCSpause || iswhite(o)); | 340 | lua_assert(g->gcstate != GCSpause || iswhite(o)); |
341 | lua_assert(!islocal(o) || !testbit(gch(o)->marked, LOCALMARK)); | ||
350 | switch (gch(o)->tt) { | 342 | switch (gch(o)->tt) { |
351 | case LUA_TUSERDATA: { | 343 | case LUA_TUSERDATA: { |
352 | Table *mt = gco2u(o)->metatable; | 344 | Table *mt = gco2u(o)->metatable; |
@@ -384,18 +376,18 @@ static void checkobject (global_State *g, GCObject *o, int maybedead) { | |||
384 | 376 | ||
385 | #define TESTGRAYBIT 7 | 377 | #define TESTGRAYBIT 7 |
386 | 378 | ||
387 | static void checkgraylist (global_State *g, GCObject *l) { | 379 | static void checkgraylist (global_State *g, GCObject *o) { |
388 | UNUSED(g); /* better to keep it available if we need to print an object */ | 380 | ((void)g); /* better to keep it available if we need to print an object */ |
389 | while (l) { | 381 | while (o) { |
390 | lua_assert(isgray(l)); | 382 | lua_assert(isgray(o)); |
391 | lua_assert(!testbit(l->gch.marked, TESTGRAYBIT)); | 383 | lua_assert(!testbit(o->gch.marked, TESTGRAYBIT)); |
392 | l_setbit(l->gch.marked, TESTGRAYBIT); | 384 | l_setbit(o->gch.marked, TESTGRAYBIT); |
393 | switch (gch(l)->tt) { | 385 | switch (gch(o)->tt) { |
394 | case LUA_TTABLE: l = gco2t(l)->gclist; break; | 386 | case LUA_TTABLE: o = gco2t(o)->gclist; break; |
395 | case LUA_TLCL: l = gco2lcl(l)->gclist; break; | 387 | case LUA_TLCL: o = gco2lcl(o)->gclist; break; |
396 | case LUA_TCCL: l = gco2ccl(l)->gclist; break; | 388 | case LUA_TCCL: o = gco2ccl(o)->gclist; break; |
397 | case LUA_TTHREAD: l = gco2th(l)->gclist; break; | 389 | case LUA_TTHREAD: o = gco2th(o)->gclist; break; |
398 | case LUA_TPROTO: l = gco2p(l)->gclist; break; | 390 | case LUA_TPROTO: o = gco2p(o)->gclist; break; |
399 | default: lua_assert(0); /* other objects cannot be gray */ | 391 | default: lua_assert(0); /* other objects cannot be gray */ |
400 | } | 392 | } |
401 | } | 393 | } |
@@ -451,30 +443,35 @@ int lua_checkmemory (lua_State *L) { | |||
451 | if (gch(o)->tt == LUA_TTHREAD) isthread = 1; /* now travesing threads... */ | 443 | if (gch(o)->tt == LUA_TTHREAD) isthread = 1; /* now travesing threads... */ |
452 | else lua_assert(!isthread); /* ... and only threads */ | 444 | else lua_assert(!isthread); /* ... and only threads */ |
453 | checkobject(g, o, maybedead); | 445 | checkobject(g, o, maybedead); |
454 | lua_assert(!tofinalize(o)); | 446 | lua_assert(!tofinalize(o) && testbit(o->gch.marked, LOCALMARK)); |
455 | lua_assert(testbit(o->gch.marked, LOCALMARK)); | ||
456 | } | 447 | } |
457 | /* check 'finobj' list */ | 448 | /* check 'finobj' list */ |
458 | checkgray(g, g->finobj); | 449 | checkgray(g, g->finobj); |
459 | for (o = g->finobj; o != NULL; o = gch(o)->next) { | 450 | for (o = g->finobj; o != NULL; o = gch(o)->next) { |
460 | lua_assert(tofinalize(o)); | 451 | checkobject(g, o, 0); |
452 | lua_assert(tofinalize(o) && testbit(o->gch.marked, LOCALMARK)); | ||
461 | lua_assert(gch(o)->tt == LUA_TUSERDATA || | 453 | lua_assert(gch(o)->tt == LUA_TUSERDATA || |
462 | gch(o)->tt == LUA_TTABLE); | 454 | gch(o)->tt == LUA_TTABLE); |
463 | checkobject(g, o, 0); | ||
464 | } | 455 | } |
465 | /* check 'tobefnz' list */ | 456 | /* check 'tobefnz' list */ |
466 | checkgray(g, g->tobefnz); | 457 | checkgray(g, g->tobefnz); |
467 | for (o = g->tobefnz; o != NULL; o = gch(o)->next) { | 458 | for (o = g->tobefnz; o != NULL; o = gch(o)->next) { |
468 | lua_assert(!iswhite(o) || g->gcstate == GCSpause); | 459 | lua_assert(!iswhite(o) || g->gcstate == GCSpause); |
469 | lua_assert(!isdead(g, o) && tofinalize(o)); | 460 | lua_assert(!isdead(g, o) && tofinalize(o)); |
470 | lua_assert(gch(o)->tt == LUA_TUSERDATA || | 461 | lua_assert(gch(o)->tt == LUA_TUSERDATA || gch(o)->tt == LUA_TTABLE); |
471 | gch(o)->tt == LUA_TTABLE); | ||
472 | } | 462 | } |
473 | /* check 'localgc' list */ | 463 | /* check 'localgc' list */ |
474 | checkgray(g, g->localgc); | 464 | checkgray(g, g->localgc); |
475 | for (o = g->localgc; o != NULL; o = gch(o)->next) { | 465 | for (o = g->localgc; o != NULL; o = gch(o)->next) { |
476 | checkobject(g, o, 1); | 466 | checkobject(g, o, 1); |
477 | lua_assert(!testbit(o->gch.marked, LOCALMARK)); | 467 | lua_assert(!tofinalize(o) && !testbit(o->gch.marked, LOCALMARK)); |
468 | } | ||
469 | /* check 'localfin' list */ | ||
470 | checkgray(g, g->localfin); | ||
471 | for (o = g->localfin; o != NULL; o = gch(o)->next) { | ||
472 | checkobject(g, o, 0); | ||
473 | lua_assert(tofinalize(o) && !testbit(o->gch.marked, LOCALMARK)); | ||
474 | lua_assert(gch(o)->tt == LUA_TUSERDATA || gch(o)->tt == LUA_TTABLE); | ||
478 | } | 475 | } |
479 | return 0; | 476 | return 0; |
480 | } | 477 | } |
@@ -653,7 +650,7 @@ static int gc_local (lua_State *L) { | |||
653 | 650 | ||
654 | static int gc_state (lua_State *L) { | 651 | static int gc_state (lua_State *L) { |
655 | static const char *statenames[] = {"propagate", "atomic", | 652 | static const char *statenames[] = {"propagate", "atomic", |
656 | "sweeplocal", "sweepfin", "sweepall", "sweepmainth", | 653 | "sweeplocal", "sweeplocfin", "sweepfin", "sweepall", "sweepmainth", |
657 | "pause", ""}; | 654 | "pause", ""}; |
658 | int option = luaL_checkoption(L, 1, "", statenames); | 655 | int option = luaL_checkoption(L, 1, "", statenames); |
659 | if (option == GCSpause + 1) { | 656 | if (option == GCSpause + 1) { |