summaryrefslogtreecommitdiff
path: root/libs/liblua/src/lstate.h
diff options
context:
space:
mode:
Diffstat (limited to 'libs/liblua/src/lstate.h')
-rw-r--r--libs/liblua/src/lstate.h91
1 files changed, 28 insertions, 63 deletions
diff --git a/libs/liblua/src/lstate.h b/libs/liblua/src/lstate.h
index c1c38204a6..cbcf07e203 100644
--- a/libs/liblua/src/lstate.h
+++ b/libs/liblua/src/lstate.h
@@ -87,49 +87,13 @@
/*
-** About 'nCcalls': each thread in Lua (a lua_State) keeps a count of
-** how many "C calls" it still can do in the C stack, to avoid C-stack
-** overflow. This count is very rough approximation; it considers only
-** recursive functions inside the interpreter, as non-recursive calls
-** can be considered using a fixed (although unknown) amount of stack
-** space.
-**
-** The count has two parts: the lower part is the count itself; the
-** higher part counts the number of non-yieldable calls in the stack.
-** (They are together so that we can change both with one instruction.)
-**
-** Because calls to external C functions can use an unknown amount
-** of space (e.g., functions using an auxiliary buffer), calls
-** to these functions add more than one to the count (see CSTACKCF).
-**
-** The proper count excludes the number of CallInfo structures allocated
-** by Lua, as a kind of "potential" calls. So, when Lua calls a function
-** (and "consumes" one CallInfo), it needs neither to decrement nor to
-** check 'nCcalls', as its use of C stack is already accounted for.
+** About 'nCcalls': This count has two parts: the lower 16 bits counts
+** the number of recursive invocations in the C stack; the higher
+** 16 bits counts the number of non-yieldable calls in the stack.
+** (They are together so that we can change and save both with one
+** instruction.)
*/
-/* number of "C stack slots" used by an external C function */
-#define CSTACKCF 10
-
-
-/*
-** The C-stack size is sliced in the following zones:
-** - larger than CSTACKERR: normal stack;
-** - [CSTACKMARK, CSTACKERR]: buffer zone to signal a stack overflow;
-** - [CSTACKCF, CSTACKERRMARK]: error-handling zone;
-** - below CSTACKERRMARK: buffer zone to signal overflow during overflow;
-** (Because the counter can be decremented CSTACKCF at once, we need
-** the so called "buffer zones", with at least that size, to properly
-** detect a change from one zone to the next.)
-*/
-#define CSTACKERR (8 * CSTACKCF)
-#define CSTACKMARK (CSTACKERR - (CSTACKCF + 2))
-#define CSTACKERRMARK (CSTACKCF + 2)
-
-
-/* initial limit for the C-stack of threads */
-#define CSTACKTHREAD (2 * CSTACKERR)
-
/* true if this thread does not have non-yieldable calls in the stack */
#define yieldable(L) (((L)->nCcalls & 0xffff0000) == 0)
@@ -144,13 +108,8 @@
/* Decrement the number of non-yieldable calls */
#define decnny(L) ((L)->nCcalls -= 0x10000)
-/* Increment the number of non-yieldable calls and decrement nCcalls */
-#define incXCcalls(L) ((L)->nCcalls += 0x10000 - CSTACKCF)
-
-/* Decrement the number of non-yieldable calls and increment nCcalls */
-#define decXCcalls(L) ((L)->nCcalls -= 0x10000 - CSTACKCF)
-
-
+/* Non-yieldable call increment */
+#define nyci (0x10000 | 1)
@@ -168,12 +127,20 @@ struct lua_longjmp; /* defined in ldo.c */
#endif
-/* extra stack space to handle TM calls and some other extras */
+/*
+** Extra stack space to handle TM calls and some other extras. This
+** space is not included in 'stack_last'. It is used only to avoid stack
+** checks, either because the element will be promptly popped or because
+** there will be a stack check soon after the push. Function frames
+** never use this extra space, so it does not need to be kept clean.
+*/
#define EXTRA_STACK 5
#define BASIC_STACK_SIZE (2*LUA_MINSTACK)
+#define stacksize(th) cast_int((th)->stack_last - (th)->stack)
+
/* kinds of Garbage Collection */
#define KGC_INC 0 /* incremental gc */
@@ -224,14 +191,15 @@ typedef struct CallInfo {
*/
#define CIST_OAH (1<<0) /* original value of 'allowhook' */
#define CIST_C (1<<1) /* call is running a C function */
-#define CIST_HOOKED (1<<2) /* call is running a debug hook */
-#define CIST_YPCALL (1<<3) /* call is a yieldable protected call */
-#define CIST_TAIL (1<<4) /* call was tail called */
-#define CIST_HOOKYIELD (1<<5) /* last hook called yielded */
-#define CIST_FIN (1<<6) /* call is running a finalizer */
-#define CIST_TRAN (1<<7) /* 'ci' has transfer information */
+#define CIST_FRESH (1<<2) /* call is on a fresh "luaV_execute" frame */
+#define CIST_HOOKED (1<<3) /* call is running a debug hook */
+#define CIST_YPCALL (1<<4) /* call is a yieldable protected call */
+#define CIST_TAIL (1<<5) /* call was tail called */
+#define CIST_HOOKYIELD (1<<6) /* last hook called yielded */
+#define CIST_FIN (1<<7) /* call is running a finalizer */
+#define CIST_TRAN (1<<8) /* 'ci' has transfer information */
#if defined(LUA_COMPAT_LT_LE)
-#define CIST_LEQ (1<<8) /* using __lt for __le */
+#define CIST_LEQ (1<<9) /* using __lt for __le */
#endif
/* active function is a Lua function */
@@ -296,7 +264,6 @@ typedef struct global_State {
TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */
lua_WarnFunction warnf; /* warning function */
void *ud_warn; /* auxiliary data to 'warnf' */
- unsigned int Cstacklimit; /* current limit for the C stack */
} global_State;
@@ -311,7 +278,7 @@ struct lua_State {
StkId top; /* first free slot in the stack */
global_State *l_G;
CallInfo *ci; /* call info for current function */
- StkId stack_last; /* last free slot in the stack */
+ StkId stack_last; /* end of stack (last element + 1) */
StkId stack; /* stack base */
UpVal *openupval; /* list of open upvalues in this stack */
GCObject *gclist;
@@ -320,9 +287,8 @@ struct lua_State {
CallInfo base_ci; /* CallInfo for first level (C calling Lua) */
volatile lua_Hook hook;
ptrdiff_t errfunc; /* current error handling function (stack index) */
- l_uint32 nCcalls; /* number of allowed nested C calls - 'nci' */
+ l_uint32 nCcalls; /* number of nested (non-yieldable | C) calls */
int oldpc; /* last pc traced */
- int stacksize;
int basehookcount;
int hookcount;
volatile l_signalT hookmask;
@@ -389,12 +355,11 @@ LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);
LUAI_FUNC void luaE_freeCI (lua_State *L);
LUAI_FUNC void luaE_shrinkCI (lua_State *L);
-LUAI_FUNC void luaE_enterCcall (lua_State *L);
+LUAI_FUNC void luaE_checkcstack (lua_State *L);
+LUAI_FUNC void luaE_incCstack (lua_State *L);
LUAI_FUNC void luaE_warning (lua_State *L, const char *msg, int tocont);
LUAI_FUNC void luaE_warnerror (lua_State *L, const char *where);
-#define luaE_exitCcall(L) ((L)->nCcalls++)
-
#endif