diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2016-09-08 13:36:26 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2016-09-08 13:36:26 -0300 |
commit | 7fe1a4cff3998bf019144924f39aec3f76a5cf32 (patch) | |
tree | 3f1c3984ae7093b3cdc3659a6db3d6565507f159 | |
parent | dbb6f11e8ee1eaa496215da5c04af80ec19b4df1 (diff) | |
download | lua-github-7fe1a4cff3998bf019144924f39aec3f76a5cf32.tar.gz |
cleaner and more correct code for 'luaD_shrinkstack' (the old
test "inuse <= LUAI_MAXSTACK" for stack overflow is not correct,
as the real maximum usable size is "LUAI_MAXSTACK - EXTRA_STACK")
-rw-r--r-- | ldo.c | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -221,14 +221,17 @@ static int stackinuse (lua_State *L) { void luaD_shrinkstack (lua_State *L) { int inuse = stackinuse(L); int goodsize = inuse + (inuse / 8) + 2*EXTRA_STACK; - if (goodsize > LUAI_MAXSTACK) goodsize = LUAI_MAXSTACK; - if (L->stacksize > LUAI_MAXSTACK) /* was handling stack overflow? */ + if (goodsize > LUAI_MAXSTACK) + goodsize = LUAI_MAXSTACK; /* respect stack limit */ + if (L->stacksize > LUAI_MAXSTACK) /* had been handling stack overflow? */ luaE_freeCI(L); /* free all CIs (list grew because of an error) */ else luaE_shrinkCI(L); /* shrink list */ - if (inuse <= LUAI_MAXSTACK && /* not handling stack overflow? */ - goodsize < L->stacksize) /* trying to shrink? */ - luaD_reallocstack(L, goodsize); /* shrink it */ + /* if thread is currently not handling a stack overflow and its + good size is smaller than current size, shrink its stack */ + if (inuse <= (LUAI_MAXSTACK - EXTRA_STACK) && + goodsize < L->stacksize) + luaD_reallocstack(L, goodsize); else condmovestack(L,,); /* don't change stack (change only for debugging) */ } |