mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
divide POINTER and REF_OBJECT OK
This commit is contained in:
parent
37f3062b88
commit
059096a7b1
@ -30,7 +30,8 @@ Arg* PikaStdData_Dict___next__(PikaObj* self) {
|
|||||||
int __iter_i = args_getInt(self->list, "__iter_i");
|
int __iter_i = args_getInt(self->list, "__iter_i");
|
||||||
PikaObj* pyload = obj_getObj(self, "pyload", 0);
|
PikaObj* pyload = obj_getObj(self, "pyload", 0);
|
||||||
Arg* res = arg_copy(args_getArg_index(pyload->list, __iter_i));
|
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);
|
arg_deinit(res);
|
||||||
return arg_setNull(NULL);
|
return arg_setNull(NULL);
|
||||||
}
|
}
|
||||||
|
@ -217,9 +217,9 @@ int PikaStdLib_SysObj_len(PikaObj* self, Arg* arg) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Arg* PikaStdLib_SysObj_list(PikaObj *self){
|
Arg* PikaStdLib_SysObj_list(PikaObj* self) {
|
||||||
#if PIKA_BUILTIN_LIST_ENABLE
|
#if PIKA_BUILTIN_LIST_ENABLE
|
||||||
PikaObj *New_PikaStdData_List(Args *args);
|
PikaObj* New_PikaStdData_List(Args * args);
|
||||||
return obj_newObjInPackage(New_PikaStdData_List);
|
return obj_newObjInPackage(New_PikaStdData_List);
|
||||||
#endif
|
#endif
|
||||||
obj_setErrorCode(self, 1);
|
obj_setErrorCode(self, 1);
|
||||||
@ -227,9 +227,9 @@ Arg* PikaStdLib_SysObj_list(PikaObj *self){
|
|||||||
return arg_setNull(NULL);
|
return arg_setNull(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
Arg* PikaStdLib_SysObj_dict(PikaObj *self){
|
Arg* PikaStdLib_SysObj_dict(PikaObj* self) {
|
||||||
#if PIKA_BUILTIN_DICT_ENABLE
|
#if PIKA_BUILTIN_DICT_ENABLE
|
||||||
PikaObj *New_PikaStdData_Dict(Args *args);
|
PikaObj* New_PikaStdData_Dict(Args * args);
|
||||||
return obj_newObjInPackage(New_PikaStdData_Dict);
|
return obj_newObjInPackage(New_PikaStdData_Dict);
|
||||||
#endif
|
#endif
|
||||||
obj_setErrorCode(self, 1);
|
obj_setErrorCode(self, 1);
|
||||||
|
@ -30,7 +30,8 @@ Arg* PikaStdData_Dict___next__(PikaObj* self) {
|
|||||||
int __iter_i = args_getInt(self->list, "__iter_i");
|
int __iter_i = args_getInt(self->list, "__iter_i");
|
||||||
PikaObj* pyload = obj_getObj(self, "pyload", 0);
|
PikaObj* pyload = obj_getObj(self, "pyload", 0);
|
||||||
Arg* res = arg_copy(args_getArg_index(pyload->list, __iter_i));
|
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);
|
arg_deinit(res);
|
||||||
return arg_setNull(NULL);
|
return arg_setNull(NULL);
|
||||||
}
|
}
|
||||||
|
@ -217,9 +217,9 @@ int PikaStdLib_SysObj_len(PikaObj* self, Arg* arg) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Arg* PikaStdLib_SysObj_list(PikaObj *self){
|
Arg* PikaStdLib_SysObj_list(PikaObj* self) {
|
||||||
#if PIKA_BUILTIN_LIST_ENABLE
|
#if PIKA_BUILTIN_LIST_ENABLE
|
||||||
PikaObj *New_PikaStdData_List(Args *args);
|
PikaObj* New_PikaStdData_List(Args * args);
|
||||||
return obj_newObjInPackage(New_PikaStdData_List);
|
return obj_newObjInPackage(New_PikaStdData_List);
|
||||||
#endif
|
#endif
|
||||||
obj_setErrorCode(self, 1);
|
obj_setErrorCode(self, 1);
|
||||||
@ -227,9 +227,9 @@ Arg* PikaStdLib_SysObj_list(PikaObj *self){
|
|||||||
return arg_setNull(NULL);
|
return arg_setNull(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
Arg* PikaStdLib_SysObj_dict(PikaObj *self){
|
Arg* PikaStdLib_SysObj_dict(PikaObj* self) {
|
||||||
#if PIKA_BUILTIN_DICT_ENABLE
|
#if PIKA_BUILTIN_DICT_ENABLE
|
||||||
PikaObj *New_PikaStdData_Dict(Args *args);
|
PikaObj* New_PikaStdData_Dict(Args * args);
|
||||||
return obj_newObjInPackage(New_PikaStdData_Dict);
|
return obj_newObjInPackage(New_PikaStdData_Dict);
|
||||||
#endif
|
#endif
|
||||||
obj_setErrorCode(self, 1);
|
obj_setErrorCode(self, 1);
|
||||||
|
@ -13,7 +13,7 @@ void ctypesUtils_setFloat(PikaObj* self, float val) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ctypesUtils_setPtr(PikaObj* self, void* ptr) {
|
void ctypesUtils_setPtr(PikaObj* self, void* ptr) {
|
||||||
obj_setRefObject(self, "value", ptr);
|
obj_setPtr(self, "value", ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ctypesUtils_getInt(PikaObj* self) {
|
int ctypesUtils_getInt(PikaObj* self) {
|
||||||
|
@ -144,7 +144,7 @@ TEST(object_test, test8) {
|
|||||||
TEST(object_test, test9) {
|
TEST(object_test, test9) {
|
||||||
PikaObj* sys = newRootObj((char*)"sys", New_PikaStdLib_SysObj);
|
PikaObj* sys = newRootObj((char*)"sys", New_PikaStdLib_SysObj);
|
||||||
obj_run(sys, (char*)"ls()");
|
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_run(sys, (char*)"ls()");
|
||||||
obj_deinit(sys);
|
obj_deinit(sys);
|
||||||
EXPECT_EQ(pikaMemNow(), 0);
|
EXPECT_EQ(pikaMemNow(), 0);
|
||||||
|
@ -144,6 +144,16 @@ int32_t obj_setInt(PikaObj* self, char* argPath, int64_t val) {
|
|||||||
return 0;
|
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) {
|
int32_t obj_setRefObject(PikaObj* self, char* argPath, void* pointer) {
|
||||||
PikaObj* obj = obj_getObj(self, argPath, 1);
|
PikaObj* obj = obj_getObj(self, argPath, 1);
|
||||||
if (NULL == obj) {
|
if (NULL == obj) {
|
||||||
@ -300,15 +310,6 @@ int32_t obj_load(PikaObj* self, Args* args, char* name) {
|
|||||||
return 0;
|
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) {
|
int32_t obj_freeObj(PikaObj* self, char* objPath) {
|
||||||
PikaObj* obj = obj_getPtr(self, objPath);
|
PikaObj* obj = obj_getPtr(self, objPath);
|
||||||
obj_deinit(obj);
|
obj_deinit(obj);
|
||||||
@ -327,7 +328,7 @@ PikaObj* obj_getClassObjByNewFun(PikaObj* context,
|
|||||||
NewFun newClassFun) {
|
NewFun newClassFun) {
|
||||||
Args* initArgs = New_args(NULL);
|
Args* initArgs = New_args(NULL);
|
||||||
PikaObj* thisClass = newClassFun(initArgs);
|
PikaObj* thisClass = newClassFun(initArgs);
|
||||||
obj_setRefObject(thisClass, "_clsptr", (void*)newClassFun);
|
obj_setPtr(thisClass, "_clsptr", (void*)newClassFun);
|
||||||
args_deinit(initArgs);
|
args_deinit(initArgs);
|
||||||
return thisClass;
|
return thisClass;
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,7 @@ int32_t obj_disable(PikaObj* self);
|
|||||||
// arg type operations
|
// arg type operations
|
||||||
int32_t obj_setInt(PikaObj* self, char* argPath, int64_t val);
|
int32_t obj_setInt(PikaObj* self, char* argPath, int64_t val);
|
||||||
int32_t obj_setRefObject(PikaObj* self, char* argPath, void* pointer);
|
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_setFloat(PikaObj* self, char* argPath, float value);
|
||||||
int32_t obj_setStr(PikaObj* self, char* argPath, char* str);
|
int32_t obj_setStr(PikaObj* self, char* argPath, char* str);
|
||||||
int32_t obj_setArg(PikaObj* self, char* argPath, Arg* arg);
|
int32_t obj_setArg(PikaObj* self, char* argPath, Arg* arg);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user