From 059096a7b11084366d5fc89dac6a9be3b11828c5 Mon Sep 17 00:00:00 2001 From: lyon Date: Mon, 25 Apr 2022 15:01:58 +0800 Subject: [PATCH] divide POINTER and REF_OBJECT OK --- package/PikaStdLib/PikaStdData_Dict.c | 3 ++- package/PikaStdLib/PikaStdLib_SysObj.c | 8 +++---- .../PikaStdLib/PikaStdData_Dict.c | 3 ++- .../PikaStdLib/PikaStdLib_SysObj.c | 8 +++---- .../pikascript-lib/ctypes/ctypes_utils.c | 2 +- port/linux/test/object-test.cpp | 2 +- src/PikaObj.c | 21 ++++++++++--------- src/PikaObj.h | 1 + 8 files changed, 26 insertions(+), 22 deletions(-) diff --git a/package/PikaStdLib/PikaStdData_Dict.c b/package/PikaStdLib/PikaStdData_Dict.c index ff4ef751f..86000aa75 100644 --- a/package/PikaStdLib/PikaStdData_Dict.c +++ b/package/PikaStdLib/PikaStdData_Dict.c @@ -30,7 +30,8 @@ Arg* PikaStdData_Dict___next__(PikaObj* self) { int __iter_i = args_getInt(self->list, "__iter_i"); PikaObj* pyload = obj_getObj(self, "pyload", 0); Arg* res = arg_copy(args_getArg_index(pyload->list, __iter_i)); - if (ARG_TYPE_REF_OBJECT == arg_getType(res)) { + /* skip pointer */ + if (ARG_TYPE_POINTER == arg_getType(res)) { arg_deinit(res); return arg_setNull(NULL); } diff --git a/package/PikaStdLib/PikaStdLib_SysObj.c b/package/PikaStdLib/PikaStdLib_SysObj.c index da1c8bb7d..95a5dad0e 100644 --- a/package/PikaStdLib/PikaStdLib_SysObj.c +++ b/package/PikaStdLib/PikaStdLib_SysObj.c @@ -217,9 +217,9 @@ int PikaStdLib_SysObj_len(PikaObj* self, Arg* arg) { return -1; } -Arg* PikaStdLib_SysObj_list(PikaObj *self){ +Arg* PikaStdLib_SysObj_list(PikaObj* self) { #if PIKA_BUILTIN_LIST_ENABLE - PikaObj *New_PikaStdData_List(Args *args); + PikaObj* New_PikaStdData_List(Args * args); return obj_newObjInPackage(New_PikaStdData_List); #endif obj_setErrorCode(self, 1); @@ -227,9 +227,9 @@ Arg* PikaStdLib_SysObj_list(PikaObj *self){ return arg_setNull(NULL); } -Arg* PikaStdLib_SysObj_dict(PikaObj *self){ +Arg* PikaStdLib_SysObj_dict(PikaObj* self) { #if PIKA_BUILTIN_DICT_ENABLE - PikaObj *New_PikaStdData_Dict(Args *args); + PikaObj* New_PikaStdData_Dict(Args * args); return obj_newObjInPackage(New_PikaStdData_Dict); #endif obj_setErrorCode(self, 1); diff --git a/port/linux/package/pikascript/pikascript-lib/PikaStdLib/PikaStdData_Dict.c b/port/linux/package/pikascript/pikascript-lib/PikaStdLib/PikaStdData_Dict.c index ff4ef751f..86000aa75 100644 --- a/port/linux/package/pikascript/pikascript-lib/PikaStdLib/PikaStdData_Dict.c +++ b/port/linux/package/pikascript/pikascript-lib/PikaStdLib/PikaStdData_Dict.c @@ -30,7 +30,8 @@ Arg* PikaStdData_Dict___next__(PikaObj* self) { int __iter_i = args_getInt(self->list, "__iter_i"); PikaObj* pyload = obj_getObj(self, "pyload", 0); Arg* res = arg_copy(args_getArg_index(pyload->list, __iter_i)); - if (ARG_TYPE_REF_OBJECT == arg_getType(res)) { + /* skip pointer */ + if (ARG_TYPE_POINTER == arg_getType(res)) { arg_deinit(res); return arg_setNull(NULL); } diff --git a/port/linux/package/pikascript/pikascript-lib/PikaStdLib/PikaStdLib_SysObj.c b/port/linux/package/pikascript/pikascript-lib/PikaStdLib/PikaStdLib_SysObj.c index da1c8bb7d..95a5dad0e 100644 --- a/port/linux/package/pikascript/pikascript-lib/PikaStdLib/PikaStdLib_SysObj.c +++ b/port/linux/package/pikascript/pikascript-lib/PikaStdLib/PikaStdLib_SysObj.c @@ -217,9 +217,9 @@ int PikaStdLib_SysObj_len(PikaObj* self, Arg* arg) { return -1; } -Arg* PikaStdLib_SysObj_list(PikaObj *self){ +Arg* PikaStdLib_SysObj_list(PikaObj* self) { #if PIKA_BUILTIN_LIST_ENABLE - PikaObj *New_PikaStdData_List(Args *args); + PikaObj* New_PikaStdData_List(Args * args); return obj_newObjInPackage(New_PikaStdData_List); #endif obj_setErrorCode(self, 1); @@ -227,9 +227,9 @@ Arg* PikaStdLib_SysObj_list(PikaObj *self){ return arg_setNull(NULL); } -Arg* PikaStdLib_SysObj_dict(PikaObj *self){ +Arg* PikaStdLib_SysObj_dict(PikaObj* self) { #if PIKA_BUILTIN_DICT_ENABLE - PikaObj *New_PikaStdData_Dict(Args *args); + PikaObj* New_PikaStdData_Dict(Args * args); return obj_newObjInPackage(New_PikaStdData_Dict); #endif obj_setErrorCode(self, 1); diff --git a/port/linux/package/pikascript/pikascript-lib/ctypes/ctypes_utils.c b/port/linux/package/pikascript/pikascript-lib/ctypes/ctypes_utils.c index d16dfac51..60440af3b 100644 --- a/port/linux/package/pikascript/pikascript-lib/ctypes/ctypes_utils.c +++ b/port/linux/package/pikascript/pikascript-lib/ctypes/ctypes_utils.c @@ -13,7 +13,7 @@ void ctypesUtils_setFloat(PikaObj* self, float val) { } void ctypesUtils_setPtr(PikaObj* self, void* ptr) { - obj_setRefObject(self, "value", ptr); + obj_setPtr(self, "value", ptr); } int ctypesUtils_getInt(PikaObj* self) { diff --git a/port/linux/test/object-test.cpp b/port/linux/test/object-test.cpp index c41a75345..954696a26 100644 --- a/port/linux/test/object-test.cpp +++ b/port/linux/test/object-test.cpp @@ -144,7 +144,7 @@ TEST(object_test, test8) { TEST(object_test, test9) { PikaObj* sys = newRootObj((char*)"sys", New_PikaStdLib_SysObj); obj_run(sys, (char*)"ls()"); - obj_setRefObject(sys, (char*)"baseClass", (void*)New_TinyObj); + obj_setPtr(sys, (char*)"baseClass", (void*)New_TinyObj); obj_run(sys, (char*)"ls()"); obj_deinit(sys); EXPECT_EQ(pikaMemNow(), 0); diff --git a/src/PikaObj.c b/src/PikaObj.c index 7a6b6e295..d7edda620 100644 --- a/src/PikaObj.c +++ b/src/PikaObj.c @@ -144,6 +144,16 @@ int32_t obj_setInt(PikaObj* self, char* argPath, int64_t val) { return 0; } +int32_t obj_setPtr(PikaObj* self, char* argPath, void* pointer) { + PikaObj* obj = obj_getObj(self, argPath, 1); + if (NULL == obj) { + return 1; + } + char* name = strPointToLastToken(argPath, '.'); + args_setPtr(obj->list, name, pointer); + return 0; +} + int32_t obj_setRefObject(PikaObj* self, char* argPath, void* pointer) { PikaObj* obj = obj_getObj(self, argPath, 1); if (NULL == obj) { @@ -300,15 +310,6 @@ int32_t obj_load(PikaObj* self, Args* args, char* name) { return 0; } -int32_t obj_addOther(PikaObj* self, char* subObjectName, void* new_ObjectFun) { - Args initArgs = {0}; - void* (*new_Object)(Args * initArgs) = (void* (*)(Args*))new_ObjectFun; - void* subObject = new_Object(&initArgs); - obj_setRefObject(self, subObjectName, subObject); - args_deinit(&initArgs); - return 0; -} - int32_t obj_freeObj(PikaObj* self, char* objPath) { PikaObj* obj = obj_getPtr(self, objPath); obj_deinit(obj); @@ -327,7 +328,7 @@ PikaObj* obj_getClassObjByNewFun(PikaObj* context, NewFun newClassFun) { Args* initArgs = New_args(NULL); PikaObj* thisClass = newClassFun(initArgs); - obj_setRefObject(thisClass, "_clsptr", (void*)newClassFun); + obj_setPtr(thisClass, "_clsptr", (void*)newClassFun); args_deinit(initArgs); return thisClass; } diff --git a/src/PikaObj.h b/src/PikaObj.h index 64cc2482e..b4d15c83a 100644 --- a/src/PikaObj.h +++ b/src/PikaObj.h @@ -104,6 +104,7 @@ int32_t obj_disable(PikaObj* self); // arg type operations int32_t obj_setInt(PikaObj* self, char* argPath, int64_t val); int32_t obj_setRefObject(PikaObj* self, char* argPath, void* pointer); +int32_t obj_setPtr(PikaObj* self, char* argPath, void* pointer); int32_t obj_setFloat(PikaObj* self, char* argPath, float value); int32_t obj_setStr(PikaObj* self, char* argPath, char* str); int32_t obj_setArg(PikaObj* self, char* argPath, Arg* arg);