Răsfoiți Sursa

fix callbck write object.attr

pikastech 3 ani în urmă
părinte
comite
6eb499dd5f
6 a modificat fișierele cu 13 adăugiri și 4 ștergeri
  1. 1 1
      src/PikaObj.c
  2. 1 1
      src/PikaObj.h
  3. 7 0
      src/PikaVM.c
  4. 1 1
      src/PikaVersion.h
  5. 1 1
      test/module-test.cpp
  6. 2 0
      test/python/issue/issue_global.py

+ 1 - 1
src/PikaObj.c

@@ -144,7 +144,7 @@ PIKA_RES obj_setPtr(PikaObj* self, char* argPath, void* pointer) {
     return PIKA_RES_OK;
 }
 
-PIKA_RES obj_setRef(PikaObj* self, char* argPath, void* pointer) {
+PIKA_RES obj_setRef(PikaObj* self, char* argPath, PikaObj* pointer) {
     PikaObj* obj = obj_getHostObj(self, argPath);
     if (NULL == obj) {
         /* [error] object no found */

+ 1 - 1
src/PikaObj.h

@@ -111,7 +111,7 @@ int32_t obj_disable(PikaObj* self);
 
 // arg type operations
 PIKA_RES obj_setInt(PikaObj* self, char* argPath, int64_t val);
-PIKA_RES obj_setRef(PikaObj* self, char* argPath, void* pointer);
+PIKA_RES obj_setRef(PikaObj* self, char* argPath, PikaObj* pointer);
 PIKA_RES obj_setPtr(PikaObj* self, char* argPath, void* pointer);
 PIKA_RES obj_setFloat(PikaObj* self, char* argPath, double value);
 PIKA_RES obj_setStr(PikaObj* self, char* argPath, char* str);

+ 7 - 0
src/PikaVM.c

@@ -1489,10 +1489,17 @@ static Arg* VM_instruction_handler_OUT(PikaObj* self,
     }
 
     host_obj = obj_getHostObjWithIsTemp(context, arg_path, &is_temp);
+
+    if (NULL == host_obj) {
+        host_obj = obj_getHostObjWithIsTemp(vm->globals, arg_path, &is_temp);
+    }
+
     if (host_obj != NULL) {
         if (_proxy_setattr(host_obj, arg_name, out_arg)) {
             return NULL;
         }
+        obj_setArg_noCopy(host_obj, arg_name, out_arg);
+        return NULL;
     }
 
     obj_setArg_noCopy(context, arg_path, out_arg);

+ 1 - 1
src/PikaVersion.h

@@ -2,4 +2,4 @@
 #define PIKA_VERSION_MINOR       11
 #define PIKA_VERSION_MICRO       2
 
-#define PIKA_EDIT_TIME      "2022/09/26 22:03:32"
+#define PIKA_EDIT_TIME      "2022/09/27 10:23:59"

+ 1 - 1
test/module-test.cpp

@@ -333,7 +333,6 @@ TEST(modbus, rtu_master) {
     EXPECT_EQ(pikaMemNow(), 0);
 }
 
-
 TEST(proxy, test1) {
     /* init */
     pikaMemInfo.heapUsedMax = 0;
@@ -363,6 +362,7 @@ TEST(issue, global) {
     pikaVM_runSingleFile(pikaMain, "test/python/issue/issue_global.py");
     /* collect */
     /* assert */
+    EXPECT_EQ(obj_getInt(pikaMain, "testpara.timer2_flag"), 1);
     /* deinit */
     obj_deinit(pikaMain);
     EXPECT_EQ(pikaMemNow(), 0);

+ 2 - 0
test/python/issue/issue_global.py

@@ -53,5 +53,7 @@ testpara.fun1('fun1')
 testpara.fun2('fun2')
 testpara.fun3('fun3')
 callBack1(1)
+print('testpara.timer2_flag', testpara.timer2_flag)
 callBack2(2)
+print('testpara.timer2_flag', testpara.timer2_flag)
 callBack3(3)