[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Possible closure bug in 4.1 snapshot
- From: Edgar Toernig <froese@...>
- Date: Wed, 28 Nov 2001 14:33:41 +0100
Roberto Ierusalimschy wrote:
>
> Any sugestions how to correct that?
First idea: create struct UpVal during OP_CLOSURE, these are linked
into lua_State, struct UpVal performs an additional indirection.
struct lua_State {
...
struct UpVal *openupval; // instead opencl
...
};
struct LClosure {
...
struct UpVal *upvals[1];
};
struct UpVal {
TObject *valp; // points to stack or to UpVal.u.value
union {
TOBject value; // when closed: the value
struct UpVal *next; // when open: link for L.openuval
} u;
int refcnt; // or mark und next
};
OP_CLOSURE copies upvals from outer closure as it does now. For new
upvals it looks in L->openupval if an upval is already created and
use that; if not it creates a new one with valp pointing to stack
location.
luaF_close becomes pretty simple: remove from openupval list, copy
the value from stack to UpVal.u.value and correct the valp.
The openupval list should naturally be sorted with upper stack _frames_
at the top so earling abort should be possible (luaF_close may need
the base ptr for that).
An optimization: the lookup during OP_CLOSURE (to see whether an UpVal
is already present) may be avoided by having a some kind of display
(i.e. an addition stack slot for each exported variable that holds
the UpVal location for that var if it was created). But I'm not sure
if that's worth the trouble.
Ciao, ET.