diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-03-07 15:15:10 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-03-07 15:15:10 -0300 |
commit | c16a35d6696ac995ef6c7b60f251f6821811f50f (patch) | |
tree | 8a25bd8597f46fe7db32cce9efa6668f6b950edc | |
parent | 8f837e83b20f3c409ba187765c2bf5aefc111923 (diff) | |
download | lua-c16a35d6696ac995ef6c7b60f251f6821811f50f.tar.gz lua-c16a35d6696ac995ef6c7b60f251f6821811f50f.tar.bz2 lua-c16a35d6696ac995ef6c7b60f251f6821811f50f.zip |
`lua_stackspace' replaced by `lua_checkstack'
-rw-r--r-- | lapi.c | 19 | ||||
-rw-r--r-- | lauxlib.c | 4 | ||||
-rw-r--r-- | lua.h | 4 |
3 files changed, 18 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.174 2002/02/14 21:46:13 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.175 2002/03/04 21:29:41 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 | */ |
@@ -80,8 +80,18 @@ void luaA_pushobject (lua_State *L, const TObject *o) { | |||
80 | incr_top(L); | 80 | incr_top(L); |
81 | } | 81 | } |
82 | 82 | ||
83 | LUA_API int lua_stackspace (lua_State *L) { | 83 | |
84 | return (L->stack_last - L->top); | 84 | LUA_API int lua_checkstack (lua_State *L, int size) { |
85 | int res; | ||
86 | lua_lock(L); | ||
87 | if ((L->top - L->stack) + size >= LUA_MAXSTACK) | ||
88 | res = 0; /* stack overflow */ | ||
89 | luaD_checkstack(L, size); | ||
90 | if (L->ci->top < L->top + size) | ||
91 | L->ci->top = L->top + size; | ||
92 | res = 1; | ||
93 | lua_unlock(L); | ||
94 | return res; | ||
85 | } | 95 | } |
86 | 96 | ||
87 | 97 | ||
@@ -667,8 +677,7 @@ LUA_API int lua_pushupvalues (lua_State *L) { | |||
667 | func = (L->ci->base - 1); | 677 | func = (L->ci->base - 1); |
668 | api_check(L, iscfunction(func)); | 678 | api_check(L, iscfunction(func)); |
669 | n = clvalue(func)->c.nupvalues; | 679 | n = clvalue(func)->c.nupvalues; |
670 | if (LUA_MINSTACK+n > lua_stackspace(L)) | 680 | luaD_checkstack(L, n + LUA_MINSTACK); |
671 | luaD_error(L, "stack overflow"); | ||
672 | for (i=0; i<n; i++) { | 681 | for (i=0; i<n; i++) { |
673 | setobj(L->top, &clvalue(func)->c.upvalue[i]); | 682 | setobj(L->top, &clvalue(func)->c.upvalue[i]); |
674 | L->top++; | 683 | L->top++; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.1 2001/11/29 22:14:34 rieru Exp rieru $ | 2 | ** $Id: lauxlib.c,v 1.60 2002/02/14 21:41:53 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -67,7 +67,7 @@ static void tag_error (lua_State *L, int narg, int tag) { | |||
67 | 67 | ||
68 | 68 | ||
69 | LUALIB_API void luaL_check_stack (lua_State *L, int space, const char *mes) { | 69 | LUALIB_API void luaL_check_stack (lua_State *L, int space, const char *mes) { |
70 | if (space > lua_stackspace(L)) | 70 | if (!lua_checkstack(L, space)) |
71 | luaL_verror(L, "stack overflow (%.30s)", mes); | 71 | luaL_verror(L, "stack overflow (%.30s)", mes); |
72 | } | 72 | } |
73 | 73 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.h,v 1.1 2001/11/29 22:14:34 rieru Exp rieru $ | 2 | ** $Id: lua.h,v 1.121 2002/02/14 21:40:13 roberto Exp roberto $ |
3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil | 4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil |
5 | ** e-mail: info@lua.org | 5 | ** e-mail: info@lua.org |
@@ -109,7 +109,7 @@ LUA_API void lua_pushvalue (lua_State *L, int index); | |||
109 | LUA_API void lua_remove (lua_State *L, int index); | 109 | LUA_API void lua_remove (lua_State *L, int index); |
110 | LUA_API void lua_insert (lua_State *L, int index); | 110 | LUA_API void lua_insert (lua_State *L, int index); |
111 | LUA_API void lua_replace (lua_State *L, int index); | 111 | LUA_API void lua_replace (lua_State *L, int index); |
112 | LUA_API int lua_stackspace (lua_State *L); | 112 | LUA_API int lua_checkstack (lua_State *L, int size); |
113 | 113 | ||
114 | 114 | ||
115 | /* | 115 | /* |