diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-03-25 14:12:06 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-03-25 14:12:06 -0300 |
commit | 0443ad9e288825b6e4441eb11104bcdb4ff4593a (patch) | |
tree | e342cb5e94c97f8e024ed89e8de6d44a207992cd | |
parent | f9b0cf0e2ee35c5444959f77e95f3f07376b9e3e (diff) | |
download | lua-0443ad9e288825b6e4441eb11104bcdb4ff4593a.tar.gz lua-0443ad9e288825b6e4441eb11104bcdb4ff4593a.tar.bz2 lua-0443ad9e288825b6e4441eb11104bcdb4ff4593a.zip |
LUAI_MAXCCALLS renamed LUAI_MAXCSTACK
The limit LUAI_MAXCCALLS was renamed LUAI_MAXCSTACK, which better
represents its meaning. Moreover, its definition was moved to
'luaconf.h', given its importance now that Lua does not use
a "stackless" implementation.
-rw-r--r-- | ldo.c | 4 | ||||
-rw-r--r-- | llimits.h | 9 | ||||
-rw-r--r-- | lstate.c | 16 | ||||
-rw-r--r-- | ltests.h | 4 | ||||
-rw-r--r-- | luaconf.h | 15 |
5 files changed, 27 insertions, 21 deletions
@@ -521,7 +521,7 @@ void luaD_call (lua_State *L, StkId func, int nresults) { | |||
521 | */ | 521 | */ |
522 | void luaD_callnoyield (lua_State *L, StkId func, int nResults) { | 522 | void luaD_callnoyield (lua_State *L, StkId func, int nResults) { |
523 | incXCcalls(L); | 523 | incXCcalls(L); |
524 | if (getCcalls(L) >= LUAI_MAXCCALLS) /* possible stack overflow? */ | 524 | if (getCcalls(L) >= LUAI_MAXCSTACK) /* possible stack overflow? */ |
525 | luaE_freeCI(L); | 525 | luaE_freeCI(L); |
526 | luaD_call(L, func, nResults); | 526 | luaD_call(L, func, nResults); |
527 | decXCcalls(L); | 527 | decXCcalls(L); |
@@ -673,7 +673,7 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs, | |||
673 | L->nCcalls = 1; | 673 | L->nCcalls = 1; |
674 | else /* correct 'nCcalls' for this thread */ | 674 | else /* correct 'nCcalls' for this thread */ |
675 | L->nCcalls = getCcalls(from) - from->nci + L->nci + CSTACKCF; | 675 | L->nCcalls = getCcalls(from) - from->nci + L->nci + CSTACKCF; |
676 | if (L->nCcalls >= LUAI_MAXCCALLS) | 676 | if (L->nCcalls >= LUAI_MAXCSTACK) |
677 | return resume_error(L, "C stack overflow", nargs); | 677 | return resume_error(L, "C stack overflow", nargs); |
678 | luai_userstateresume(L, nargs); | 678 | luai_userstateresume(L, nargs); |
679 | api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs); | 679 | api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs); |
@@ -168,15 +168,6 @@ typedef LUAI_UACINT l_uacInt; | |||
168 | #endif | 168 | #endif |
169 | 169 | ||
170 | 170 | ||
171 | /* | ||
172 | ** maximum depth for nested C calls and syntactical nested non-terminals | ||
173 | ** in a program. (Value must fit in an unsigned short int. It must also | ||
174 | ** be compatible with the size of the C stack.) | ||
175 | */ | ||
176 | #if !defined(LUAI_MAXCCALLS) | ||
177 | #define LUAI_MAXCCALLS 2200 | ||
178 | #endif | ||
179 | |||
180 | 171 | ||
181 | 172 | ||
182 | /* | 173 | /* |
@@ -100,13 +100,13 @@ void luaE_setdebt (global_State *g, l_mem debt) { | |||
100 | ** Increment count of "C calls" and check for overflows. In case of | 100 | ** Increment count of "C calls" and check for overflows. In case of |
101 | ** a stack overflow, check appropriate error ("regular" overflow or | 101 | ** a stack overflow, check appropriate error ("regular" overflow or |
102 | ** overflow while handling stack overflow). | 102 | ** overflow while handling stack overflow). |
103 | ** If 'nCcalls' is larger than LUAI_MAXCCALLS but smaller than | 103 | ** If 'nCcalls' is larger than LUAI_MAXCSTACK but smaller than |
104 | ** LUAI_MAXCCALLS + CSTACKCF (plus 2 to avoid by-one errors), it means | 104 | ** LUAI_MAXCSTACK + CSTACKCF (plus 2 to avoid by-one errors), it means |
105 | ** it has just entered the "overflow zone", so the function raises an | 105 | ** it has just entered the "overflow zone", so the function raises an |
106 | ** overflow error. | 106 | ** overflow error. |
107 | ** If 'nCcalls' is larger than LUAI_MAXCCALLS + CSTACKCF + 2 | 107 | ** If 'nCcalls' is larger than LUAI_MAXCSTACK + CSTACKCF + 2 |
108 | ** (which means it is already handling an overflow) but smaller than | 108 | ** (which means it is already handling an overflow) but smaller than |
109 | ** 9/8 of LUAI_MAXCCALLS, does not report an error (to allow message | 109 | ** 9/8 of LUAI_MAXCSTACK, does not report an error (to allow message |
110 | ** handling to work). | 110 | ** handling to work). |
111 | ** Otherwise, report a stack overflow while handling a stack overflow | 111 | ** Otherwise, report a stack overflow while handling a stack overflow |
112 | ** (probably caused by a repeating error in the message handling | 112 | ** (probably caused by a repeating error in the message handling |
@@ -115,16 +115,16 @@ void luaE_setdebt (global_State *g, l_mem debt) { | |||
115 | void luaE_enterCcall (lua_State *L) { | 115 | void luaE_enterCcall (lua_State *L) { |
116 | int ncalls = getCcalls(L); | 116 | int ncalls = getCcalls(L); |
117 | L->nCcalls++; | 117 | L->nCcalls++; |
118 | if (ncalls >= LUAI_MAXCCALLS) { /* possible overflow? */ | 118 | if (ncalls >= LUAI_MAXCSTACK) { /* possible overflow? */ |
119 | luaE_freeCI(L); /* release unused CIs */ | 119 | luaE_freeCI(L); /* release unused CIs */ |
120 | ncalls = getCcalls(L); /* update call count */ | 120 | ncalls = getCcalls(L); /* update call count */ |
121 | if (ncalls >= LUAI_MAXCCALLS) { /* still overflow? */ | 121 | if (ncalls >= LUAI_MAXCSTACK) { /* still overflow? */ |
122 | if (ncalls <= LUAI_MAXCCALLS + CSTACKCF + 2) { | 122 | if (ncalls <= LUAI_MAXCSTACK + CSTACKCF + 2) { |
123 | /* no error before increments; raise the error now */ | 123 | /* no error before increments; raise the error now */ |
124 | L->nCcalls += (CSTACKCF + 4); /* avoid raising it again */ | 124 | L->nCcalls += (CSTACKCF + 4); /* avoid raising it again */ |
125 | luaG_runerror(L, "C stack overflow"); | 125 | luaG_runerror(L, "C stack overflow"); |
126 | } | 126 | } |
127 | else if (ncalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS >> 3))) | 127 | else if (ncalls >= (LUAI_MAXCSTACK + (LUAI_MAXCSTACK >> 3))) |
128 | luaD_throw(L, LUA_ERRERR); /* error while handling stack error */ | 128 | luaD_throw(L, LUA_ERRERR); /* error while handling stack error */ |
129 | } | 129 | } |
130 | } | 130 | } |
@@ -30,8 +30,8 @@ | |||
30 | 30 | ||
31 | 31 | ||
32 | /* compiled with -O0, Lua uses a lot of C stack space... */ | 32 | /* compiled with -O0, Lua uses a lot of C stack space... */ |
33 | #undef LUAI_MAXCCALLS | 33 | #undef LUAI_MAXCSTACK |
34 | #define LUAI_MAXCCALLS 400 | 34 | #define LUAI_MAXCSTACK 400 |
35 | 35 | ||
36 | /* to avoid warnings, and to make sure value is really unused */ | 36 | /* to avoid warnings, and to make sure value is really unused */ |
37 | #define UNUSED(x) (x=0, (void)(x)) | 37 | #define UNUSED(x) (x=0, (void)(x)) |
@@ -28,6 +28,21 @@ | |||
28 | */ | 28 | */ |
29 | 29 | ||
30 | /* | 30 | /* |
31 | @@ LUAI_MAXCSTACK defines the maximum depth for nested calls and | ||
32 | ** also limits the maximum depth of other recursive algorithms in | ||
33 | ** the implementation, such as syntactic analysis. A value too | ||
34 | ** large may allow the interpreter to crash (C-stack overflow). | ||
35 | ** The default value seems ok for regular machines, but may be | ||
36 | ** too high for restricted hardware. | ||
37 | ** The test file 'cstack.lua' may help finding a good limit. | ||
38 | ** (It will crash with a limit too high.) | ||
39 | */ | ||
40 | #if !defined(LUAI_MAXCSTACK) | ||
41 | #define LUAI_MAXCSTACK 2200 | ||
42 | #endif | ||
43 | |||
44 | |||
45 | /* | ||
31 | @@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. You | 46 | @@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. You |
32 | ** can also define LUA_32BITS in the make file, but changing here you | 47 | ** can also define LUA_32BITS in the make file, but changing here you |
33 | ** ensure that all software connected to Lua will be compiled with the | 48 | ** ensure that all software connected to Lua will be compiled with the |