From: Dag Sverre Seljebotn Date: Wed, 7 Jan 2009 13:20:01 +0000 (+0100) Subject: merge X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f4cb6c7ba583316157cf00b4c8395484fc5faaae;p=cython.git merge --- f4cb6c7ba583316157cf00b4c8395484fc5faaae diff --cc Cython/Compiler/DebugFlags.py index aaa040b9,958ce269..b5c27369 --- a/Cython/Compiler/DebugFlags.py +++ b/Cython/Compiler/DebugFlags.py @@@ -2,4 -2,4 +2,5 @@@ debug_disposal_code = debug_temp_alloc = 0 debug_coercion = 0 -debug_refnanny = 1 +debug_temp_code_comments = 1 ++ diff --cc Cython/Compiler/ExprNodes.py index 1043a64c,5f832cdc..4673dcf8 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@@ -1016,9 -903,10 +1016,10 @@@ class LongNode(AtomicNewTempExprNode) self.result(), self.value, code.error_goto_if_null(self.result(), self.pos))) + code.put_gotref(self.result()) -class ImagNode(AtomicExprNode): +class ImagNode(AtomicNewTempExprNode): # Imaginary number literal # # value float imaginary part @@@ -1442,14 -1321,11 +1450,15 @@@ class ImportNode(ExprNode) self.module_name.py_result(), name_list_code, code.error_goto_if_null(self.result(), self.pos))) + code.put_gotref(self.result()) -class IteratorNode(ExprNode): +class IteratorNode(NewTempExprNode): # Used as part of for statement implementation. + # + # allocate_counter_temp/release_counter_temp needs to be called + # by parent (ForInStatNode) + # # Implements result = iter(sequence) # # sequence ExprNode @@@ -1490,16 -1360,12 +1499,17 @@@ self.sequence.py_result(), self.result())) code.putln("} else {") - code.putln("%s = -1; %s = PyObject_GetIter(%s); %s" % ( - self.counter.result(), - self.result(), - self.sequence.py_result(), - code.error_goto_if_null(self.result(), self.pos))) - code.put_gotref(self.result()) + if is_builtin_sequence: + code.putln( + 'PyErr_SetString(PyExc_TypeError, "\'NoneType\' object is not iterable"); %s' % + code.error_goto(self.pos)) + else: + code.putln("%s = -1; %s = PyObject_GetIter(%s); %s" % ( + self.counter_cname, + self.result(), + self.sequence.py_result(), + code.error_goto_if_null(self.result(), self.pos))) ++ code.put_gotref(self.result()) code.putln("}") @@@ -2158,9 -1895,10 +2171,10 @@@ class SliceNode(ExprNode) self.stop.py_result(), self.step.py_result(), code.error_goto_if_null(self.result(), self.pos))) + code.put_gotref(self.result()) -class CallNode(ExprNode): +class CallNode(NewTempExprNode): def gil_check(self, env): # Make sure we're not in a nogil environment if env.nogil: @@@ -2990,8 -2715,10 +3012,9 @@@ class SequenceNode(NewTempExprNode) item.result(), typecast(item.ctype(), py_object_type, unpack_code), code.error_goto_if_null(item.result(), self.pos))) + code.put_gotref(item.result()) value_node = self.coerced_unpacked_items[i] value_node.generate_evaluation_code(code) - self.args[i].generate_assignment_code(value_node, code) code.put_error_if_neg(self.pos, "__Pyx_EndUnpack(%s)" % ( self.iterator.py_result())) @@@ -3519,9 -3149,9 +3548,9 @@@ class UnboundMethodNode(ExprNode) self.function.py_result(), self.class_cname, code.error_goto_if_null(self.result(), self.pos))) - + code.put_gotref(self.result()) -class PyCFunctionNode(AtomicExprNode): +class PyCFunctionNode(AtomicNewTempExprNode): # Helper class used in the implementation of Python # class definitions. Constructs a PyCFunction object # from a PyMethodDef struct. diff --cc Cython/Compiler/Nodes.py index 3bdeeae7,4592cf47..38ac2cca --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@@ -3047,11 -2989,10 +3067,12 @@@ class InPlaceAssignmentNode(AssignmentN self.rhs.py_result(), extra, code.error_goto_if_null(self.result_value.py_result(), self.pos))) + code.put_gotref(self.result_value.result()) self.result_value.generate_evaluation_code(code) # May be a type check... self.rhs.generate_disposal_code(code) + self.rhs.free_temps(code) self.dup.generate_disposal_code(code) + self.dup.free_temps(code) self.lhs.generate_assignment_code(self.result_value, code) else: c_op = self.operator @@@ -4005,10 -3930,13 +4028,15 @@@ class TryExceptStatNode(StatNode) for var in Naming.exc_save_vars: code.put_xdecref_clear(var, py_object_type) code.put_goto(try_end_label) + if code.label_used(try_return_label): + code.put_label(try_return_label) + for var in Naming.exc_save_vars: + code.put_xdecref_clear(var, py_object_type) + code.put_goto(old_return_label) code.put_label(our_error_label) code.put_var_xdecrefs_clear(self.cleanup_list) + for temp_name, type in temps_to_clean_up: + code.put_xdecref_clear(temp_name, type) for except_clause in self.except_clauses: except_clause.generate_handling_code(code, except_end_label) @@@ -4551,9 -4472,9 +4579,10 @@@ class FromImportStatNode(StatNode) self.module.py_result(), cname, code.error_goto_if_null(self.item.result(), self.pos))) + code.put_gotref(self.item.result()) target.generate_assignment_code(self.item, code) self.module.generate_disposal_code(code) + self.module.free_temps(code) diff --cc Cython/Compiler/Visitor.py index 50856a3f,0ad6b0de..ad5b33ab --- a/Cython/Compiler/Visitor.py +++ b/Cython/Compiler/Visitor.py @@@ -26,19 -25,19 +26,19 @@@ class BasicVisitor(object) # Must resolve, try entire hierarchy pattern = "visit_%s" mro = inspect.getmro(cls) + handler_method = None for mro_cls in mro: - try: + if hasattr(self, pattern % mro_cls.__name__): handler_method = getattr(self, pattern % mro_cls.__name__) break - except AttributeError: - pass - else: + if handler_method is None: print type(self), type(obj) - if hasattr(self, 'access_path'): + if hasattr(self, 'access_path') and self.access_path: print self.access_path - print self.access_path[-1][0].pos - print self.access_path[-1][0].__dict__ - raise RuntimeError("Visitor does not accept object: %s" % (obj,)) + if self.access_path: + print self.access_path[-1][0].pos + print self.access_path[-1][0].__dict__ + raise RuntimeError("Visitor does not accept object: %s" % obj) #print "Caching " + cls.__name__ self.dispatch_table[cls] = handler_method return handler_method(obj)