summaryrefslogtreecommitdiff
path: root/Cython/Compiler/ModuleNode.py
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2014-03-03 18:43:16 +0100
committerStefan Behnel <stefan_ml@behnel.de>2014-03-03 18:43:16 +0100
commit0be0dd141b8ce80a98541e7a7f73e3931a22e08c (patch)
tree3bf11bc06785a6294b58822e815497dc53726413 /Cython/Compiler/ModuleNode.py
parentd2aff824dd0900982a420ebaaa1dac6120a9d72e (diff)
downloadcython-0be0dd141b8ce80a98541e7a7f73e3931a22e08c.tar.gz
apply freelist type check also when *adding* dead objects to the freelist to make sure their eventual cleanup works correctly
Diffstat (limited to 'Cython/Compiler/ModuleNode.py')
-rw-r--r--Cython/Compiler/ModuleNode.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py
index 9871e3efe..1612ccb86 100644
--- a/Cython/Compiler/ModuleNode.py
+++ b/Cython/Compiler/ModuleNode.py
@@ -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 {")