ソースを参照

change _Func to &

blueloveTH 3 年 前
コミット
7ecb8476f9
2 ファイル変更23 行追加1 行削除
  1. 22 0
      src/main.cpp
  2. 1 1
      src/vm.h

+ 22 - 0
src/main.cpp

@@ -4,6 +4,7 @@
 #include "pocketpy.h"
 #include "pocketpy.h"
 
 
 //#define PK_DEBUG_TIME
 //#define PK_DEBUG_TIME
+//#define PK_DEBUG_STACK
 
 
 struct Timer{
 struct Timer{
     const char* title;
     const char* title;
@@ -49,7 +50,28 @@ extern "C" {
 
 
 #else
 #else
 
 
+
+#ifdef PK_DEBUG_STACK
+#include <sys/resource.h>
+
+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){
 int main(int argc, char** argv){
+#ifdef PK_DEBUG_STACK
+    setStackSize(1);
+#endif
+
     if(argc == 1){
     if(argc == 1){
         REPL repl(newVM());
         REPL repl(newVM());
         while(true){
         while(true){

+ 1 - 1
src/vm.h

@@ -366,7 +366,7 @@ public:
             auto f = std::get<_CppFunc>(callable->_native);
             auto f = std::get<_CppFunc>(callable->_native);
             return f(this, args);
             return f(this, args);
         } else if(callable->isType(_tp_function)){
         } else if(callable->isType(_tp_function)){
-            _Func fn = PyFunction_AS_C(callable);
+            const _Func& fn = PyFunction_AS_C(callable);
             PyVarDict locals;
             PyVarDict locals;
             int i = 0;
             int i = 0;
             for(const auto& name : fn.args){
             for(const auto& name : fn.args){