diff --git a/src/main.cpp b/src/main.cpp index fcca6ef6..2b9d9a7d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,6 +4,7 @@ #include "pocketpy.h" //#define PK_DEBUG_TIME +//#define PK_DEBUG_STACK struct Timer{ const char* title; @@ -49,7 +50,28 @@ extern "C" { #else + +#ifdef PK_DEBUG_STACK +#include + +void setStackSize(_Float mb){ + const rlim_t kStackSize = (_Int)(mb * 1024 * 1024); + struct rlimit rl; + int result; + result = getrlimit(RLIMIT_STACK, &rl); + rl.rlim_cur = kStackSize; + result = setrlimit(RLIMIT_STACK, &rl); + if (result != 0){ + std::cerr << "setrlimit returned result = " << result << std::endl; + } +} +#endif + int main(int argc, char** argv){ +#ifdef PK_DEBUG_STACK + setStackSize(1); +#endif + if(argc == 1){ REPL repl(newVM()); while(true){ diff --git a/src/vm.h b/src/vm.h index be753b1e..e99c7c0c 100644 --- a/src/vm.h +++ b/src/vm.h @@ -366,7 +366,7 @@ public: auto f = std::get<_CppFunc>(callable->_native); return f(this, args); } else if(callable->isType(_tp_function)){ - _Func fn = PyFunction_AS_C(callable); + const _Func& fn = PyFunction_AS_C(callable); PyVarDict locals; int i = 0; for(const auto& name : fn.args){