diff --git a/port/linux/push-core.sh b/port/linux/push-core.sh index 82a1d2cb0..1102ecd7f 100644 --- a/port/linux/push-core.sh +++ b/port/linux/push-core.sh @@ -5,7 +5,7 @@ FLAG_NOTE="\033[35m[Note]\033[0m" cp package/pikascript/pikascript-core/* ../../src -r cp package/pikascript/PikaObj.pyi ../../src -git add test/python/*.py +git add ../../test/python/*.py sh std_push.sh PikaStdLib sh std_push.sh PikaStdData sh std_push.sh PikaDebug diff --git a/src/PikaVM.c b/src/PikaVM.c index ac5e61ea0..ed9c58f90 100644 --- a/src/PikaVM.c +++ b/src/PikaVM.c @@ -1489,8 +1489,10 @@ static Arg* VM_instruction_handler_OUT(PikaObj* self, } host_obj = obj_getHostObjWithIsTemp(context, arg_path, &is_temp); - if (_proxy_setattr(host_obj, arg_name, out_arg)) { - return NULL; + if (host_obj != NULL) { + if (_proxy_setattr(host_obj, arg_name, out_arg)) { + return NULL; + } } obj_setArg_noCopy(context, arg_path, out_arg); diff --git a/test/module-test.cpp b/test/module-test.cpp index 9d027a08a..9fb0f3876 100644 --- a/test/module-test.cpp +++ b/test/module-test.cpp @@ -352,4 +352,20 @@ TEST(proxy, test1) { EXPECT_EQ(pikaMemNow(), 0); } +TEST(issue, global) { + /* init */ + 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"); + pikaVM_runSingleFile(pikaMain, "test/python/issue/issue_global.py"); + /* collect */ + /* assert */ + /* deinit */ + obj_deinit(pikaMain); + EXPECT_EQ(pikaMemNow(), 0); +} + #endif \ No newline at end of file diff --git a/test/python/issue/issue_global.py b/test/python/issue/issue_global.py new file mode 100644 index 000000000..c6538f772 --- /dev/null +++ b/test/python/issue/issue_global.py @@ -0,0 +1,57 @@ + +class Test: + def __init__(self): + self.timer1_flag = 0 + self.timer2_flag = 0 + self.timer3_flag = 0 + + def get_timer1_flag(self) -> int: + return self.timer1_flag + + def set_timer1_flag(self, flag): + self.timer1_flag = flag + + def fun1(self, name): + self.timer1_flag = 1 + print("fun1", name) + + def fun2(self, name): + #self.timer2_flag = 1 + print("fun2", name) + print('self.timer2_flag = ', self.timer2_flag) + + def fun3(self, name): + self.timer3_flag = 1 + print("fun3", name) + + +def callBack1(signal): + print("signal", signal) + testpara.fun1("callBack1") + print(testpara.timer1_flag) + + +def callBack2(signal): + print("signal", signal) + #global testpara + # global testpara.timer2_flag + testpara.timer2_flag += 1 + testpara.fun2("callBack2") + print('testpara.timer2_flag = ', testpara.timer2_flag) + + +def callBack3(signal): + print("signal", signal) + # global testpara + # testpara.timer3_flag = 1 + testpara.fun3("callBack3") + print(testpara.timer3_flag) + + +testpara = Test() +testpara.fun1('fun1') +testpara.fun2('fun2') +testpara.fun3('fun3') +callBack1(1) +callBack2(2) +callBack3(3)