mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
fix issue_global.py
This commit is contained in:
parent
75d6f97823
commit
917aa71e70
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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
|
57
test/python/issue/issue_global.py
Normal file
57
test/python/issue/issue_global.py
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user