diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-03-15 18:04:33 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-03-15 18:04:33 -0300 |
| commit | a4e1230f95223f2106cf0e118426ba91f1017d89 (patch) | |
| tree | bc6b67ae14a3381498a203e715d48e8d059b6fef /lfunc.c | |
| parent | 9804467eeb9836bc147adffee411b21e6257da6b (diff) | |
| download | lua-a4e1230f95223f2106cf0e118426ba91f1017d89.tar.gz lua-a4e1230f95223f2106cf0e118426ba91f1017d89.tar.bz2 lua-a4e1230f95223f2106cf0e118426ba91f1017d89.zip | |
better way to control open upvalues
Diffstat (limited to 'lfunc.c')
| -rw-r--r-- | lfunc.c | 22 |
1 files changed, 12 insertions, 10 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lfunc.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $ | 2 | ** $Id: lfunc.c,v 2.2 2004/02/16 19:09:52 roberto Exp roberto $ |
| 3 | ** Auxiliary functions to manipulate prototypes and closures | 3 | ** Auxiliary functions to manipulate prototypes and closures |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -34,6 +34,7 @@ Closure *luaF_newLclosure (lua_State *L, int nelems, TValue *e) { | |||
| 34 | c->l.isC = 0; | 34 | c->l.isC = 0; |
| 35 | c->l.g = *e; | 35 | c->l.g = *e; |
| 36 | c->l.nupvalues = cast(lu_byte, nelems); | 36 | c->l.nupvalues = cast(lu_byte, nelems); |
| 37 | while (nelems--) c->l.upvals[nelems] = NULL; | ||
| 37 | return c; | 38 | return c; |
| 38 | } | 39 | } |
| 39 | 40 | ||
| @@ -67,17 +68,18 @@ UpVal *luaF_findupval (lua_State *L, StkId level) { | |||
| 67 | 68 | ||
| 68 | void luaF_close (lua_State *L, StkId level) { | 69 | void luaF_close (lua_State *L, StkId level) { |
| 69 | UpVal *uv; | 70 | UpVal *uv; |
| 71 | global_State *g = G(L); | ||
| 70 | while ((uv = ngcotouv(L->openupval)) != NULL && uv->v >= level) { | 72 | while ((uv = ngcotouv(L->openupval)) != NULL && uv->v >= level) { |
| 71 | lu_byte mark = uv->marked; | 73 | GCObject *o = obj2gco(uv); |
| 72 | lua_assert(!isblack(obj2gco(uv))); | 74 | lua_assert(!isblack(o)); |
| 73 | setobj(L, &uv->value, uv->v); | ||
| 74 | luaC_barrier(L, uv, uv->v); | ||
| 75 | uv->v = &uv->value; /* now current value lives here */ | ||
| 76 | L->openupval = uv->next; /* remove from `open' list */ | 75 | L->openupval = uv->next; /* remove from `open' list */ |
| 77 | luaC_link(L, obj2gco(uv), LUA_TUPVAL); | 76 | if (isdead(g, o)) |
| 78 | if (G(L)->gcstate == GCSpropagate) | 77 | luaM_freelem(L, uv); /* free upvalue */ |
| 79 | uv->marked = mark; /* preserve previous mark */ | 78 | else { |
| 80 | lua_assert(!isdead(G(L), obj2gco(uv))); | 79 | setobj(L, &uv->value, uv->v); |
| 80 | uv->v = &uv->value; /* now current value lives here */ | ||
| 81 | luaC_linkupval(L, uv); /* link upvalue into `gcroot' list */ | ||
| 82 | } | ||
| 81 | } | 83 | } |
| 82 | } | 84 | } |
| 83 | 85 | ||
