aboutsummaryrefslogtreecommitdiff
path: root/ltests.c
diff options
context:
space:
mode:
Diffstat (limited to 'ltests.c')
-rw-r--r--ltests.c57
1 files changed, 35 insertions, 22 deletions
diff --git a/ltests.c b/ltests.c
index e45a82cf..4e087435 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 2.140 2013/08/05 16:58:28 roberto Exp roberto $ 2** $Id: ltests.c,v 2.141 2013/08/07 12:18:11 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*/
@@ -188,6 +188,25 @@ static int testobjref1 (global_State *g, GCObject *f, GCObject *t) {
188} 188}
189 189
190 190
191/*
192** Check locality
193*/
194static int testobjref2 (GCObject *f, GCObject *t) {
195 /* not a local or pointed by a thread? */
196 if (!islocal(t) || gch(f)->tt == LUA_TTHREAD)
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 return 0;
207}
208
209
191static void printobj (global_State *g, GCObject *o) { 210static void printobj (global_State *g, GCObject *o) {
192 int i = 1; 211 int i = 1;
193 GCObject *p; 212 GCObject *p;
@@ -198,24 +217,30 @@ static void printobj (global_State *g, GCObject *o) {
198 if (p == NULL) i = 0; /* zero means 'not found' */ 217 if (p == NULL) i = 0; /* zero means 'not found' */
199 else i = -i; /* negative means 'found in findobj list */ 218 else i = -i; /* negative means 'found in findobj list */
200 } 219 }
201 printf("||%d:%s(%p)-%c(%02X)||", i, ttypename(gch(o)->tt), (void *)o, 220 printf("||%d:%s(%p)-%s-%c(%02X)||",
221 i, ttypename(novariant(gch(o)->tt)), (void *)o,
222 islocal(o)?"L":"NL",
202 isdead(g,o)?'d':isblack(o)?'b':iswhite(o)?'w':'g', gch(o)->marked); 223 isdead(g,o)?'d':isblack(o)?'b':iswhite(o)?'w':'g', gch(o)->marked);
203} 224}
204 225
205 226
206static int testobjref (global_State *g, GCObject *f, GCObject *t) { 227static int testobjref (global_State *g, GCObject *f, GCObject *t) {
207 int r = testobjref1(g,f,t); 228 int r1 = testobjref1(g,f,t);
208 if (!r) { 229 int r2 = testobjref2(f,t);
209 printf("%d(%02X) - ", g->gcstate, g->currentwhite); 230 if (!r1 || !r2) {
231 if (!r1)
232 printf("%d(%02X) - ", g->gcstate, g->currentwhite);
233 else
234 printf("local violation - ");
210 printobj(g, f); 235 printobj(g, f);
211 printf("\t-> "); 236 printf(" -> ");
212 printobj(g, t); 237 printobj(g, t);
213 printf("\n"); 238 printf("\n");
214 } 239 }
215 return r; 240 return r1 && r2;
216} 241}
217 242
218#define checkobjref(g,f,t) lua_assert(testobjref(g,f,obj2gco(t))) 243#define checkobjref(g,f,t) lua_assert(testobjref(g,f,obj2gco(t)))
219 244
220 245
221static void checkvalref (global_State *g, GCObject *f, const TValue *t) { 246static void checkvalref (global_State *g, GCObject *f, const TValue *t) {
@@ -349,6 +374,7 @@ static void checkobject (global_State *g, GCObject *o, int maybedead) {
349 break; 374 break;
350 } 375 }
351 case LUA_TTHREAD: { 376 case LUA_TTHREAD: {
377 lua_assert(!islocal(o));
352 checkstack(g, gco2th(o)); 378 checkstack(g, gco2th(o));
353 break; 379 break;
354 } 380 }
@@ -617,22 +643,9 @@ static int get_gccolor (lua_State *L) {
617 o = obj_at(L, 1); 643 o = obj_at(L, 1);
618 if (!iscollectable(o)) 644 if (!iscollectable(o))
619 lua_pushstring(L, "no collectable"); 645 lua_pushstring(L, "no collectable");
620 else { 646 else
621 int marked = gcvalue(o)->gch.marked;
622 int n = 1;
623 lua_pushstring(L, iswhite(gcvalue(o)) ? "white" : 647 lua_pushstring(L, iswhite(gcvalue(o)) ? "white" :
624 isblack(gcvalue(o)) ? "black" : "grey"); 648 isblack(gcvalue(o)) ? "black" : "grey");
625 if (testbit(marked, FINALIZEDBIT)) {
626 lua_pushliteral(L, "/finalized"); n++;
627 }
628 if (testbit(marked, SEPARATED)) {
629 lua_pushliteral(L, "/separated"); n++;
630 }
631 if (testbit(marked, FIXEDBIT)) {
632 lua_pushliteral(L, "/fixed"); n++;
633 }
634 lua_concat(L, n);
635 }
636 return 1; 649 return 1;
637} 650}
638 651