cython-devel

changeset 1925:9a445f71940f

Fix #267
author Dag Sverre Seljebotn <dagss@student.matnat.uio.no>
date Sun Mar 29 12:19:11 2009 +0200 (2 years ago)
parents 7f00f88a459d
children 6b5e32a276ac
files Cython/Compiler/ExprNodes.py
line diff
1.1 --- a/Cython/Compiler/ExprNodes.py Sun Mar 29 12:06:06 2009 +0200 1.2 +++ b/Cython/Compiler/ExprNodes.py Sun Mar 29 12:19:11 2009 +0200 1.3 @@ -4501,32 +4501,9 @@ 1.4 if self.true_val.type.is_pyobject or self.false_val.type.is_pyobject: 1.5 self.true_val = self.true_val.coerce_to(self.type, env) 1.6 self.false_val = self.false_val.coerce_to(self.type, env) 1.7 - # must be tmp variables so they can share a result 1.8 - self.true_val = self.true_val.coerce_to_temp(env) 1.9 - self.false_val = self.false_val.coerce_to_temp(env) 1.10 self.is_temp = 1 1.11 if self.type == PyrexTypes.error_type: 1.12 self.type_error() 1.13 - 1.14 - def allocate_temps(self, env, result_code = None): 1.15 - # We only ever evaluate one side, and this is 1.16 - # after evaluating the truth value, so we may 1.17 - # use an allocation strategy here which results in 1.18 - # this node and both its operands sharing the same 1.19 - # result variable. This allows us to avoid some 1.20 - # assignments and increfs/decrefs that would otherwise 1.21 - # be necessary. 1.22 - self.allocate_temp(env, result_code) 1.23 - self.test.allocate_temps(env, result_code) 1.24 - self.true_val.allocate_temps(env, self.result()) 1.25 - self.false_val.allocate_temps(env, self.result()) 1.26 - # We haven't called release_temp on either value, 1.27 - # because although they are temp nodes, they don't own 1.28 - # their result variable. And because they are temp 1.29 - # nodes, any temps in their subnodes will have been 1.30 - # released before their allocate_temps returned. 1.31 - # Therefore, they contain no temp vars that need to 1.32 - # be released. 1.33 1.34 def compute_result_type(self, type1, type2): 1.35 if type1 == type2: 1.36 @@ -4558,15 +4535,27 @@ 1.37 self.false_val.check_const() 1.38 1.39 def generate_evaluation_code(self, code): 1.40 + # Because subexprs may not be evaluated we can use a more optimal 1.41 + # subexpr allocation strategy than the default, so override evaluation_code. 1.42 + 1.43 + code.mark_pos(self.pos) 1.44 + #self.allocate_temp_result(code) # uncomment this when we switch to new temps 1.45 self.test.generate_evaluation_code(code) 1.46 code.putln("if (%s) {" % self.test.result() ) 1.47 - self.true_val.generate_evaluation_code(code) 1.48 + self.eval_and_get(code, self.true_val) 1.49 code.putln("} else {") 1.50 - self.false_val.generate_evaluation_code(code) 1.51 + self.eval_and_get(code, self.false_val) 1.52 code.putln("}") 1.53 self.test.generate_disposal_code(code) 1.54 self.test.free_temps(code) 1.55 1.56 + def eval_and_get(self, code, expr): 1.57 + expr.generate_evaluation_code(code) 1.58 + expr.make_owned_reference(code) 1.59 + code.putln("%s = %s;" % (self.result(), expr.result())) 1.60 + expr.generate_post_assignment_code(code) 1.61 + expr.free_temps(code) 1.62 + 1.63 richcmp_constants = { 1.64 "<" : "Py_LT", 1.65 "<=": "Py_LE",