From b9ff295636828c5f39c3293b90dc10311a95e78b Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sat, 12 Jan 2008 21:33:30 +0100 Subject: [PATCH] fix tp_clear() according to Python docs: zero out member pointer before decrefing its content --- Cython/Compiler/ModuleNode.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 5c78abda..5b918dab 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -758,6 +758,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): py_attrs.append(entry) if py_attrs: self.generate_self_cast(scope, code) + code.putln("PyObject* tmp;") if base_type: code.putln("if (%s->tp_clear) {" % base_type.typeptr_cname) code.putln( @@ -766,8 +767,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln("}") for entry in py_attrs: name = "p->%s" % entry.cname - code.put_xdecref(name, entry.type) - code.put_init_var_to_py_none(entry, "p->%s") + code.putln("tmp = %s; %s = 0;" % (name, name)) + code.putln("Py_XDECREF(tmp);") code.putln( "return 0;") code.putln( -- 2.26.2