Commit 199b5c5c authored by Stefan Behnel's avatar Stefan Behnel

initialise all fields to 0 when using object structs from the freelist

--HG--
extra : rebase_source : 346e99306b247c116d988b58802ed7e7eb62754c
parent b25259c9
...@@ -1076,10 +1076,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1076,10 +1076,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
else: else:
code.putln("PyObject *o;") code.putln("PyObject *o;")
if freelist_size: if freelist_size:
code.globalstate.use_utility_code(
UtilityCode.load_cached("IncludeStringH", "StringTools.c"))
obj_struct = type.declaration_code("", deref=True)
code.putln("if ((%s > 0) & (t->tp_basicsize == sizeof(%s))) {" % ( code.putln("if ((%s > 0) & (t->tp_basicsize == sizeof(%s))) {" % (
freecount_name, type.declaration_code("", deref=True))) freecount_name, obj_struct))
code.putln("o = (PyObject*)%s[--%s];" % ( code.putln("o = (PyObject*)%s[--%s];" % (
freelist_name, freecount_name)) freelist_name, freecount_name))
code.putln("memset(o, 0, sizeof(%s));" % obj_struct)
code.putln("PyObject_INIT(o, t);") code.putln("PyObject_INIT(o, t);")
if scope.needs_gc(): if scope.needs_gc():
code.putln("PyObject_GC_Track(o);") code.putln("PyObject_GC_Track(o);")
......
...@@ -69,6 +69,52 @@ cdef class LargerExtSubType(ExtSubType): ...@@ -69,6 +69,52 @@ cdef class LargerExtSubType(ExtSubType):
self.attribute2 = object() self.attribute2 = object()
@cython.freelist(8)
cdef class ExtTypeWithCAttr:
"""
>>> obj = ExtTypeWithCAttr()
>>> obj = ExtTypeWithCAttr()
>>> obj = ExtTypeWithCAttr()
>>> obj = ExtTypeWithCAttr()
>>> obj = ExtTypeWithCAttr()
>>> obj = ExtTypeWithCAttr()
"""
cdef int cattr
def __cinit__(self):
assert self.cattr == 0
self.cattr = 1
cdef class ExtSubTypeWithCAttr(ExtTypeWithCAttr):
"""
>>> obj = ExtSubTypeWithCAttr()
>>> obj = ExtSubTypeWithCAttr()
>>> obj = ExtSubTypeWithCAttr()
>>> obj = ExtSubTypeWithCAttr()
>>> obj = ExtSubTypeWithCAttr()
>>> obj = ExtSubTypeWithCAttr()
"""
cdef class ExtTypeWithCAttrNoFreelist:
"""
For comparison with normal CPython instantiation.
>>> obj = ExtTypeWithCAttrNoFreelist()
>>> obj = ExtTypeWithCAttrNoFreelist()
>>> obj = ExtTypeWithCAttrNoFreelist()
>>> obj = ExtTypeWithCAttrNoFreelist()
>>> obj = ExtTypeWithCAttrNoFreelist()
>>> obj = ExtTypeWithCAttrNoFreelist()
"""
cdef int cattr
def __cinit__(self):
assert self.cattr == 0
self.cattr = 1
@cython.freelist(8) @cython.freelist(8)
cdef class ExtTypeWithRefCycle: cdef class ExtTypeWithRefCycle:
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment