From c16a35d6696ac995ef6c7b60f251f6821811f50f Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 7 Mar 2002 15:15:10 -0300 Subject: [PATCH] `lua_stackspace' replaced by `lua_checkstack' --- lapi.c | 19 ++++++++++++++----- lauxlib.c | 4 ++-- lua.h | 4 ++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lapi.c b/lapi.c index 44001697..ec13bb74 100644 --- a/lapi.c +++ b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 1.174 2002/02/14 21:46:13 roberto Exp roberto $ +** $Id: lapi.c,v 1.175 2002/03/04 21:29:41 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -80,8 +80,18 @@ void luaA_pushobject (lua_State *L, const TObject *o) { incr_top(L); } -LUA_API int lua_stackspace (lua_State *L) { - return (L->stack_last - L->top); + +LUA_API int lua_checkstack (lua_State *L, int size) { + int res; + lua_lock(L); + if ((L->top - L->stack) + size >= LUA_MAXSTACK) + res = 0; /* stack overflow */ + luaD_checkstack(L, size); + if (L->ci->top < L->top + size) + L->ci->top = L->top + size; + res = 1; + lua_unlock(L); + return res; } @@ -667,8 +677,7 @@ LUA_API int lua_pushupvalues (lua_State *L) { func = (L->ci->base - 1); api_check(L, iscfunction(func)); n = clvalue(func)->c.nupvalues; - if (LUA_MINSTACK+n > lua_stackspace(L)) - luaD_error(L, "stack overflow"); + luaD_checkstack(L, n + LUA_MINSTACK); for (i=0; itop, &clvalue(func)->c.upvalue[i]); L->top++; diff --git a/lauxlib.c b/lauxlib.c index d71763fb..ceef7026 100644 --- a/lauxlib.c +++ b/lauxlib.c @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.c,v 1.1 2001/11/29 22:14:34 rieru Exp rieru $ +** $Id: lauxlib.c,v 1.60 2002/02/14 21:41:53 roberto Exp roberto $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -67,7 +67,7 @@ static void tag_error (lua_State *L, int narg, int tag) { LUALIB_API void luaL_check_stack (lua_State *L, int space, const char *mes) { - if (space > lua_stackspace(L)) + if (!lua_checkstack(L, space)) luaL_verror(L, "stack overflow (%.30s)", mes); } diff --git a/lua.h b/lua.h index e0e913b9..2fd5ff0a 100644 --- a/lua.h +++ b/lua.h @@ -1,5 +1,5 @@ /* -** $Id: lua.h,v 1.1 2001/11/29 22:14:34 rieru Exp rieru $ +** $Id: lua.h,v 1.121 2002/02/14 21:40:13 roberto Exp roberto $ ** Lua - An Extensible Extension Language ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil ** e-mail: info@lua.org @@ -109,7 +109,7 @@ LUA_API void lua_pushvalue (lua_State *L, int index); LUA_API void lua_remove (lua_State *L, int index); LUA_API void lua_insert (lua_State *L, int index); LUA_API void lua_replace (lua_State *L, int index); -LUA_API int lua_stackspace (lua_State *L); +LUA_API int lua_checkstack (lua_State *L, int size); /*