aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/ldo.c b/ldo.c
index c92573d6..8085b735 100644
--- a/ldo.c
+++ b/ldo.c
@@ -206,6 +206,25 @@ l_noret luaD_errerr (lua_State *L) {
206 206
207 207
208/* 208/*
209** Check whether stacks have enough space to run a simple function (such
210** as a finalizer): At least BASIC_STACK_SIZE in the Lua stack, two
211** available CallInfos, and two "slots" in the C stack.
212*/
213int luaD_checkminstack (lua_State *L) {
214 if (getCcalls(L) >= LUAI_MAXCCALLS - 2)
215 return 0; /* not enough C-stack slots */
216 if (L->ci->next == NULL && luaE_extendCI(L, 0) == NULL)
217 return 0; /* unable to allocate first ci */
218 if (L->ci->next->next == NULL && luaE_extendCI(L, 0) == NULL)
219 return 0; /* unable to allocate second ci */
220 if (L->stack_last.p - L->top.p >= BASIC_STACK_SIZE)
221 return 1; /* enough (BASIC_STACK_SIZE) free slots in the Lua stack */
222 else /* try to grow stack to a size with enough free slots */
223 return luaD_growstack(L, BASIC_STACK_SIZE, 0);
224}
225
226
227/*
209** Reallocate the stack to a new size, correcting all pointers into it. 228** Reallocate the stack to a new size, correcting all pointers into it.
210** In ISO C, any pointer use after the pointer has been deallocated is 229** In ISO C, any pointer use after the pointer has been deallocated is
211** undefined behavior. So, before the reallocation, all pointers are 230** undefined behavior. So, before the reallocation, all pointers are
@@ -503,7 +522,7 @@ void luaD_poscall (lua_State *L, CallInfo *ci, int nres) {
503 522
504 523
505 524
506#define next_ci(L) (L->ci->next ? L->ci->next : luaE_extendCI(L)) 525#define next_ci(L) (L->ci->next ? L->ci->next : luaE_extendCI(L, 1))
507 526
508 527
509l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nret, 528l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nret,