lua

A copy of the Lua development repository
Log | Files | Refs | README

commit 138d00176ca3330b0ad18eb4006605746b68df94
parent 8edbf57fb8e3c20aac9560b7e4cce7583d14ebf6
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Wed, 19 Oct 2016 10:31:16 -0200

new flag in 'CallInfo.callstatus' to tell whether function is running
as a finalizer

Diffstat:
Mlgc.c | 4+++-
Mlstate.h | 3++-
2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/lgc.c b/lgc.c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.211 2015/12/10 18:12:30 roberto Exp roberto $ +** $Id: lgc.c,v 2.212 2016/03/31 19:02:03 roberto Exp roberto $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -818,7 +818,9 @@ static void GCTM (lua_State *L, int propagateerrors) { setobj2s(L, L->top, tm); /* push finalizer... */ setobj2s(L, L->top + 1, &v); /* ... and its argument */ L->top += 2; /* and (next line) call the finalizer */ + L->ci->callstatus |= CIST_FIN; /* will run a finalizer */ status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0); + L->ci->callstatus &= ~CIST_FIN; /* not running a finalizer anymore */ L->allowhook = oldah; /* restore hooks */ g->gcrunning = running; /* restore state */ if (status != LUA_OK && propagateerrors) { /* error while running __gc? */ diff --git a/lstate.h b/lstate.h @@ -1,5 +1,5 @@ /* -** $Id: lstate.h,v 2.130 2015/12/16 16:39:38 roberto Exp roberto $ +** $Id: lstate.h,v 2.131 2016/06/16 13:36:09 roberto Exp roberto $ ** Global State ** See Copyright Notice in lua.h */ @@ -104,6 +104,7 @@ typedef struct CallInfo { #define CIST_TAIL (1<<5) /* call was tail called */ #define CIST_HOOKYIELD (1<<6) /* last hook called yielded */ #define CIST_LEQ (1<<7) /* using __lt for __le */ +#define CIST_FIN (1<<8) /* call is running a finalizer */ #define isLua(ci) ((ci)->callstatus & CIST_LUA)