diff options
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 17 |
1 files changed, 9 insertions, 8 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.83 2009/06/18 18:59:18 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.84 2009/06/19 14:21:23 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -86,14 +86,15 @@ LUA_API int lua_checkstack (lua_State *L, int size) { | |||
| 86 | int res = 1; | 86 | int res = 1; |
| 87 | CallInfo *ci = L->ci; | 87 | CallInfo *ci = L->ci; |
| 88 | lua_lock(L); | 88 | lua_lock(L); |
| 89 | if (size > LUAI_MAXCSTACK || | 89 | if (L->stack_last - L->top <= size) { /* need to grow stack? */ |
| 90 | (L->top - (ci->func + 1) + size) > LUAI_MAXCSTACK) | 90 | int inuse = L->top - L->stack + EXTRA_STACK; |
| 91 | res = 0; /* stack overflow */ | 91 | if (inuse > LUAI_MAXSTACK - size) /* can grow without overflow? */ |
| 92 | else if (size > 0) { | 92 | res = 0; /* no */ |
| 93 | luaD_checkstack(L, size); | 93 | else |
| 94 | if (ci->top < L->top + size) | 94 | luaD_growstack(L, size); |
| 95 | ci->top = L->top + size; | ||
| 96 | } | 95 | } |
| 96 | if (res && ci->top < L->top + size) | ||
| 97 | ci->top = L->top + size; /* adjust frame top */ | ||
| 97 | lua_unlock(L); | 98 | lua_unlock(L); |
| 98 | return res; | 99 | return res; |
| 99 | } | 100 | } |
