fix bad core generation for ctypedef classes when init tp_weaklistoffset type slot
authorLisandro Dalcin <dalcinl@gmail.com>
Wed, 8 Apr 2009 23:09:24 +0000 (20:09 -0300)
committerLisandro Dalcin <dalcinl@gmail.com>
Wed, 8 Apr 2009 23:09:24 +0000 (20:09 -0300)
Cython/Compiler/ModuleNode.py
tests/bugs/weakref_T276.pyx [new file with mode: 0644]

index b7dc076b3e32fbd2fda1c91727ad8ffd06e914da..01567912f77c2dc0f81416cf92084f134b190686 100644 (file)
@@ -1959,10 +1959,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
                 if weakref_entry:
                     if weakref_entry.type is py_object_type:
                         tp_weaklistoffset = "%s.tp_weaklistoffset" % typeobj_cname
-                        code.putln("if (%s == 0) %s = offsetof(struct %s, %s);" % (
+                        if type.typedef_flag:
+                            objstruct = type.objstruct_cname
+                        else:
+                            objstruct = "struct %s" % type.objstruct_cname
+                        code.putln("if (%s == 0) %s = offsetof(%s, %s);" % (
                             tp_weaklistoffset,
                             tp_weaklistoffset,
-                            type.objstruct_cname,
+                            objstruct,
                             weakref_entry.cname))
                     else:
                         error(weakref_entry.pos, "__weakref__ slot must be of type 'object'")
diff --git a/tests/bugs/weakref_T276.pyx b/tests/bugs/weakref_T276.pyx
new file mode 100644 (file)
index 0000000..2100761
--- /dev/null
@@ -0,0 +1,12 @@
+__doc__ = u"""
+"""
+
+cdef class A:
+    cdef __weakref__
+
+ctypedef public class B [type B_Type, object BObject]:
+    cdef __weakref__
+
+cdef public class C [type C_Type, object CObject]:
+    cdef __weakref__
+