divide POINTER and REF_OBJECT OK

This commit is contained in:
lyon 2022-04-25 15:01:58 +08:00
parent 37f3062b88
commit 059096a7b1
8 changed files with 26 additions and 22 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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) {

View File

@ -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);

View File

@ -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;
}

View File

@ -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);