prevent tp_new() optimisation from breaking external types with known typeobj
authorStefan Behnel <stefan_ml@behnel.de>
Fri, 29 Mar 2013 20:21:14 +0000 (21:21 +0100)
committerStefan Behnel <stefan_ml@behnel.de>
Fri, 29 Mar 2013 20:21:14 +0000 (21:21 +0100)
Cython/Compiler/Optimize.py
tests/run/tp_new_cimport.srctree

index ea11aa3..5660c2f 100644 (file)
@@ -2189,7 +2189,9 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
 
         if type_arg.type_entry:
             ext_type = type_arg.type_entry.type
-            if ext_type.is_extension_type and ext_type.typeobj_cname:
+            if (ext_type.is_extension_type and ext_type.typeobj_cname and
+                    ext_type.scope.global_scope() == self.current_env().global_scope()):
+                # known type in current module
                 tp_slot = TypeSlots.ConstructorSlot("tp_new", '__new__')
                 slot_func_cname = TypeSlots.get_slot_function(ext_type.scope, tp_slot)
                 if slot_func_cname:
index d60d712..632172c 100644 (file)
@@ -42,7 +42,7 @@ def test_sub():
 
 ######## a.pxd ########
 
-cdef class ExtTypeA:
+cdef api class ExtTypeA[type ExtTypeA_Type, object ExtTypeAObject]:
     cdef readonly attrA
 
 ######## a.pyx ########