aboutsummaryrefslogtreecommitdiff
path: root/lstate.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-01-18 11:40:45 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-01-18 11:40:45 -0300
commitd0f34d91373fa265d4445e456e4a10ce206c1559 (patch)
tree0389b97b7844634144158df06040ea89c63fda46 /lstate.h
parent825ac8eca8e384d6ad2538b5670088c31e08a9d7 (diff)
downloadlua-d0f34d91373fa265d4445e456e4a10ce206c1559.tar.gz
lua-d0f34d91373fa265d4445e456e4a10ce206c1559.tar.bz2
lua-d0f34d91373fa265d4445e456e4a10ce206c1559.zip
Allow yields in '__close' metamethods ater errors
Completes commit b07fc10e91a. '__close' metamethods can yield even when they are being called due to an error. '__close' metamethods from C functions are still not allowed to yield.
Diffstat (limited to 'lstate.h')
-rw-r--r--lstate.h22
1 files changed, 19 insertions, 3 deletions
diff --git a/lstate.h b/lstate.h
index 38a6c9b6..38248e57 100644
--- a/lstate.h
+++ b/lstate.h
@@ -191,17 +191,33 @@ typedef struct CallInfo {
191*/ 191*/
192#define CIST_OAH (1<<0) /* original value of 'allowhook' */ 192#define CIST_OAH (1<<0) /* original value of 'allowhook' */
193#define CIST_C (1<<1) /* call is running a C function */ 193#define CIST_C (1<<1) /* call is running a C function */
194#define CIST_FRESH (1<<2) /* call is on a fresh "luaV_execute" frame */ 194#define CIST_FRESH (1<<2) /* call is on a fresh "luaV_execute" frame */
195#define CIST_HOOKED (1<<3) /* call is running a debug hook */ 195#define CIST_HOOKED (1<<3) /* call is running a debug hook */
196#define CIST_YPCALL (1<<4) /* call is a yieldable protected call */ 196#define CIST_YPCALL (1<<4) /* call is a yieldable protected call */
197#define CIST_TAIL (1<<5) /* call was tail called */ 197#define CIST_TAIL (1<<5) /* call was tail called */
198#define CIST_HOOKYIELD (1<<6) /* last hook called yielded */ 198#define CIST_HOOKYIELD (1<<6) /* last hook called yielded */
199#define CIST_FIN (1<<7) /* call is running a finalizer */ 199#define CIST_FIN (1<<7) /* call is running a finalizer */
200#define CIST_TRAN (1<<8) /* 'ci' has transfer information */ 200#define CIST_TRAN (1<<8) /* 'ci' has transfer information */
201/* Bits 9-11 are used for CIST_RECST (see below) */
202#define CIST_RECST 9
201#if defined(LUA_COMPAT_LT_LE) 203#if defined(LUA_COMPAT_LT_LE)
202#define CIST_LEQ (1<<9) /* using __lt for __le */ 204#define CIST_LEQ (1<<12) /* using __lt for __le */
203#endif 205#endif
204 206
207
208/*
209** Field CIST_RECST stores the "recover status", used to keep the error
210** status while closing to-be-closed variables in coroutines, so that
211** Lua can correctly resume after an yield from a __close method called
212** because of an error. (Three bits are enough for error status.)
213*/
214#define getcistrecst(ci) (((ci)->callstatus >> CIST_RECST) & 7)
215#define setcistrecst(ci,st) \
216 check_exp(((st) & 7) == (st), /* status must fit in three bits */ \
217 ((ci)->callstatus = ((ci)->callstatus & ~(7 << CIST_RECST)) \
218 | ((st) << CIST_RECST)))
219
220
205/* active function is a Lua function */ 221/* active function is a Lua function */
206#define isLua(ci) (!((ci)->callstatus & CIST_C)) 222#define isLua(ci) (!((ci)->callstatus & CIST_C))
207 223