aboutsummaryrefslogtreecommitdiff
path: root/lstate.h
diff options
context:
space:
mode:
Diffstat (limited to 'lstate.h')
-rw-r--r--lstate.h52
1 files changed, 42 insertions, 10 deletions
diff --git a/lstate.h b/lstate.h
index ce337707..b069b390 100644
--- a/lstate.h
+++ b/lstate.h
@@ -15,7 +15,6 @@
15 15
16 16
17/* 17/*
18
19** Some notes about garbage-collected objects: All objects in Lua must 18** Some notes about garbage-collected objects: All objects in Lua must
20** be kept somehow accessible until being freed, so all objects always 19** be kept somehow accessible until being freed, so all objects always
21** belong to one (and only one) of these lists, using field 'next' of 20** belong to one (and only one) of these lists, using field 'next' of
@@ -43,26 +42,58 @@
43** 'weak': tables with weak values to be cleared; 42** 'weak': tables with weak values to be cleared;
44** 'ephemeron': ephemeron tables with white->white entries; 43** 'ephemeron': ephemeron tables with white->white entries;
45** 'allweak': tables with weak keys and/or weak values to be cleared. 44** 'allweak': tables with weak keys and/or weak values to be cleared.
46
47*/ 45*/
48 46
49 47
50/*
51 48
49/*
52** About 'nCcalls': each thread in Lua (a lua_State) keeps a count of 50** About 'nCcalls': each thread in Lua (a lua_State) keeps a count of
53** how many "C calls" it has in the C stack, to avoid C-stack overflow. 51** how many "C calls" it can do in the C stack, to avoid C-stack overflow.
54** This count is very rough approximation; it considers only recursive 52** This count is very rough approximation; it considers only recursive
55** functions inside the interpreter, as non-recursive calls can be 53** functions inside the interpreter, as non-recursive calls can be
56** considered using a fixed (although unknown) amount of stack space. 54** considered using a fixed (although unknown) amount of stack space.
57** 55**
56** The count itself has two parts: the lower part is the count itself;
57** the higher part counts the number of non-yieldable calls in the stack.
58**
59** Because calls to external C functions can use of unkown amount
60** of space (e.g., functions using an auxiliary buffer), calls
61** to these functions add more than one to the count.
62**
58** The proper count also includes the number of CallInfo structures 63** The proper count also includes the number of CallInfo structures
59** allocated by Lua, as a kind of "potential" calls. So, when Lua 64** allocated by Lua, as a kind of "potential" calls. So, when Lua
60** calls a function (and "consumes" one CallInfo), it needs neither to 65** calls a function (and "consumes" one CallInfo), it needs neither to
61** increment nor to check 'nCcalls', as its use of C stack is already 66** increment nor to check 'nCcalls', as its use of C stack is already
62** accounted for. 67** accounted for.
63
64*/ 68*/
65 69
70/* number of "C stack slots" used by an external C function */
71#define CSTACKCF 10
72
73/* true if this thread does not have non-yieldable calls in the stack */
74#define yieldable(L) (((L)->nCcalls & 0xffff0000) == 0)
75
76/* real number of C calls */
77#define getCcalls(L) ((L)->nCcalls & 0xffff)
78
79
80/* Increment the number of non-yieldable calls */
81#define incnny(L) ((L)->nCcalls += 0x10000)
82
83/* Decrement the number of non-yieldable calls */
84#define decnny(L) ((L)->nCcalls -= 0x10000)
85
86/* Increment the number of non-yieldable calls and nCcalls */
87#define incXCcalls(L) ((L)->nCcalls += 0x10000 + CSTACKCF)
88
89/* Decrement the number of non-yieldable calls and nCcalls */
90#define decXCcalls(L) ((L)->nCcalls -= 0x10000 + CSTACKCF)
91
92
93
94
95
96
66struct lua_longjmp; /* defined in ldo.c */ 97struct lua_longjmp; /* defined in ldo.c */
67 98
68 99
@@ -208,8 +239,9 @@ typedef struct global_State {
208*/ 239*/
209struct lua_State { 240struct lua_State {
210 CommonHeader; 241 CommonHeader;
211 unsigned short nci; /* number of items in 'ci' list */
212 lu_byte status; 242 lu_byte status;
243 lu_byte allowhook;
244 unsigned short nci; /* number of items in 'ci' list */
213 StkId top; /* first free slot in the stack */ 245 StkId top; /* first free slot in the stack */
214 global_State *l_G; 246 global_State *l_G;
215 CallInfo *ci; /* call info for current function */ 247 CallInfo *ci; /* call info for current function */
@@ -223,13 +255,11 @@ struct lua_State {
223 CallInfo base_ci; /* CallInfo for first level (C calling Lua) */ 255 CallInfo base_ci; /* CallInfo for first level (C calling Lua) */
224 volatile lua_Hook hook; 256 volatile lua_Hook hook;
225 ptrdiff_t errfunc; /* current error handling function (stack index) */ 257 ptrdiff_t errfunc; /* current error handling function (stack index) */
258 l_uint32 nCcalls; /* number of allowed nested C calls - 'nci' */
226 int stacksize; 259 int stacksize;
227 int basehookcount; 260 int basehookcount;
228 int hookcount; 261 int hookcount;
229 unsigned short nny; /* number of non-yieldable calls in stack */
230 unsigned short nCcalls; /* number of nested C calls + 'nny' */
231 l_signalT hookmask; 262 l_signalT hookmask;
232 lu_byte allowhook;
233}; 263};
234 264
235 265
@@ -283,8 +313,10 @@ LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
283LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L); 313LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);
284LUAI_FUNC void luaE_freeCI (lua_State *L); 314LUAI_FUNC void luaE_freeCI (lua_State *L);
285LUAI_FUNC void luaE_shrinkCI (lua_State *L); 315LUAI_FUNC void luaE_shrinkCI (lua_State *L);
286LUAI_FUNC void luaE_incCcalls (lua_State *L); 316LUAI_FUNC void luaE_enterCcall (lua_State *L);
317
287 318
319#define luaE_exitCcall(L) ((L)->nCcalls--)
288 320
289#endif 321#endif
290 322