diff --git a/lfunc.c b/lfunc.c index daa430c6..4ed1fcb9 100644 --- a/lfunc.c +++ b/lfunc.c @@ -1,5 +1,5 @@ /* -** $Id: lfunc.c,v 2.20 2010/03/12 19:14:06 roberto Exp roberto $ +** $Id: lfunc.c,v 2.21 2010/03/26 20:58:11 roberto Exp roberto $ ** Auxiliary functions to manipulate prototypes and closures ** See Copyright Notice in lua.h */ @@ -96,10 +96,16 @@ void luaF_close (lua_State *L, StkId level) { if (isdead(g, o)) luaF_freeupval(L, uv); /* free upvalue */ else { - unlinkupval(uv); - setobj(L, &uv->u.value, uv->v); + unlinkupval(uv); /* remove upvalue from 'uvhead' list */ + setobj(L, &uv->u.value, uv->v); /* move value to upvalue slot */ uv->v = &uv->u.value; /* now current value lives here */ - luaC_linkupval(L, uv); /* link upvalue into `gcroot' list */ + gch(o)->next = g->allgc; /* link upvalue into 'allgc' list */ + g->allgc = o; + lua_assert(!isblack(o)); /* open upvalues are never black */ + if (isgray(o)) { /* is it marked? */ + gray2black(o); /* could not be black; now it can */ + luaC_barrier(L, uv, uv->v); + } } } }