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):
else:
finalised_check = (
'(!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))')
code.putln("if (unlikely(Py_TYPE(o)->tp_finalize) && %s) {" %
finalised_check)
code.putln(
"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
code.putln("if (PyObject_CallFinalizerFromDealloc(o)) return;")
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