mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
fix and move to '/pikafs/xxx' from 'pikafs/xxx'
This commit is contained in:
parent
51bbe08d76
commit
21155bfbb3
@ -8,8 +8,11 @@ int PikaStdData_FILEIO_init(PikaObj* self, char* path, char* mode) {
|
||||
/* already initialized */
|
||||
return 0;
|
||||
}
|
||||
if (strIsStartWith(path, "pikafs/")) {
|
||||
pikafs_FILE* f = pikafs_fopen(path + 7, "rb");
|
||||
if (strIsStartWith(path, "/pikafs/")) {
|
||||
pikafs_FILE* f = pikafs_fopen(path + 8, "rb");
|
||||
if (f == NULL) {
|
||||
return 1;
|
||||
}
|
||||
obj_setInt(self, "pikafs", PIKA_TRUE);
|
||||
obj_setPtr(self, "_f", f);
|
||||
obj_setStr(self, "_mode", mode);
|
||||
|
3
port/linux/.vscode/launch.json
vendored
3
port/linux/.vscode/launch.json
vendored
@ -33,7 +33,8 @@
|
||||
// "--gtest_filter=json.speed"
|
||||
// "--gtest_filter=json.json_issue1"
|
||||
// "--gtest_filter=json.err"
|
||||
"--gtest_filter=builtin.eval"
|
||||
// "--gtest_filter=builtin.eval"
|
||||
"--gtest_filter=stddata.pikafs_open_err"
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
|
3
port/linux/.vscode/settings.json
vendored
3
port/linux/.vscode/settings.json
vendored
@ -133,5 +133,8 @@
|
||||
},
|
||||
"[c]": {
|
||||
"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"
|
||||
},
|
||||
"[jsonc]": {
|
||||
"editor.defaultFormatter": "vscode.json-language-features"
|
||||
}
|
||||
}
|
@ -8,8 +8,11 @@ int PikaStdData_FILEIO_init(PikaObj* self, char* path, char* mode) {
|
||||
/* already initialized */
|
||||
return 0;
|
||||
}
|
||||
if (strIsStartWith(path, "pikafs/")) {
|
||||
pikafs_FILE* f = pikafs_fopen(path + 7, "rb");
|
||||
if (strIsStartWith(path, "/pikafs/")) {
|
||||
pikafs_FILE* f = pikafs_fopen(path + 8, "rb");
|
||||
if (f == NULL) {
|
||||
return 1;
|
||||
}
|
||||
obj_setInt(self, "pikafs", PIKA_TRUE);
|
||||
obj_setPtr(self, "_f", f);
|
||||
obj_setStr(self, "_mode", mode);
|
||||
|
@ -1080,17 +1080,24 @@ PIKA_RES pikaMaker_linkRaw(PikaMaker* self, char* file_path) {
|
||||
*/
|
||||
pikafs_FILE* pikafs_fopen(char* file_name, char* mode) {
|
||||
pikafs_FILE* f = (pikafs_FILE*)pikaMalloc(sizeof(pikafs_FILE));
|
||||
if (NULL == f) {
|
||||
return NULL; // 避免空指针
|
||||
}
|
||||
memset(f, 0, sizeof(pikafs_FILE));
|
||||
extern volatile PikaObj* __pikaMain;
|
||||
uint8_t* library_bytes = obj_getPtr((PikaObj*)__pikaMain, "@libraw");
|
||||
if (NULL == library_bytes) {
|
||||
return NULL;
|
||||
goto __error; // 如果library_bytes为NULL,则跳转到__error
|
||||
}
|
||||
if (PIKA_RES_OK !=
|
||||
_loadModuleDataWithName(library_bytes, file_name, &f->addr, &f->size)) {
|
||||
return NULL;
|
||||
goto __error; // 如果_loadModuleDataWithName的结果不是PIKA_RES_OK,则跳转到__error
|
||||
}
|
||||
return f;
|
||||
|
||||
__error:
|
||||
pikaFree(f, sizeof(pikafs_FILE)); // 释放内存
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pikafs_FILE* pikafs_fopen_pack(char* pack_name, char* file_name) {
|
||||
@ -1156,7 +1163,7 @@ int pikafs_fwrite(void* buf, size_t size, size_t count, pikafs_FILE* file) {
|
||||
* @return 0 if success
|
||||
*/
|
||||
int pikafs_fclose(pikafs_FILE* file) {
|
||||
if (file->need_free){
|
||||
if (file->need_free) {
|
||||
pikaFree(file->addr, file->size);
|
||||
}
|
||||
pikaFree(file, sizeof(pikafs_FILE));
|
||||
|
@ -540,7 +540,7 @@ TEST(stddata, pikafs_open) {
|
||||
/* run */
|
||||
__platform_printf("BEGIN\r\n");
|
||||
obj_run(pikaMain,
|
||||
"f = open('pikafs/widget_config.ini','r')\n"
|
||||
"f = open('/pikafs/widget_config.ini','r')\n"
|
||||
"f.read(8)\n"
|
||||
"f.close()\n");
|
||||
/* collect */
|
||||
@ -551,6 +551,26 @@ TEST(stddata, pikafs_open) {
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(stddata, pikafs_open_err) {
|
||||
/* init */
|
||||
g_PikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
extern unsigned char pikaModules_py_a[];
|
||||
obj_linkLibrary(pikaMain, pikaModules_py_a);
|
||||
/* run */
|
||||
__platform_printf("BEGIN\r\n");
|
||||
obj_run(pikaMain,
|
||||
"f = open('/pikafs/_no_file_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, list_slice_issue) {
|
||||
/* init */
|
||||
g_PikaMemInfo.heapUsedMax = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user