blueloveTH 2 yıl önce
ebeveyn
işleme
be273f55c9
3 değiştirilmiş dosya ile 8 ekleme ve 7 silme
  1. 2 1
      src/ceval.h
  2. 5 5
      src/io.h
  3. 1 1
      src/vm.h

+ 2 - 1
src/ceval.h

@@ -442,7 +442,8 @@ __NEXT_STEP:;
             auto it = _lazy_modules.find(name);
             if(it == _lazy_modules.end()){
                 bool ok = false;
-                source = _read_file_cwd(fmt(name, ".py"), &ok);
+                Bytes b = _read_file_cwd(fmt(name, ".py"), &ok);
+                source = Str(b._data);
                 if(!ok) _error("ImportError", fmt("module ", name.escape(), " not found"));
             }else{
                 source = it->second;

+ 5 - 5
src/io.h

@@ -11,18 +11,18 @@
 
 namespace pkpy{
 
-inline Str _read_file_cwd(const Str& name, bool* ok){
+inline Bytes _read_file_cwd(const Str& name, bool* ok){
     std::filesystem::path path(name.sv());
     bool exists = std::filesystem::exists(path);
     if(!exists){
         *ok = false;
-        return Str();
+        return Bytes();
     }
     std::ifstream ifs(path);
     std::string buffer((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
     ifs.close();
     *ok = true;
-    return Str(std::move(buffer));
+    return Bytes({std::move(buffer)});
 }
 
 struct FileIO {
@@ -175,9 +175,9 @@ namespace pkpy{
 inline void add_module_io(VM* vm){}
 inline void add_module_os(VM* vm){}
 
-inline Str _read_file_cwd(const Str& name, bool* ok){
+inline Bytes _read_file_cwd(const Str& name, bool* ok){
     *ok = false;
-    return Str();
+    return Bytes();
 }
 
 } // namespace pkpy

+ 1 - 1
src/vm.h

@@ -24,7 +24,7 @@ namespace pkpy{
 #define POPX()            (s_data.popx())
 #define STACK_VIEW(n)     (s_data.view(n))
 
-Str _read_file_cwd(const Str& name, bool* ok);
+Bytes _read_file_cwd(const Str& name, bool* ok);
 
 #define DEF_NATIVE_2(ctype, ptype)                                      \
     template<> inline ctype py_cast<ctype>(VM* vm, PyObject* obj) {     \