diff --git a/src/ceval.h b/src/ceval.h index d28e8f5f..7dfd992d 100644 --- a/src/ceval.h +++ b/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; diff --git a/src/io.h b/src/io.h index d1b3ed96..a5101fa7 100644 --- a/src/io.h +++ b/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(ifs)), (std::istreambuf_iterator())); 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 diff --git a/src/vm.h b/src/vm.h index a79499bf..b5119baa 100644 --- a/src/vm.h +++ b/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(VM* vm, PyObject* obj) { \