From d764cc552251fc69207c1bb4b34d3a6a5b7020c6 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 18 Feb 2014 10:39:37 -0300 Subject: new list 'twups' to allow traversal of upvalues from dead threads (+ fixed some problems with cycles involving those upvalues) --- lfunc.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'lfunc.c') diff --git a/lfunc.c b/lfunc.c index 685d7bdd..9d0703e1 100644 --- a/lfunc.c +++ b/lfunc.c @@ -1,5 +1,5 @@ /* -** $Id: lfunc.c,v 2.39 2014/02/13 12:11:34 roberto Exp roberto $ +** $Id: lfunc.c,v 2.40 2014/02/15 13:12:01 roberto Exp roberto $ ** Auxiliary functions to manipulate prototypes and closures ** See Copyright Notice in lua.h */ @@ -35,7 +35,9 @@ Closure *luaF_newLclosure (lua_State *L, int n) { return c; } - +/* +** fill a closure with new closed upvalues +*/ void luaF_initupvals (lua_State *L, LClosure *cl) { int i; for (i = 0; i < cl->nupvalues; i++) { @@ -52,18 +54,24 @@ UpVal *luaF_findupval (lua_State *L, StkId level) { UpVal **pp = &L->openupval; UpVal *p; UpVal *uv; + lua_assert(isintwups(L) || L->openupval == NULL); while (*pp != NULL && (p = *pp)->v >= level) { lua_assert(upisopen(p)); if (p->v == level) /* found a corresponding upvalue? */ return p; /* return it */ pp = &p->u.open.next; } - /* not found: create a new one */ + /* not found: create a new upvalue */ uv = luaM_new(L, UpVal); uv->refcount = 0; - uv->u.open.next = *pp; + uv->u.open.next = *pp; /* link it to list of open upvalues */ + uv->u.open.touched = 1; *pp = uv; uv->v = level; /* current value lives in the stack */ + if (!isintwups(L)) { /* thread not in list of threads with upvalues? */ + L->twups = G(L)->twups; /* link it to the list */ + G(L)->twups = L; + } return uv; } -- cgit v1.2.1