fix linklibrary open pikafs issue

This commit is contained in:
lyon1998 2024-02-25 00:24:31 +08:00
parent d5796cd56e
commit e3f1c3b26e
5 changed files with 25 additions and 5 deletions

View File

@ -23,7 +23,8 @@
// "--gtest_filter=except.try_import_except" // "--gtest_filter=except.try_import_except"
// "--gtest_filter=vm.test_cmodule_import_as" // "--gtest_filter=vm.test_cmodule_import_as"
// "--gtest_filter=vm.subsrc_import" // "--gtest_filter=vm.subsrc_import"
"--gtest_filter=event.event_thread" // "--gtest_filter=event.event_thread"
"--gtest_filter=stddata.pikafs_open"
], ],
"stopAtEntry": false, "stopAtEntry": false,
"cwd": "${workspaceFolder}", "cwd": "${workspaceFolder}",

View File

@ -550,6 +550,26 @@ TEST(stddata, pikafs_open) {
EXPECT_EQ(pikaMemNow(), 0); 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) { TEST(stddata, pikafs_open_err) {
/* init */ /* init */
g_PikaMemInfo.heapUsedMax = 0; g_PikaMemInfo.heapUsedMax = 0;

View File

@ -704,6 +704,7 @@ int LibObj_loadLibrary(LibObj* self, uint8_t* library_bytes) {
&bytecode_addr, &bytecode_size); &bytecode_addr, &bytecode_size);
LibObj_dynamicLink(self, module_name, bytecode_addr); LibObj_dynamicLink(self, module_name, bytecode_addr);
} }
obj_setPtr(self, "@libraw", library_bytes);
return PIKA_RES_OK; return PIKA_RES_OK;
} }
@ -1428,8 +1429,7 @@ pikafs_FILE* pikafs_fopen(char* file_name, char* mode) {
return NULL; return NULL;
} }
memset(f, 0, sizeof(pikafs_FILE)); memset(f, 0, sizeof(pikafs_FILE));
extern volatile PikaObj* __pikaMain; uint8_t* library_bytes = obj_getPtr(pika_getLibObj(), "@libraw");
uint8_t* library_bytes = obj_getPtr((PikaObj*)__pikaMain, "@libraw");
if (NULL == library_bytes) { if (NULL == library_bytes) {
goto __error; goto __error;
} }

View File

@ -2649,7 +2649,6 @@ PikaObj* obj_linkLibrary(PikaObj* self, uint8_t* library_bytes) {
obj_newMetaObj(self, "@lib", New_LibObj); obj_newMetaObj(self, "@lib", New_LibObj);
LibObj* lib = obj_getObj(self, "@lib"); LibObj* lib = obj_getObj(self, "@lib");
LibObj_loadLibrary(lib, library_bytes); LibObj_loadLibrary(lib, library_bytes);
obj_setPtr(self, "@libraw", library_bytes);
return self; return self;
} }

View File

@ -2,4 +2,4 @@
#define PIKA_VERSION_MINOR 13 #define PIKA_VERSION_MINOR 13
#define PIKA_VERSION_MICRO 2 #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"