diff options
author | Benoit Giannangeli <giann008@gmail.com> | 2017-05-22 10:51:55 +0200 |
---|---|---|
committer | Benoit Giannangeli <giann008@gmail.com> | 2017-05-22 10:51:55 +0200 |
commit | 25e2110a5eac0a2e6c7b4d502ffbd53fc61af301 (patch) | |
tree | 7e0ccc2dd0a03b36fc2ecee1887765b24bf3ac6a /src/lapi.js | |
parent | 18271b4169631ce8f10c10c0776d9bfb40bd691f (diff) | |
parent | 5b764695bdc939784fd448fe6ba16ed3a9f44b19 (diff) | |
download | fengari-25e2110a5eac0a2e6c7b4d502ffbd53fc61af301.tar.gz fengari-25e2110a5eac0a2e6c7b4d502ffbd53fc61af301.tar.bz2 fengari-25e2110a5eac0a2e6c7b4d502ffbd53fc61af301.zip |
Merge remote-tracking branch 'daurnimator/stack'
Diffstat (limited to 'src/lapi.js')
-rw-r--r-- | src/lapi.js | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/lapi.js b/src/lapi.js index cea0568..ca5a8a0 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -91,8 +91,20 @@ const index2addr_ = function(L, idx) { }; const lua_checkstack = function(L, n) { + let res; let ci = L.ci; - let res = L.stack.length < luaconf.LUAI_MAXSTACK; + assert(n >= 0, "negative 'n'"); + if (L.stack_last - L.top > n) /* stack large enough? */ + res = true; + else { /* no; need to grow stack */ + let inuse = L.top + lstate.EXTRA_STACK; + if (inuse > luaconf.LUAI_MAXSTACK - n) /* can grow without overflow? */ + res = false; /* no */ + else { /* try to grow stack */ + ldo.luaD_growstack(L, n); + res = true; + } + } if (res && ci.top < L.top + n) ci.top = L.top + n; /* adjust frame top */ @@ -140,6 +152,7 @@ const lua_pushvalue = function(L, idx) { const lua_settop = function(L, idx) { let func = L.ci.funcOff; if (idx >= 0) { + assert(idx <= L.stack_last - (func + 1), "new top too large"); while (L.top < func + 1 + idx) L.stack[L.top++] = new TValue(CT.LUA_TNIL, null); L.top = func + 1 + idx; |