From 13328c5bee9b847317313491c3eb9f6f66766de7 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 22 May 2017 23:26:44 +1000 Subject: Add luaD_inctop calls where appropriate --- src/ldo.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/ldo.js') diff --git a/src/ldo.js b/src/ldo.js index 83f26cf..fbef68f 100644 --- a/src/ldo.js +++ b/src/ldo.js @@ -89,6 +89,11 @@ const luaD_shrinkstack = function(L) { luaD_reallocstack(L, goodsize); }; +const luaD_inctop = function(L) { + luaD_checkstack(L, 1); + L.top++; +}; + /* ** Prepares a function call: checks the stack, creates a new CallInfo ** entry, fills in the relevant information, calls hook if needed. @@ -653,6 +658,7 @@ 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_inctop = luaD_inctop; module.exports.luaD_pcall = luaD_pcall; module.exports.luaD_poscall = luaD_poscall; module.exports.luaD_precall = luaD_precall; -- cgit v1.2.3-54-g00ecf From f7bb8409d6c57b5e9319f4f48d7d02f216b4cc32 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Tue, 23 May 2017 00:05:13 +1000 Subject: src/ldo.js: free CallInfo to recover from (lua) stack overflow --- src/ldo.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/ldo.js') diff --git a/src/ldo.js b/src/ldo.js index fbef68f..cda1274 100644 --- a/src/ldo.js +++ b/src/ldo.js @@ -85,6 +85,10 @@ const luaD_shrinkstack = function(L) { let goodsize = inuse + Math.floor(inuse / 8) + 2*lstate.EXTRA_STACK; if (goodsize > luaconf.LUAI_MAXSTACK) goodsize = luaconf.LUAI_MAXSTACK; /* respect stack limit */ + if (L.stack.length > luaconf.LUAI_MAXSTACK) /* had been handling stack overflow? */ + lstate.luaE_freeCI(L); /* free all CIs (list grew because of an error) */ + /* if thread is currently not handling a stack overflow and its + good size is smaller than current size, shrink its stack */ if (inuse <= (luaconf.LUAI_MAXSTACK - lstate.EXTRA_STACK) && goodsize < L.stack.length) luaD_reallocstack(L, goodsize); }; -- cgit v1.2.3-54-g00ecf From f6b260d2b97c40f360136d0c1320d8f6468f7e87 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Tue, 23 May 2017 00:05:31 +1000 Subject: src/ldo.js: luaG_runerror takes lua strings --- src/ldo.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ldo.js') diff --git a/src/ldo.js b/src/ldo.js index cda1274..701a211 100644 --- a/src/ldo.js +++ b/src/ldo.js @@ -59,7 +59,7 @@ const luaD_growstack = function(L, n) { if (newsize < needed) newsize = needed; if (newsize > luaconf.LUAI_MAXSTACK) { /* stack overflow? */ luaD_reallocstack(L, ERRORSTACKSIZE); - ldebug.luaG_runerror(L, "stack overflow"); + ldebug.luaG_runerror(L, defs.to_luastring("stack overflow", true)); } else luaD_reallocstack(L, newsize); @@ -281,7 +281,7 @@ const tryfuncTM = function(L, off, func) { */ const stackerror = function(L) { if (L.nCcalls === llimit.LUAI_MAXCCALLS) - ldebug.luaG_runerror(L, "JS stack overflow"); + ldebug.luaG_runerror(L, defs.to_luastring("JS stack overflow", true)); else if (L.nCcalls >= llimit.LUAI_MAXCCALLS + (llimit.LUAI_MAXCCALLS >> 3)) luaD_throw(L, TS.LUA_ERRERR); /* error while handing stack error */ }; -- cgit v1.2.3-54-g00ecf