diff options
author | daurnimator <quae@daurnimator.com> | 2017-05-22 17:04:46 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-05-22 18:46:23 +1000 |
commit | 9294302fc069e0b8d893521fa552b5ed66601024 (patch) | |
tree | 8ef6f03a985fd7f7a672757039a35b266e978b7c /src/lapi.js | |
parent | 6e413992b24c760b149a8abf580811cc1d057d19 (diff) | |
download | fengari-9294302fc069e0b8d893521fa552b5ed66601024.tar.gz fengari-9294302fc069e0b8d893521fa552b5ed66601024.tar.bz2 fengari-9294302fc069e0b8d893521fa552b5ed66601024.zip |
Fix lua_checkstack to check against LUAI_MAXSTACK. Adds luaD_growstack and luaD_reallocstack
Diffstat (limited to 'src/lapi.js')
-rw-r--r-- | src/lapi.js | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/lapi.js b/src/lapi.js index cea0568..79c666c 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.length - 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 */ |