summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-22 17:48:16 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-22 18:46:26 +1000
commit20efa5c3b00e3a82ab135ec4a1f5d0563912aefe (patch)
tree628fa40d294e85e3e3f4d866fa49f6bd45d963ef /src
parent9294302fc069e0b8d893521fa552b5ed66601024 (diff)
downloadfengari-20efa5c3b00e3a82ab135ec4a1f5d0563912aefe.tar.gz
fengari-20efa5c3b00e3a82ab135ec4a1f5d0563912aefe.tar.bz2
fengari-20efa5c3b00e3a82ab135ec4a1f5d0563912aefe.zip
Add luaD_checkstack calls
Diffstat (limited to 'src')
-rw-r--r--src/ldo.js12
-rw-r--r--src/lobject.js2
-rw-r--r--src/lvm.js1
3 files changed, 13 insertions, 2 deletions
diff --git a/src/ldo.js b/src/ldo.js
index 1036ce5..5243f1f 100644
--- a/src/ldo.js
+++ b/src/ldo.js
@@ -63,6 +63,11 @@ const luaD_growstack = function(L, n) {
}
};
+const luaD_checkstack = function(L, n) {
+ if (L.stack.length - L.top <= n)
+ luaD_growstack(L, n);
+};
+
/*
** Prepares a function call: checks the stack, creates a new CallInfo
** entry, fills in the relevant information, calls hook if needed.
@@ -78,11 +83,13 @@ const luaD_precall = function(L, off, nresults) {
case CT.LUA_TLCF: {
let f = func.type === CT.LUA_TCCL ? func.value.f : func.value;
+ luaD_checkstack(L, defs.LUA_MINSTACK);
let ci = lstate.luaE_extendCI(L);
ci.funcOff = off;
ci.nresults = nresults;
ci.func = func;
ci.top = L.top + defs.LUA_MINSTACK;
+ assert(ci.top <= L.stack.length);
ci.callstatus = 0;
if (L.hookmask & defs.LUA_MASKCALL)
luaD_hook(L, defs.LUA_HOOKCALL, -1);
@@ -96,11 +103,11 @@ const luaD_precall = function(L, off, nresults) {
return true;
}
case CT.LUA_TLCL: {
+ let base;
let p = func.value.p;
let n = L.top - off - 1;
let fsize = p.maxstacksize;
- let base;
-
+ luaD_checkstack(L, fsize);
if (p.is_vararg) {
base = adjust_varargs(L, p, n);
} else {
@@ -619,6 +626,7 @@ module.exports.SParser = SParser;
module.exports.adjust_varargs = adjust_varargs;
module.exports.luaD_call = luaD_call;
module.exports.luaD_callnoyield = luaD_callnoyield;
+module.exports.luaD_checkstack = luaD_checkstack;
module.exports.luaD_growstack = luaD_growstack;
module.exports.luaD_hook = luaD_hook;
module.exports.luaD_pcall = luaD_pcall;
diff --git a/src/lobject.js b/src/lobject.js
index 79496d5..41c3a84 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -6,6 +6,7 @@ const assert = require('assert');
const defs = require('./defs.js');
const ljstype = require('./ljstype.js');
const ldebug = require('./ldebug.js');
+const ldo = require('./ldo.js');
const lstring = require('./lstring.js');
const luaconf = require('./luaconf.js');
const lvm = require('./lvm.js');
@@ -492,6 +493,7 @@ const luaO_pushvfstring = function(L, fmt, argp) {
n += 2;
i = e + 2;
}
+ ldo.luaD_checkstack(L, 1);
pushstr(L, fmt.slice(i));
if (n > 0) lvm.luaV_concat(L, n+1);
return L.stack[L.top-1].svalue();
diff --git a/src/lvm.js b/src/lvm.js
index 6e1012c..6711bfa 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -645,6 +645,7 @@ const luaV_execute = function(L) {
if (b < 0) {
b = n; /* get all var. arguments */
+ ldo.luaD_checkstack(L, n);
L.top = ra + n;
}