From: Lisandro Dalcin Date: Wed, 8 Apr 2009 23:09:24 +0000 (-0300) Subject: fix bad core generation for ctypedef classes when init tp_weaklistoffset type slot X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=279e68ea8f7d08bb8eadd5573b6f31d677a15097;p=cython.git fix bad core generation for ctypedef classes when init tp_weaklistoffset type slot --- diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index b7dc076b..01567912 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -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 index 00000000..21007618 --- /dev/null +++ b/tests/bugs/weakref_T276.pyx @@ -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__ +