From 054a2a6873fd382bb2efa56b3b3aa7f2dd17ee67 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Fri, 11 Nov 2022 18:57:21 +0800 Subject: [PATCH] add RecursionError --- src/vm.h | 9 ++++++++- web/index.js | 1 - 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/vm.h b/src/vm.h index 1bb9c706..5529cf96 100644 --- a/src/vm.h +++ b/src/vm.h @@ -431,6 +431,11 @@ public: PyVar _exec(const _Code& code, PyVar _module, PyVarDict& locals){ if(code == nullptr) UNREACHABLE(); + + if(callstack.size() > 1000){ + throw RuntimeError("RecursionError", "maximum recursion depth exceeded", _cleanErrorAndGetSnapshots()); + } + Frame* frame = new Frame( code.get(), _module, @@ -663,7 +668,9 @@ private: std::stack<_Str> _cleanErrorAndGetSnapshots(){ std::stack<_Str> snapshots; while (!callstack.empty()){ - snapshots.push(callstack.top()->errorSnapshot()); + if(snapshots.size() < 10){ + snapshots.push(callstack.top()->errorSnapshot()); + } callstack.pop(); } return snapshots; diff --git a/web/index.js b/web/index.js index c2dd7079..6e4198c6 100644 --- a/web/index.js +++ b/web/index.js @@ -17,7 +17,6 @@ var Module = { }, 'onAbort': function(text) { stopped = true; - term.write("Aborted\r\n"); }, };