merge and fixes
authorStefan Behnel <scoder@users.berlios.de>
Mon, 23 Feb 2009 20:42:43 +0000 (21:42 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Mon, 23 Feb 2009 20:42:43 +0000 (21:42 +0100)
1  2 
Cython/Compiler/ModuleNode.py
Cython/Compiler/Nodes.py
tests/run/argdefault.pyx

index d6d8f4cad07d1ba3d6b36b87f4c5f65d42e0d577,3967f8dd9163025a53224e404509deffa927996c..bd15729bf539dc20a1e5aa5c2742052110434e23
@@@ -1706,6 -1706,10 +1706,9 @@@ class ModuleNode(Nodes.Node, Nodes.Bloc
                  code.put_decref_clear(entry.pystring_cname,
                                        PyrexTypes.py_object_type,
                                        nanny=False)
 -                code.putln("Py_DECREF(%s); %s = 0;" % (
 -                        code.entry_as_pyobject(entry), entry.cname))
+         for entry in env.default_entries:
+             if entry.type.is_pyobject and entry.used:
++                code.put_var_decref_clear(entry)
          code.putln("Py_INCREF(Py_None); return Py_None;")
          code.putln('}')
  
index 01eb070afdef7ee165075e8f5fa5f842bfbd3c58,b1c850abcc11dfd6e643775c52a5443880ca711d..57dce96a95cabd7ceda5cf6ccc73db5d238f5a62
@@@ -1231,16 -1233,14 +1233,17 @@@ class FuncDefNode(StatNode, BlockNode)
              if default:
                  if not default.is_literal:
                      default.generate_evaluation_code(code)
 -                    assign_code = "%s = %s;" % (
 -                        arg.default_entry.cname,
 -                        default.result_as(arg.default_entry.type))
 -                    if default.type.is_pyobject:
 -                        assign_code += " Py_INCREF(%s);" % \
 -                            arg.type.as_pyobject(arg.default_entry.cname)
 -                    code.putln(assign_code)
 -                    default.generate_disposal_code(code)
 +                    default.make_owned_reference(code)
++                    if default.is_temp and default.type.is_pyobject:
++                        cleanup = " %s = 0;" % default.result()
++                    else:
++                        cleanup = ''
 +                    code.putln(
-                         "%s = %s;" % (
++                        "%s = %s;%s" % (
 +                            arg.default_entry.cname,
-                             default.result_as(arg.default_entry.type)))
-                     if default.is_temp and default.type.is_pyobject:
-                         code.putln(
-                             "%s = 0;" %
-                                 default.result())
++                            default.result_as(arg.default_entry.type),
++                            cleanup))
 +                    code.put_giveref(arg.default_entry.cname)
                      default.free_temps(code)
          # For Python class methods, create and store function object
          if self.assmt:
index 0000000000000000000000000000000000000000,6ef1faaa8d5a8f1671b1625120d7f8cb484a264b..d1cdf7b41158e90aaf617dd82a8277d749bfb0f6
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,78 +1,78 @@@
 -<argdefaultglb.Foo object at ...>
+ __doc__ = """
+ >>> f0()
+ (1, 2)
+ >>> g0()
+ (1, 2)
+ >>> f1()
+ [1, 2]
+ >>> g1()
+ [1, 2]
+ >>> f2()
+ {1: 2}
+ >>> g2()
+ {1: 2}
+ >>> f3() #doctest: +ELLIPSIS
 -<argdefaultglb.Foo object at ...>
++<argdefault.Foo object at ...>
+ >>> g3() #doctest: +ELLIPSIS
 -<argdefaultglb.Bar object at ...>
++<argdefault.Foo object at ...>
+ >>> f4() #doctest: +ELLIPSIS
 -<argdefaultglb.Bar object at ...>
++<argdefault.Bar object at ...>
+ >>> g4() #doctest: +ELLIPSIS
 -<argdefaultglb.Bla object at ...>
++<argdefault.Bar object at ...>
+ >>> f5() #doctest: +ELLIPSIS
 -<argdefaultglb.Bla object at ...>
++<argdefault.Bla object at ...>
+ >>> g5() #doctest: +ELLIPSIS
++<argdefault.Bla object at ...>
+ """
+ GLB0 = (1, 2)
+ def f0(arg=GLB0):
+     return arg
+ def g0(arg=(1, 2)):
+     return arg
+ GLB1 = [1, 2]
+ def f1(arg=GLB1):
+     return arg
+ def g1(arg=[1, 2]):
+     return arg
+ cdef GLB2 = {1: 2}
+ def f2(arg=GLB2):
+     return arg
+ def g2(arg={1: 2}):
+     return arg
+ class Foo(object):
+     pass
+ cdef GLB3 = Foo()
+ def f3(arg=GLB3):
+     return arg
+ def g3(arg=Foo()):
+     return arg
+ cdef class Bar:
+     pass
+ cdef Bar GLB4 = Bar()
+ def f4(arg=GLB4):
+     return arg
+ def g4(arg=Bar()):
+     return arg
+ cdef class Bla:
+     pass
+ cdef Bla GLB5 = Bla()
+ def f5(Bla arg=GLB5):
+     return arg
+ def g5(Bla arg=Bla()):
+     return arg