aboutsummaryrefslogtreecommitdiff
path: root/lstate.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-09-23 10:18:01 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-10-12 12:29:09 -0300
commit287b302acb8d925178e9edb800f0a8d18c7d35f6 (patch)
treebd662481ea995dc8c050324d553146e870434d93 /lstate.h
parent5d8ce05b3f6fad79e37ed21c1076e47a322472c6 (diff)
downloadlua-287b302acb8d925178e9edb800f0a8d18c7d35f6.tar.gz
lua-287b302acb8d925178e9edb800f0a8d18c7d35f6.tar.bz2
lua-287b302acb8d925178e9edb800f0a8d18c7d35f6.zip
Revision of stackless implementation
- more organized handling of 'nCcalls' - comments - deprecation of 'setcstacklimit'
Diffstat (limited to 'lstate.h')
-rw-r--r--lstate.h56
1 files changed, 10 insertions, 46 deletions
diff --git a/lstate.h b/lstate.h
index 983aa0d5..a05db376 100644
--- a/lstate.h
+++ b/lstate.h
@@ -87,48 +87,12 @@
87 87
88 88
89/* 89/*
90** About 'nCcalls': each thread in Lua (a lua_State) keeps a count of 90** About 'nCcalls': This count has two parts: the lower 16 bits counts
91** how many "C calls" it still can do in the C stack, to avoid C-stack 91** the number of recursive invocations in the C stack; the higher
92** overflow. This count is very rough approximation; it considers only 92** 16 bits counts the number of non-yieldable calls in the stack.
93** recursive functions inside the interpreter, as non-recursive calls 93** (They are together so that we can change and save both with one
94** can be considered using a fixed (although unknown) amount of stack 94** instruction.)
95** space.
96**
97** The count has two parts: the lower part is the count itself; the
98** higher part counts the number of non-yieldable calls in the stack.
99** (They are together so that we can change both with one instruction.)
100**
101** Because calls to external C functions can use an unknown amount
102** of space (e.g., functions using an auxiliary buffer), calls
103** to these functions add more than one to the count (see CSTACKCF).
104**
105** The proper count excludes the number of CallInfo structures allocated
106** by Lua, as a kind of "potential" calls. So, when Lua calls a function
107** (and "consumes" one CallInfo), it needs neither to decrement nor to
108** check 'nCcalls', as its use of C stack is already accounted for.
109*/
110
111/* number of "C stack slots" used by an external C function */
112#define CSTACKCF 10
113
114
115/*
116** The C-stack size is sliced in the following zones:
117** - larger than CSTACKERR: normal stack;
118** - [CSTACKMARK, CSTACKERR]: buffer zone to signal a stack overflow;
119** - [CSTACKCF, CSTACKERRMARK]: error-handling zone;
120** - below CSTACKERRMARK: buffer zone to signal overflow during overflow;
121** (Because the counter can be decremented CSTACKCF at once, we need
122** the so called "buffer zones", with at least that size, to properly
123** detect a change from one zone to the next.)
124*/ 95*/
125#define CSTACKERR (8 * CSTACKCF)
126#define CSTACKMARK (CSTACKERR - (CSTACKCF + 2))
127#define CSTACKERRMARK (CSTACKCF + 2)
128
129
130/* initial limit for the C-stack of threads */
131#define CSTACKTHREAD (2 * CSTACKERR)
132 96
133 97
134/* true if this thread does not have non-yieldable calls in the stack */ 98/* true if this thread does not have non-yieldable calls in the stack */
@@ -144,7 +108,8 @@
144/* Decrement the number of non-yieldable calls */ 108/* Decrement the number of non-yieldable calls */
145#define decnny(L) ((L)->nCcalls -= 0x10000) 109#define decnny(L) ((L)->nCcalls -= 0x10000)
146 110
147 111/* Non-yieldable call increment */
112#define nyci (0x10000 | 1)
148 113
149 114
150 115
@@ -290,7 +255,6 @@ typedef struct global_State {
290 TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */ 255 TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */
291 lua_WarnFunction warnf; /* warning function */ 256 lua_WarnFunction warnf; /* warning function */
292 void *ud_warn; /* auxiliary data to 'warnf' */ 257 void *ud_warn; /* auxiliary data to 'warnf' */
293 unsigned int Cstacklimit; /* current limit for the C stack */
294} global_State; 258} global_State;
295 259
296 260
@@ -314,7 +278,7 @@ struct lua_State {
314 CallInfo base_ci; /* CallInfo for first level (C calling Lua) */ 278 CallInfo base_ci; /* CallInfo for first level (C calling Lua) */
315 volatile lua_Hook hook; 279 volatile lua_Hook hook;
316 ptrdiff_t errfunc; /* current error handling function (stack index) */ 280 ptrdiff_t errfunc; /* current error handling function (stack index) */
317 l_uint32 nCcalls; /* number of allowed nested C calls - 'nci' */ 281 l_uint32 nCcalls; /* number of nested (non-yieldable | C) calls */
318 int oldpc; /* last pc traced */ 282 int oldpc; /* last pc traced */
319 int stacksize; 283 int stacksize;
320 int basehookcount; 284 int basehookcount;
@@ -383,11 +347,11 @@ LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
383LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L); 347LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);
384LUAI_FUNC void luaE_freeCI (lua_State *L); 348LUAI_FUNC void luaE_freeCI (lua_State *L);
385LUAI_FUNC void luaE_shrinkCI (lua_State *L); 349LUAI_FUNC void luaE_shrinkCI (lua_State *L);
350LUAI_FUNC void luaE_checkcstack (lua_State *L);
351LUAI_FUNC void luaE_incCstack (lua_State *L);
386LUAI_FUNC void luaE_warning (lua_State *L, const char *msg, int tocont); 352LUAI_FUNC void luaE_warning (lua_State *L, const char *msg, int tocont);
387LUAI_FUNC void luaE_warnerror (lua_State *L, const char *where); 353LUAI_FUNC void luaE_warnerror (lua_State *L, const char *where);
388 354
389 355
390#define luaE_exitCcall(L) ((L)->nCcalls++)
391
392#endif 356#endif
393 357