aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-06-17 14:13:29 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-06-17 14:13:29 -0300
commit3fc25ff15b5f7a28bfcc795d220c35ae7b25c6d7 (patch)
tree6e1a0cd0e6889756d104da7be9058746a854f231
parentfa3113ffbf4455871baf1d1d9d48679a17e6f3e5 (diff)
downloadlua-3fc25ff15b5f7a28bfcc795d220c35ae7b25c6d7.tar.gz
lua-3fc25ff15b5f7a28bfcc795d220c35ae7b25c6d7.tar.bz2
lua-3fc25ff15b5f7a28bfcc795d220c35ae7b25c6d7.zip
macro 'checkobjref' accepts NULL (as all its uses checked for NULL
before) + user value from a userdata may not be a GC object
-rw-r--r--ltests.c36
1 files 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 @@
1/* 1/*
2** $Id: ltests.c,v 2.170 2014/05/13 19:40:28 roberto Exp roberto $ 2** $Id: ltests.c,v 2.171 2014/06/10 17:41:38 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*/
@@ -207,7 +207,8 @@ static int testobjref (global_State *g, GCObject *f, GCObject *t) {
207 return r1; 207 return r1;
208} 208}
209 209
210#define checkobjref(g,f,t) lua_assert(testobjref(g,f,obj2gco(t))) 210#define checkobjref(g,f,t) \
211 lua_assert((t) == NULL || testobjref(g,f,obj2gco(t)))
211 212
212 213
213static void checkvalref (global_State *g, GCObject *f, const TValue *t) { 214static void checkvalref (global_State *g, GCObject *f, const TValue *t) {
@@ -220,8 +221,7 @@ static void checktable (global_State *g, Table *h) {
220 int i; 221 int i;
221 Node *n, *limit = gnode(h, sizenode(h)); 222 Node *n, *limit = gnode(h, sizenode(h));
222 GCObject *hgc = obj2gco(h); 223 GCObject *hgc = obj2gco(h);
223 if (h->metatable) 224 checkobjref(g, hgc, h->metatable);
224 checkobjref(g, hgc, h->metatable);
225 for (i = 0; i < h->sizearray; i++) 225 for (i = 0; i < h->sizearray; i++)
226 checkvalref(g, hgc, &h->array[i]); 226 checkvalref(g, hgc, &h->array[i]);
227 for (n = gnode(h, 0); n < limit; n++) { 227 for (n = gnode(h, 0); n < limit; n++) {
@@ -241,24 +241,18 @@ static void checktable (global_State *g, Table *h) {
241static void checkproto (global_State *g, Proto *f) { 241static void checkproto (global_State *g, Proto *f) {
242 int i; 242 int i;
243 GCObject *fgc = obj2gco(f); 243 GCObject *fgc = obj2gco(f);
244 if (f->cache) checkobjref(g, fgc, f->cache); 244 checkobjref(g, fgc, f->cache);
245 if (f->source) checkobjref(g, fgc, f->source); 245 checkobjref(g, fgc, f->source);
246 for (i=0; i<f->sizek; i++) { 246 for (i=0; i<f->sizek; i++) {
247 if (ttisstring(f->k+i)) 247 if (ttisstring(f->k+i))
248 checkobjref(g, fgc, rawtsvalue(f->k+i)); 248 checkobjref(g, fgc, rawtsvalue(f->k+i));
249 } 249 }
250 for (i=0; i<f->sizeupvalues; i++) { 250 for (i=0; i<f->sizeupvalues; i++)
251 if (f->upvalues[i].name) 251 checkobjref(g, fgc, f->upvalues[i].name);
252 checkobjref(g, fgc, f->upvalues[i].name); 252 for (i=0; i<f->sizep; i++)
253 } 253 checkobjref(g, fgc, f->p[i]);
254 for (i=0; i<f->sizep; i++) { 254 for (i=0; i<f->sizelocvars; i++)
255 if (f->p[i]) 255 checkobjref(g, fgc, f->locvars[i].varname);
256 checkobjref(g, fgc, f->p[i]);
257 }
258 for (i=0; i<f->sizelocvars; i++) {
259 if (f->locvars[i].varname)
260 checkobjref(g, fgc, f->locvars[i].varname);
261 }
262} 256}
263 257
264 258
@@ -274,7 +268,7 @@ static void checkCclosure (global_State *g, CClosure *cl) {
274static void checkLclosure (global_State *g, LClosure *cl) { 268static void checkLclosure (global_State *g, LClosure *cl) {
275 GCObject *clgc = obj2gco(cl); 269 GCObject *clgc = obj2gco(cl);
276 int i; 270 int i;
277 if (cl->p) checkobjref(g, clgc, cl->p); 271 checkobjref(g, clgc, cl->p);
278 for (i=0; i<cl->nupvalues; i++) { 272 for (i=0; i<cl->nupvalues; i++) {
279 UpVal *uv = cl->upvals[i]; 273 UpVal *uv = cl->upvals[i];
280 if (uv) { 274 if (uv) {
@@ -324,9 +318,9 @@ static void checkobject (global_State *g, GCObject *o, int maybedead) {
324 case LUA_TUSERDATA: { 318 case LUA_TUSERDATA: {
325 TValue uservalue; 319 TValue uservalue;
326 Table *mt = gco2u(o)->metatable; 320 Table *mt = gco2u(o)->metatable;
327 if (mt) checkobjref(g, o, mt); 321 checkobjref(g, o, mt);
328 getuservalue(g->mainthread, rawgco2u(o), &uservalue); 322 getuservalue(g->mainthread, rawgco2u(o), &uservalue);
329 checkobjref(g, o, &uservalue); 323 checkvalref(g, o, &uservalue);
330 break; 324 break;
331 } 325 }
332 case LUA_TTABLE: { 326 case LUA_TTABLE: {