mirror of https://github.com/rusefi/lua.git
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.
This commit is contained in:
parent
f9b0cf0e2e
commit
0443ad9e28
4
ldo.c
4
ldo.c
|
@ -521,7 +521,7 @@ void luaD_call (lua_State *L, StkId func, int nresults) {
|
||||||
*/
|
*/
|
||||||
void luaD_callnoyield (lua_State *L, StkId func, int nResults) {
|
void luaD_callnoyield (lua_State *L, StkId func, int nResults) {
|
||||||
incXCcalls(L);
|
incXCcalls(L);
|
||||||
if (getCcalls(L) >= LUAI_MAXCCALLS) /* possible stack overflow? */
|
if (getCcalls(L) >= LUAI_MAXCSTACK) /* possible stack overflow? */
|
||||||
luaE_freeCI(L);
|
luaE_freeCI(L);
|
||||||
luaD_call(L, func, nResults);
|
luaD_call(L, func, nResults);
|
||||||
decXCcalls(L);
|
decXCcalls(L);
|
||||||
|
@ -673,7 +673,7 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs,
|
||||||
L->nCcalls = 1;
|
L->nCcalls = 1;
|
||||||
else /* correct 'nCcalls' for this thread */
|
else /* correct 'nCcalls' for this thread */
|
||||||
L->nCcalls = getCcalls(from) - from->nci + L->nci + CSTACKCF;
|
L->nCcalls = getCcalls(from) - from->nci + L->nci + CSTACKCF;
|
||||||
if (L->nCcalls >= LUAI_MAXCCALLS)
|
if (L->nCcalls >= LUAI_MAXCSTACK)
|
||||||
return resume_error(L, "C stack overflow", nargs);
|
return resume_error(L, "C stack overflow", nargs);
|
||||||
luai_userstateresume(L, nargs);
|
luai_userstateresume(L, nargs);
|
||||||
api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs);
|
api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs);
|
||||||
|
|
|
@ -168,15 +168,6 @@ typedef LUAI_UACINT l_uacInt;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
** maximum depth for nested C calls and syntactical nested non-terminals
|
|
||||||
** in a program. (Value must fit in an unsigned short int. It must also
|
|
||||||
** be compatible with the size of the C stack.)
|
|
||||||
*/
|
|
||||||
#if !defined(LUAI_MAXCCALLS)
|
|
||||||
#define LUAI_MAXCCALLS 2200
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
16
lstate.c
16
lstate.c
|
@ -100,13 +100,13 @@ void luaE_setdebt (global_State *g, l_mem debt) {
|
||||||
** Increment count of "C calls" and check for overflows. In case of
|
** Increment count of "C calls" and check for overflows. In case of
|
||||||
** a stack overflow, check appropriate error ("regular" overflow or
|
** a stack overflow, check appropriate error ("regular" overflow or
|
||||||
** overflow while handling stack overflow).
|
** overflow while handling stack overflow).
|
||||||
** If 'nCcalls' is larger than LUAI_MAXCCALLS but smaller than
|
** If 'nCcalls' is larger than LUAI_MAXCSTACK but smaller than
|
||||||
** LUAI_MAXCCALLS + CSTACKCF (plus 2 to avoid by-one errors), it means
|
** LUAI_MAXCSTACK + CSTACKCF (plus 2 to avoid by-one errors), it means
|
||||||
** it has just entered the "overflow zone", so the function raises an
|
** it has just entered the "overflow zone", so the function raises an
|
||||||
** overflow error.
|
** overflow error.
|
||||||
** If 'nCcalls' is larger than LUAI_MAXCCALLS + CSTACKCF + 2
|
** If 'nCcalls' is larger than LUAI_MAXCSTACK + CSTACKCF + 2
|
||||||
** (which means it is already handling an overflow) but smaller than
|
** (which means it is already handling an overflow) but smaller than
|
||||||
** 9/8 of LUAI_MAXCCALLS, does not report an error (to allow message
|
** 9/8 of LUAI_MAXCSTACK, does not report an error (to allow message
|
||||||
** handling to work).
|
** handling to work).
|
||||||
** Otherwise, report a stack overflow while handling a stack overflow
|
** Otherwise, report a stack overflow while handling a stack overflow
|
||||||
** (probably caused by a repeating error in the message handling
|
** (probably caused by a repeating error in the message handling
|
||||||
|
@ -115,16 +115,16 @@ void luaE_setdebt (global_State *g, l_mem debt) {
|
||||||
void luaE_enterCcall (lua_State *L) {
|
void luaE_enterCcall (lua_State *L) {
|
||||||
int ncalls = getCcalls(L);
|
int ncalls = getCcalls(L);
|
||||||
L->nCcalls++;
|
L->nCcalls++;
|
||||||
if (ncalls >= LUAI_MAXCCALLS) { /* possible overflow? */
|
if (ncalls >= LUAI_MAXCSTACK) { /* possible overflow? */
|
||||||
luaE_freeCI(L); /* release unused CIs */
|
luaE_freeCI(L); /* release unused CIs */
|
||||||
ncalls = getCcalls(L); /* update call count */
|
ncalls = getCcalls(L); /* update call count */
|
||||||
if (ncalls >= LUAI_MAXCCALLS) { /* still overflow? */
|
if (ncalls >= LUAI_MAXCSTACK) { /* still overflow? */
|
||||||
if (ncalls <= LUAI_MAXCCALLS + CSTACKCF + 2) {
|
if (ncalls <= LUAI_MAXCSTACK + CSTACKCF + 2) {
|
||||||
/* no error before increments; raise the error now */
|
/* no error before increments; raise the error now */
|
||||||
L->nCcalls += (CSTACKCF + 4); /* avoid raising it again */
|
L->nCcalls += (CSTACKCF + 4); /* avoid raising it again */
|
||||||
luaG_runerror(L, "C stack overflow");
|
luaG_runerror(L, "C stack overflow");
|
||||||
}
|
}
|
||||||
else if (ncalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS >> 3)))
|
else if (ncalls >= (LUAI_MAXCSTACK + (LUAI_MAXCSTACK >> 3)))
|
||||||
luaD_throw(L, LUA_ERRERR); /* error while handling stack error */
|
luaD_throw(L, LUA_ERRERR); /* error while handling stack error */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
4
ltests.h
4
ltests.h
|
@ -30,8 +30,8 @@
|
||||||
|
|
||||||
|
|
||||||
/* compiled with -O0, Lua uses a lot of C stack space... */
|
/* compiled with -O0, Lua uses a lot of C stack space... */
|
||||||
#undef LUAI_MAXCCALLS
|
#undef LUAI_MAXCSTACK
|
||||||
#define LUAI_MAXCCALLS 400
|
#define LUAI_MAXCSTACK 400
|
||||||
|
|
||||||
/* to avoid warnings, and to make sure value is really unused */
|
/* to avoid warnings, and to make sure value is really unused */
|
||||||
#define UNUSED(x) (x=0, (void)(x))
|
#define UNUSED(x) (x=0, (void)(x))
|
||||||
|
|
15
luaconf.h
15
luaconf.h
|
@ -27,6 +27,21 @@
|
||||||
** =====================================================================
|
** =====================================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
@@ LUAI_MAXCSTACK defines the maximum depth for nested calls and
|
||||||
|
** also limits the maximum depth of other recursive algorithms in
|
||||||
|
** the implementation, such as syntactic analysis. A value too
|
||||||
|
** large may allow the interpreter to crash (C-stack overflow).
|
||||||
|
** The default value seems ok for regular machines, but may be
|
||||||
|
** too high for restricted hardware.
|
||||||
|
** The test file 'cstack.lua' may help finding a good limit.
|
||||||
|
** (It will crash with a limit too high.)
|
||||||
|
*/
|
||||||
|
#if !defined(LUAI_MAXCSTACK)
|
||||||
|
#define LUAI_MAXCSTACK 2200
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. You
|
@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. You
|
||||||
** can also define LUA_32BITS in the make file, but changing here you
|
** can also define LUA_32BITS in the make file, but changing here you
|
||||||
|
|
Loading…
Reference in New Issue