Commit 0898a2f2 authored by Stefan Behnel's avatar Stefan Behnel

safety fix: do not access type struct field "tp_finalize" if the type states...

safety fix: do not access type struct field "tp_finalize" if the type states that it does not have it (because the struct might really be shorter in that case)
parent abf1bdd0
...@@ -1350,8 +1350,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1350,8 +1350,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
else: else:
finalised_check = ( finalised_check = (
'(!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))') '(!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))')
code.putln("if (unlikely(Py_TYPE(o)->tp_finalize) && %s) {" % code.putln(
finalised_check) "if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE)"
" && Py_TYPE(o)->tp_finalize) && %s) {" % finalised_check)
# if instance was resurrected by finaliser, return # if instance was resurrected by finaliser, return
code.putln("if (PyObject_CallFinalizerFromDealloc(o)) return;") code.putln("if (PyObject_CallFinalizerFromDealloc(o)) return;")
code.putln("}") code.putln("}")
......
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