diff --git a/port/linux/.vscode/launch.json b/port/linux/.vscode/launch.json index 204cab644..139584674 100644 --- a/port/linux/.vscode/launch.json +++ b/port/linux/.vscode/launch.json @@ -23,7 +23,8 @@ // "--gtest_filter=except.try_import_except" // "--gtest_filter=vm.test_cmodule_import_as" // "--gtest_filter=vm.subsrc_import" - "--gtest_filter=event.event_thread" + // "--gtest_filter=event.event_thread" + "--gtest_filter=stddata.pikafs_open" ], "stopAtEntry": false, "cwd": "${workspaceFolder}", diff --git a/port/linux/test/stddata-test.cpp b/port/linux/test/stddata-test.cpp index a66ad225c..567b59f46 100644 --- a/port/linux/test/stddata-test.cpp +++ b/port/linux/test/stddata-test.cpp @@ -550,6 +550,26 @@ TEST(stddata, pikafs_open) { EXPECT_EQ(pikaMemNow(), 0); } +TEST(stddata, pikafs_open_libfile) { + /* init */ + g_PikaMemInfo.heapUsedMax = 0; + PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain); + obj_linkLibraryFile(pikaMain, + "package/pikascript/pikascript-api/pikaModules.py.a"); + /* run */ + __platform_printf("BEGIN\r\n"); + obj_run(pikaMain, + "f = open('/pikafs/widget_config.ini','r')\n" + "f.read(8)\n" + "f.close()\n"); + /* collect */ + /* assert */ + EXPECT_STREQ(log_buff[0], "'[端口]'\r\n"); + /* deinit */ + obj_deinit(pikaMain); + EXPECT_EQ(pikaMemNow(), 0); +} + TEST(stddata, pikafs_open_err) { /* init */ g_PikaMemInfo.heapUsedMax = 0; diff --git a/src/PikaCompiler.c b/src/PikaCompiler.c index a2473d3bb..d050e0215 100644 --- a/src/PikaCompiler.c +++ b/src/PikaCompiler.c @@ -704,6 +704,7 @@ int LibObj_loadLibrary(LibObj* self, uint8_t* library_bytes) { &bytecode_addr, &bytecode_size); LibObj_dynamicLink(self, module_name, bytecode_addr); } + obj_setPtr(self, "@libraw", library_bytes); return PIKA_RES_OK; } @@ -1428,8 +1429,7 @@ pikafs_FILE* pikafs_fopen(char* file_name, char* mode) { return NULL; } memset(f, 0, sizeof(pikafs_FILE)); - extern volatile PikaObj* __pikaMain; - uint8_t* library_bytes = obj_getPtr((PikaObj*)__pikaMain, "@libraw"); + uint8_t* library_bytes = obj_getPtr(pika_getLibObj(), "@libraw"); if (NULL == library_bytes) { goto __error; } diff --git a/src/PikaObj.c b/src/PikaObj.c index c25054c26..e0273421e 100644 --- a/src/PikaObj.c +++ b/src/PikaObj.c @@ -2649,7 +2649,6 @@ PikaObj* obj_linkLibrary(PikaObj* self, uint8_t* library_bytes) { obj_newMetaObj(self, "@lib", New_LibObj); LibObj* lib = obj_getObj(self, "@lib"); LibObj_loadLibrary(lib, library_bytes); - obj_setPtr(self, "@libraw", library_bytes); return self; } diff --git a/src/PikaVersion.h b/src/PikaVersion.h index f22143b49..b04ee6465 100644 --- a/src/PikaVersion.h +++ b/src/PikaVersion.h @@ -2,4 +2,4 @@ #define PIKA_VERSION_MINOR 13 #define PIKA_VERSION_MICRO 2 -#define PIKA_EDIT_TIME "2024/02/19 23:56:25" +#define PIKA_EDIT_TIME "2024/02/25 00:24:24"