Commit 0be0dd14 authored by Stefan Behnel's avatar Stefan Behnel

apply freelist type check also when *adding* dead objects to the freelist to...

apply freelist type check also when *adding* dead objects to the freelist to make sure their eventual cleanup works correctly
parent d2aff824
......@@ -1170,12 +1170,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.globalstate.use_utility_code(
UtilityCode.load_cached("IncludeStringH", "StringTools.c"))
if is_final_type:
abstract_check = ''
type_safety_check = ''
else:
abstract_check = ' & ((t->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)) == 0)'
type_safety_check = ' & ((t->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)) == 0)'
obj_struct = type.declaration_code("", deref=True)
code.putln("if (likely((%s > 0) & (t->tp_basicsize == sizeof(%s))%s)) {" % (
freecount_name, obj_struct, abstract_check))
freecount_name, obj_struct, type_safety_check))
code.putln("o = (PyObject*)%s[--%s];" % (
freelist_name, freecount_name))
code.putln("memset(o, 0, sizeof(%s));" % obj_struct)
......@@ -1340,9 +1340,16 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
freelist_name = scope.mangle_internal(Naming.freelist_name)
freecount_name = scope.mangle_internal(Naming.freecount_name)
if is_final_type:
type_safety_check = ''
else:
type_safety_check = (
' & ((Py_TYPE(o)->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)) == 0)')
type = scope.parent_type
code.putln("if ((%s < %d) & (Py_TYPE(o)->tp_basicsize == sizeof(%s))) {" % (
freecount_name, freelist_size, type.declaration_code("", deref=True)))
code.putln("if ((%s < %d) & (Py_TYPE(o)->tp_basicsize == sizeof(%s))%s) {" % (
freecount_name, freelist_size, type.declaration_code("", deref=True),
type_safety_check))
code.putln("%s[%s++] = %s;" % (
freelist_name, freecount_name, type.cast_code("o")))
code.putln("} else {")
......
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