diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-07-15 14:26:14 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-07-15 14:26:14 -0300 |
commit | f76f4cb79d84af4a7be9e0d75553bbe05a3ae90c (patch) | |
tree | dd9d1f8f3fb8c69f7617fe5688d7b1178bb7190e /lauxlib.c | |
parent | abb85fc059a5d6427b9dc36edee1619f2c7a1da8 (diff) | |
download | lua-f76f4cb79d84af4a7be9e0d75553bbe05a3ae90c.tar.gz lua-f76f4cb79d84af4a7be9e0d75553bbe05a3ae90c.tar.bz2 lua-f76f4cb79d84af4a7be9e0d75553bbe05a3ae90c.zip |
new way to control stack overflow, controling only total size of the stack
Diffstat (limited to 'lauxlib.c')
-rw-r--r-- | lauxlib.c | 25 |
1 files changed, 18 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.187 2009/06/18 18:59:58 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.188 2009/06/19 14:21:57 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 | */ |
@@ -106,9 +106,16 @@ static void pushfuncname (lua_State *L, lua_Debug *ar) { | |||
106 | 106 | ||
107 | static int countlevels (lua_State *L) { | 107 | static int countlevels (lua_State *L) { |
108 | lua_Debug ar; | 108 | lua_Debug ar; |
109 | int level = 1; | 109 | int li = 1, le = 1; |
110 | while (lua_getstack(L, level, &ar)) level++; | 110 | /* find an upper bound */ |
111 | return level; | 111 | while (lua_getstack(L, le, &ar)) { li = le; le *= 2; } |
112 | /* do a binary search */ | ||
113 | while (li < le) { | ||
114 | int m = (li + le)/2; | ||
115 | if (lua_getstack(L, m, &ar)) li = m + 1; | ||
116 | else le = m; | ||
117 | } | ||
118 | return le - 1; | ||
112 | } | 119 | } |
113 | 120 | ||
114 | 121 | ||
@@ -263,9 +270,13 @@ LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, | |||
263 | } | 270 | } |
264 | 271 | ||
265 | 272 | ||
266 | LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) { | 273 | LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg) { |
267 | if (!lua_checkstack(L, space)) | 274 | if (!lua_checkstack(L, space)) { |
268 | luaL_error(L, "stack overflow (%s)", mes); | 275 | if (msg) |
276 | luaL_error(L, "stack overflow (%s)", msg); | ||
277 | else | ||
278 | luaL_error(L, "stack overflow"); | ||
279 | } | ||
269 | } | 280 | } |
270 | 281 | ||
271 | 282 | ||