Browse Source

`lua_stackspace' replaced by `lua_checkstack'

v5-2
Roberto Ierusalimschy 23 years ago
parent
commit
c16a35d669
  1. 19
      lapi.c
  2. 4
      lauxlib.c
  3. 4
      lua.h

19
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; i<n; i++) {
setobj(L->top, &clvalue(func)->c.upvalue[i]);
L->top++;

4
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);
}

4
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);
/*

Loading…
Cancel
Save