From 3fc25ff15b5f7a28bfcc795d220c35ae7b25c6d7 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 17 Jun 2014 14:13:29 -0300 Subject: [PATCH] macro 'checkobjref' accepts NULL (as all its uses checked for NULL before) + user value from a userdata may not be a GC object --- ltests.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/ltests.c b/ltests.c index 1ff5c5f0..13415344 100644 --- a/ltests.c +++ b/ltests.c @@ -1,5 +1,5 @@ /* -** $Id: ltests.c,v 2.170 2014/05/13 19:40:28 roberto Exp roberto $ +** $Id: ltests.c,v 2.171 2014/06/10 17:41:38 roberto Exp roberto $ ** Internal Module for Debugging of the Lua Implementation ** See Copyright Notice in lua.h */ @@ -207,7 +207,8 @@ static int testobjref (global_State *g, GCObject *f, GCObject *t) { return r1; } -#define checkobjref(g,f,t) lua_assert(testobjref(g,f,obj2gco(t))) +#define checkobjref(g,f,t) \ + lua_assert((t) == NULL || testobjref(g,f,obj2gco(t))) static void checkvalref (global_State *g, GCObject *f, const TValue *t) { @@ -220,8 +221,7 @@ static void checktable (global_State *g, Table *h) { int i; Node *n, *limit = gnode(h, sizenode(h)); GCObject *hgc = obj2gco(h); - if (h->metatable) - checkobjref(g, hgc, h->metatable); + checkobjref(g, hgc, h->metatable); for (i = 0; i < h->sizearray; i++) checkvalref(g, hgc, &h->array[i]); for (n = gnode(h, 0); n < limit; n++) { @@ -241,24 +241,18 @@ static void checktable (global_State *g, Table *h) { static void checkproto (global_State *g, Proto *f) { int i; GCObject *fgc = obj2gco(f); - if (f->cache) checkobjref(g, fgc, f->cache); - if (f->source) checkobjref(g, fgc, f->source); + checkobjref(g, fgc, f->cache); + checkobjref(g, fgc, f->source); for (i=0; isizek; i++) { if (ttisstring(f->k+i)) checkobjref(g, fgc, rawtsvalue(f->k+i)); } - for (i=0; isizeupvalues; i++) { - if (f->upvalues[i].name) - checkobjref(g, fgc, f->upvalues[i].name); - } - for (i=0; isizep; i++) { - if (f->p[i]) - checkobjref(g, fgc, f->p[i]); - } - for (i=0; isizelocvars; i++) { - if (f->locvars[i].varname) - checkobjref(g, fgc, f->locvars[i].varname); - } + for (i=0; isizeupvalues; i++) + checkobjref(g, fgc, f->upvalues[i].name); + for (i=0; isizep; i++) + checkobjref(g, fgc, f->p[i]); + for (i=0; isizelocvars; i++) + checkobjref(g, fgc, f->locvars[i].varname); } @@ -274,7 +268,7 @@ static void checkCclosure (global_State *g, CClosure *cl) { static void checkLclosure (global_State *g, LClosure *cl) { GCObject *clgc = obj2gco(cl); int i; - if (cl->p) checkobjref(g, clgc, cl->p); + checkobjref(g, clgc, cl->p); for (i=0; inupvalues; i++) { UpVal *uv = cl->upvals[i]; if (uv) { @@ -324,9 +318,9 @@ static void checkobject (global_State *g, GCObject *o, int maybedead) { case LUA_TUSERDATA: { TValue uservalue; Table *mt = gco2u(o)->metatable; - if (mt) checkobjref(g, o, mt); + checkobjref(g, o, mt); getuservalue(g->mainthread, rawgco2u(o), &uservalue); - checkobjref(g, o, &uservalue); + checkvalref(g, o, &uservalue); break; } case LUA_TTABLE: {