Explorar el Código

fix https://github.com/blueloveTH/pocketpy/issues/51

blueloveTH hace 2 años
padre
commit
dd27071b22
Se han modificado 5 ficheros con 15 adiciones y 10 borrados
  1. 3 3
      src/common.h
  2. 1 1
      src/io.h
  3. 1 1
      src/main.cpp
  4. 7 4
      src/pocketpy.h
  5. 3 1
      src/vm.h

+ 3 - 3
src/common.h

@@ -43,10 +43,10 @@
 #define DEBUG_NO_AUTO_GC			0
 #define DEBUG_GC_STATS				0
 
-#if (defined(__ANDROID__) && __ANDROID_API__ <= 22) || defined(__EMSCRIPTEN__)
-#define PK_ENABLE_FILEIO 			0
+#if (defined(__ANDROID__) && __ANDROID_API__ <= 22)
+#define PK_ENABLE_OS 			0
 #else
-#define PK_ENABLE_FILEIO 			1
+#define PK_ENABLE_OS 			1
 #endif
 
 // This is the maximum number of arguments in a function declaration

+ 1 - 1
src/io.h

@@ -4,7 +4,7 @@
 #include "cffi.h"
 #include "common.h"
 
-#if PK_ENABLE_FILEIO
+#if PK_ENABLE_OS
 
 #include <fstream>
 #include <filesystem>

+ 1 - 1
src/main.cpp

@@ -6,7 +6,7 @@
 #ifndef __EMSCRIPTEN__
 
 int main(int argc, char** argv){
-    pkpy::VM* vm = pkpy_new_vm(true);
+    pkpy::VM* vm = pkpy_new_vm(true, true);
     vm->bind_builtin_func<0>("input", [](pkpy::VM* vm, pkpy::ArgsView args){
         return VAR(pkpy::getline());
     });

+ 7 - 4
src/pocketpy.h

@@ -828,12 +828,15 @@ inline void VM::post_init(){
     add_module_math(this);
     add_module_re(this);
     add_module_dis(this);
-    add_module_io(this);
-    add_module_os(this);
     add_module_c(this);
     add_module_gc(this);
     add_module_random(this);
 
+    if(enable_os){
+        add_module_io(this);
+        add_module_os(this);
+    }
+
     for(const char* name: {"this", "functools", "collections", "heapq", "bisect"}){
         _lazy_modules[name] = kPythonLibs[name];
     }
@@ -970,8 +973,8 @@ extern "C" {
 
     __EXPORT
     /// Create a virtual machine.
-    pkpy::VM* pkpy_new_vm(bool use_stdio){
-        return PKPY_ALLOCATE(pkpy::VM, use_stdio);
+    pkpy::VM* pkpy_new_vm(bool use_stdio, bool enable_os){
+        return PKPY_ALLOCATE(pkpy::VM, use_stdio, enable_os);
     }
 
     __EXPORT

+ 3 - 1
src/vm.h

@@ -104,7 +104,9 @@ public:
     Type tp_slice, tp_range, tp_module;
     Type tp_super, tp_exception, tp_bytes;
 
-    VM(bool use_stdio) : heap(this){
+    const bool enable_os;
+
+    VM(bool use_stdio, bool enable_os) : heap(this), enable_os(enable_os) {
         this->vm = this;
         this->_stdout = use_stdio ? &std::cout : &_stdout_buffer;
         this->_stderr = use_stdio ? &std::cerr : &_stderr_buffer;