static int traverseproto (global_State *g, Proto *f) { int i; if (f->cache && iswhite(obj2gco(f->cache))) f->cache = NULL; /* allow cache to be collected */ stringmark(f->source); for (i = 0; i < f->sizek; i++) /* mark literals */ markvalue(g, &f->k[i]); for (i = 0; i < f->sizeupvalues; i++) /* mark upvalue names */ stringmark(f->upvalues[i].name); for (i = 0; i < f->sizep; i++) /* mark nested protos */ markobject(g, f->p[i]); for (i = 0; i < f->sizelocvars; i++) /* mark local-variable names */ stringmark(f->locvars[i].varname); return TRAVCOST + f->sizek + f->sizeupvalues + f->sizep + f->sizelocvars; }
static void traverseproto (GCState *st, Proto *f) { int i; stringmark(f->source); for (i=0; i<f->sizek; i++) { /* mark literal strings */ if (ttisstring(f->k+i) || ttiswstring(f->k+i)) stringmark(tsvalue(f->k+i)); } for (i=0; i<f->sizeupvalues; i++) /* mark upvalue names */ stringmark(f->upvalues[i]); for (i=0; i<f->sizep; i++) /* mark nested protos */ markvalue(st, f->p[i]); for (i=0; i<f->sizelocvars; i++) /* mark local-variable names */ stringmark(f->locvars[i].varname); lua_assert(luaG_checkcode(f)); }
/* ** tells whether a key or value can be cleared from a weak ** table. Non-collectable objects are never removed from weak ** tables. Strings behave as `values', so are never removed too. for ** other objects: if really collected, cannot keep them; for objects ** being finalized, keep them in keys, but not in values */ static int iscleared (const TValue *o) { if (!iscollectable(o)) return 0; else if (ttisstring(o)) { stringmark(rawtsvalue(o)); /* strings are `values', so are never weak */ return 0; } else return iswhite(gcvalue(o)); }
/* ** The next function tells whether a key or value can be cleared from ** a weak table. Non-collectable objects are never removed from weak ** tables. Strings behave as `values', so are never removed too. for ** other objects: if really collected, cannot keep them; for userdata ** being finalized, keep them in keys, but not in values */ static int iscleared (const TValue *o, int iskey) { if (!iscollectable(o)) return 0; if (ttisstring(o)) { stringmark(rawtsvalue(o)); /* strings are `values', so are never weak */ return 0; } return iswhite(gcvalue(o)) || (ttisuserdata(o) && (!iskey && isfinalized(uvalue(o)))); }
/* ** All marks are conditional because a GC may happen while the ** prototype is still being created */ static void traverseproto (global_State *g, Proto *f) { int i; if (f->source) stringmark(f->source); for (i=0; i<f->sizek; i++) /* mark literals */ markvalue(g, &f->k[i]); for (i=0; i<f->sizeupvalues; i++) { /* mark upvalue names */ if (f->upvalues[i]) stringmark(f->upvalues[i]); } for (i=0; i<f->sizep; i++) { /* mark nested protos */ if (f->p[i]) markobject(g, f->p[i]); } for (i=0; i<f->sizelocvars; i++) { /* mark local-variable names */ if (f->locvars[i].varname) stringmark(f->locvars[i].varname); } }
static int valismarked (const TObject *o) { if (ttisstring(o) || ttiswstring(o)) stringmark(tsvalue(o)); /* strings are `values', so are never weak */ return !iscollectable(o) || testbit(o->value.gc->gch.marked, 0); }