aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-02-14 19:47:29 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-02-14 19:47:29 -0200
commitb0a5e156b8e6913c6eb8ed65ab28576b8b88f461 (patch)
tree11b32d6436e2c663171127990509d091c1ea847d /ldo.c
parentac178ee4788c13761ec0850b31ff17673a33f227 (diff)
downloadlua-b0a5e156b8e6913c6eb8ed65ab28576b8b88f461.tar.gz
lua-b0a5e156b8e6913c6eb8ed65ab28576b8b88f461.tar.bz2
lua-b0a5e156b8e6913c6eb8ed65ab28576b8b88f461.zip
no more maximum stack size
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/ldo.c b/ldo.c
index ec39419a..2c2a28cd 100644
--- a/ldo.c
+++ b/ldo.c
@@ -71,26 +71,26 @@ void luaD_reallocstack (lua_State *L, int newsize) {
71 71
72 72
73static void restore_stack_limit (lua_State *L) { 73static void restore_stack_limit (lua_State *L) {
74 if (L->stacksize > L->maxstacksize) { /* there was an overflow? */ 74 if (L->stacksize > LUA_MAXSTACK) { /* there was an overflow? */
75 int inuse = (L->top - L->stack); 75 int inuse = (L->top - L->stack);
76 if (inuse + MAXSTACK < L->maxstacksize) /* can `undo' overflow? */ 76 if (inuse + MAXSTACK < LUA_MAXSTACK) /* can `undo' overflow? */
77 luaD_reallocstack(L, L->maxstacksize); 77 luaD_reallocstack(L, LUA_MAXSTACK);
78 } 78 }
79} 79}
80 80
81 81
82void luaD_growstack (lua_State *L, int n) { 82void luaD_growstack (lua_State *L, int n) {
83 if (L->stacksize > L->maxstacksize) { /* overflow while handling overflow? */ 83 if (L->stacksize > LUA_MAXSTACK) { /* overflow while handling overflow? */
84 luaD_breakrun(L, LUA_ERRERR); /* break run without error message */ 84 luaD_breakrun(L, LUA_ERRERR); /* break run without error message */
85 } 85 }
86 else { 86 else {
87 if (n <= L->stacksize && 2*L->stacksize < L->maxstacksize) /* can double? */ 87 if (n <= L->stacksize && 2*L->stacksize < LUA_MAXSTACK) /* can double? */
88 luaD_reallocstack(L, 2*L->stacksize); 88 luaD_reallocstack(L, 2*L->stacksize);
89 else if (L->stacksize+n <= L->maxstacksize) /* no overflow? */ 89 else if (L->stacksize+n <= LUA_MAXSTACK) /* no overflow? */
90 luaD_reallocstack(L, L->maxstacksize); 90 luaD_reallocstack(L, LUA_MAXSTACK);
91 else { 91 else {
92 /* resize to maximum + some extra space to handle error */ 92 /* resize to maximum + some extra space to handle error */
93 luaD_reallocstack(L, L->maxstacksize+4*LUA_MINSTACK); 93 luaD_reallocstack(L, LUA_MAXSTACK+4*LUA_MINSTACK);
94 luaD_error(L, "stack overflow"); 94 luaD_error(L, "stack overflow");
95 } 95 }
96 } 96 }
@@ -428,9 +428,13 @@ LUA_API int lua_loadfile (lua_State *L, const char *filename) {
428 f = fopen(filename, "rb"); /* reopen in binary mode */ 428 f = fopen(filename, "rb"); /* reopen in binary mode */
429 if (f == NULL) return LUA_ERRFILE; /* unable to reopen file */ 429 if (f == NULL) return LUA_ERRFILE; /* unable to reopen file */
430 } 430 }
431 lua_pushliteral(L, "@"); 431 if (filename == NULL)
432 lua_pushstring(L, (filename == NULL) ? "=stdin" : filename); 432 lua_pushstring(L, "=stdin");
433 lua_concat(L, 2); 433 else {
434 lua_pushliteral(L, "@");
435 lua_pushstring(L, filename);
436 lua_concat(L, 2);
437 }
434 nlevel = lua_gettop(L); 438 nlevel = lua_gettop(L);
435 filename = lua_tostring(L, -1); /* filename = `@'..filename */ 439 filename = lua_tostring(L, -1); /* filename = `@'..filename */
436 luaZ_Fopen(&z, f, filename); 440 luaZ_Fopen(&z, f, filename);