From: Stefan Behnel Date: Thu, 4 Dec 2008 19:46:25 +0000 (+0100) Subject: fixed ref-counting in BoolBinopNode X-Git-Tag: 0.11-beta~161 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e30a5c4355f4766a8e39db1a96a5022f7609132d;p=cython.git fixed ref-counting in BoolBinopNode --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 8a46f5f1..492d2679 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -4121,10 +4121,12 @@ class BoolBinopNode(NewTempExprNode): self.operand1.generate_disposal_code(code) self.operand2.generate_evaluation_code(code) self.allocate_temp_result(code) + self.operand2.make_owned_reference(code) code.putln("%s = %s;" % (self.result(), self.operand2.result())) self.operand2.generate_post_assignment_code(code) self.operand2.free_temps(code) code.putln("} else {") + self.operand1.make_owned_reference(code) code.putln("%s = %s;" % (self.result(), self.operand1.result())) self.operand1.generate_post_assignment_code(code) self.operand1.free_temps(code) diff --git a/tests/run/or.pyx b/tests/run/or.pyx new file mode 100644 index 00000000..fb6d8e63 --- /dev/null +++ b/tests/run/or.pyx @@ -0,0 +1,51 @@ +u""" +>>> a,b = 'a *','b *' # use non-interned strings + +>>> or2_assign(2,3) == (2 or 3) +True +>>> or2_assign('a', 'b') == ('a' or 'b') +True +>>> or2_assign(a, b) == (a or b) +True + +>>> or2(2,3) == (2 or 3) +True +>>> or2(0,2) == (0 or 2) +True +>>> or2('a', 'b') == ('a' or 'b') +True +>>> or2(a, b) == (a or b) +True +>>> or2('', 'b') == ('' or 'b') +True +>>> or2([], [1]) == ([] or [1]) +True +>>> or2([], [a]) == ([] or [a]) +True + +>>> or3(0,1,2) == (0 or 1 or 2) +True +>>> or3([],(),[1]) == ([] or () or [1]) +True + +>>> or2_no_result(2,3) +>>> or2_no_result(0,2) +>>> or2_no_result('a','b') +>>> or2_no_result(a,b) +>>> a or b +'a *' +""" + +def or2_assign(a,b): + c = a or b + return c + +def or2(a,b): + return a or b + +def or3(a,b,c): + d = a or b or c + return d + +def or2_no_result(a,b): + a or b