diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-08-27 15:53:35 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-08-27 15:53:35 -0300 |
| commit | af35c7f398e8149b5f2481b63b399674e4ecdf7e (patch) | |
| tree | 7d74f5c81bb0e2555cab4bce00a94a12a6d78604 /ltests.c | |
| parent | 742b7377d38e43224ee5dda4bb83a42763c20af8 (diff) | |
| download | lua-af35c7f398e8149b5f2481b63b399674e4ecdf7e.tar.gz lua-af35c7f398e8149b5f2481b63b399674e4ecdf7e.tar.bz2 lua-af35c7f398e8149b5f2481b63b399674e4ecdf7e.zip | |
upvalues collected by reference count
Diffstat (limited to 'ltests.c')
| -rw-r--r-- | ltests.c | 40 |
1 files changed, 9 insertions, 31 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 2.148 2013/08/22 15:21:48 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.149 2013/08/26 12:41:10 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 | */ |
| @@ -195,14 +195,6 @@ static int testobjref2 (GCObject *f, GCObject *t) { | |||
| 195 | /* not a local or pointed by a thread? */ | 195 | /* not a local or pointed by a thread? */ |
| 196 | if (!islocal(t) || gch(f)->tt == LUA_TTHREAD) | 196 | if (!islocal(t) || gch(f)->tt == LUA_TTHREAD) |
| 197 | return 1; /* ok */ | 197 | return 1; /* ok */ |
| 198 | if (gch(t)->tt == LUA_TUPVAL) { | ||
| 199 | lua_assert(gch(f)->tt == LUA_TLCL); | ||
| 200 | return 1; /* upvalue pointed by a closure */ | ||
| 201 | } | ||
| 202 | if (gch(f)->tt == LUA_TUPVAL) { | ||
| 203 | UpVal *uv = gco2uv(f); | ||
| 204 | return (uv->v != &uv->value); /* open upvalue can point to local stuff */ | ||
| 205 | } | ||
| 206 | if (gch(f)->tt == LUA_TPROTO && gch(t)->tt == LUA_TLCL) | 198 | if (gch(f)->tt == LUA_TPROTO && gch(t)->tt == LUA_TLCL) |
| 207 | return 1; /* cache from a prototype */ | 199 | return 1; /* cache from a prototype */ |
| 208 | return 0; | 200 | return 0; |
| @@ -311,9 +303,11 @@ static void checkLclosure (global_State *g, LClosure *cl) { | |||
| 311 | int i; | 303 | int i; |
| 312 | if (cl->p) checkobjref(g, clgc, cl->p); | 304 | if (cl->p) checkobjref(g, clgc, cl->p); |
| 313 | for (i=0; i<cl->nupvalues; i++) { | 305 | for (i=0; i<cl->nupvalues; i++) { |
| 314 | if (cl->upvals[i]) { | 306 | UpVal *uv = cl->upvals[i]; |
| 315 | lua_assert(cl->upvals[i]->tt == LUA_TUPVAL); | 307 | if (uv) { |
| 316 | checkobjref(g, clgc, cl->upvals[i]); | 308 | if (!upisopen(uv)) /* only closed upvalues matter to invariant */ |
| 309 | checkvalref(g, clgc, uv->v); | ||
| 310 | lua_assert(uv->refcount > 0); | ||
| 317 | } | 311 | } |
| 318 | } | 312 | } |
| 319 | } | 313 | } |
| @@ -332,13 +326,10 @@ static int lua_checkpc (pCallInfo ci) { | |||
| 332 | static void checkstack (global_State *g, lua_State *L1) { | 326 | static void checkstack (global_State *g, lua_State *L1) { |
| 333 | StkId o; | 327 | StkId o; |
| 334 | CallInfo *ci; | 328 | CallInfo *ci; |
| 335 | GCObject *uvo; | 329 | UpVal *uv; |
| 336 | lua_assert(!isdead(g, obj2gco(L1))); | 330 | lua_assert(!isdead(g, obj2gco(L1))); |
| 337 | for (uvo = L1->openupval; uvo != NULL; uvo = gch(uvo)->next) { | 331 | for (uv = L1->openupval; uv != NULL; uv = uv->u.op.next) |
| 338 | UpVal *uv = gco2uv(uvo); | 332 | lua_assert(upisopen(uv)); /* must be open */ |
| 339 | lua_assert(uv->v != &uv->value); /* must be open */ | ||
| 340 | lua_assert(!isblack(uvo)); /* open upvalues cannot be black */ | ||
| 341 | } | ||
| 342 | for (ci = L1->ci; ci != NULL; ci = ci->previous) { | 333 | for (ci = L1->ci; ci != NULL; ci = ci->previous) { |
| 343 | lua_assert(ci->top <= L1->stack_last); | 334 | lua_assert(ci->top <= L1->stack_last); |
| 344 | lua_assert(lua_checkpc(ci)); | 335 | lua_assert(lua_checkpc(ci)); |
| @@ -357,13 +348,6 @@ static void checkobject (global_State *g, GCObject *o, int maybedead) { | |||
| 357 | else { | 348 | else { |
| 358 | lua_assert(g->gcstate != GCSpause || iswhite(o)); | 349 | lua_assert(g->gcstate != GCSpause || iswhite(o)); |
| 359 | switch (gch(o)->tt) { | 350 | switch (gch(o)->tt) { |
| 360 | case LUA_TUPVAL: { | ||
| 361 | UpVal *uv = gco2uv(o); | ||
| 362 | lua_assert(uv->v == &uv->value); /* must be closed */ | ||
| 363 | lua_assert(!isgray(o)); /* closed upvalues are never gray */ | ||
| 364 | checkvalref(g, o, uv->v); | ||
| 365 | break; | ||
| 366 | } | ||
| 367 | case LUA_TUSERDATA: { | 351 | case LUA_TUSERDATA: { |
| 368 | Table *mt = gco2u(o)->metatable; | 352 | Table *mt = gco2u(o)->metatable; |
| 369 | if (mt) checkobjref(g, o, mt); | 353 | if (mt) checkobjref(g, o, mt); |
| @@ -490,12 +474,6 @@ int lua_checkmemory (lua_State *L) { | |||
| 490 | for (o = g->localgc; o != NULL; o = gch(o)->next) { | 474 | for (o = g->localgc; o != NULL; o = gch(o)->next) { |
| 491 | checkobject(g, o, 1); | 475 | checkobject(g, o, 1); |
| 492 | } | 476 | } |
| 493 | /* check 'localupv' list */ | ||
| 494 | checkgray(g, g->localupv); | ||
| 495 | for (o = g->localupv; o != NULL; o = gch(o)->next) { | ||
| 496 | lua_assert(gch(o)->tt == LUA_TUPVAL); | ||
| 497 | checkobject(g, o, 1); | ||
| 498 | } | ||
| 499 | return 0; | 477 | return 0; |
| 500 | } | 478 | } |
| 501 | 479 | ||
