diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-03-20 09:51:29 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-03-20 09:51:29 -0300 |
| commit | 48e732e07d21d585982d1c53be0d9031f021f014 (patch) | |
| tree | 194a6bfa528c857ddf2951bb73c75c84844b78af | |
| parent | 938092489b9df19c9da7481c68d74dd7e0104949 (diff) | |
| download | lua-48e732e07d21d585982d1c53be0d9031f021f014.tar.gz lua-48e732e07d21d585982d1c53be0d9031f021f014.tar.bz2 lua-48e732e07d21d585982d1c53be0d9031f021f014.zip | |
improvements in stack control
| -rw-r--r-- | lapi.c | 16 |
1 files changed, 9 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 1.177 2002/03/18 18:18:35 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.178 2002/03/18 20:11:52 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 | */ |
| @@ -35,7 +35,7 @@ const char lua_ident[] = | |||
| 35 | 35 | ||
| 36 | #define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->ci->base)) | 36 | #define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->ci->base)) |
| 37 | 37 | ||
| 38 | #define api_incr_top(L) (api_check(L, L->top+1<L->stack_last), L->top++) | 38 | #define api_incr_top(L) (api_check(L, L->top<L->ci->top), L->top++) |
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | 41 | ||
| @@ -85,12 +85,14 @@ void luaA_pushobject (lua_State *L, const TObject *o) { | |||
| 85 | LUA_API int lua_checkstack (lua_State *L, int size) { | 85 | LUA_API int lua_checkstack (lua_State *L, int size) { |
| 86 | int res; | 86 | int res; |
| 87 | lua_lock(L); | 87 | lua_lock(L); |
| 88 | if ((L->top - L->stack) + size >= LUA_MAXSTACK) | 88 | if ((L->top - L->stack) >= LUA_MAXSTACK - size) |
| 89 | res = 0; /* stack overflow */ | 89 | res = 0; /* stack overflow */ |
| 90 | luaD_checkstack(L, size); | 90 | else { |
| 91 | if (L->ci->top < L->top + size) | 91 | luaD_checkstack(L, size); |
| 92 | L->ci->top = L->top + size; | 92 | if (L->ci->top < L->top + size) |
| 93 | res = 1; | 93 | L->ci->top = L->top + size; |
| 94 | res = 1; | ||
| 95 | } | ||
| 94 | lua_unlock(L); | 96 | lua_unlock(L); |
| 95 | return res; | 97 | return res; |
| 96 | } | 98 | } |
