From 279e68ea8f7d08bb8eadd5573b6f31d677a15097 Mon Sep 17 00:00:00 2001 From: Lisandro Dalcin Date: Wed, 8 Apr 2009 20:09:24 -0300 Subject: [PATCH] fix bad core generation for ctypedef classes when init tp_weaklistoffset type slot --- Cython/Compiler/ModuleNode.py | 8 ++++++-- tests/bugs/weakref_T276.pyx | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 tests/bugs/weakref_T276.pyx 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__ + -- 2.26.2