[Pyrex] [Cython-dev] fix for tp_clear()

Stefan Behnel stefan_ml at behnel.de
Sun Jan 13 10:13:22 CET 2008


Robert Bradshaw wrote:
> On Jan 12, 2008, at 2:23 PM, Stefan Behnel wrote:
>> I'd like to hear opinions why the None would be necessary here,
>> otherwise I'd just leave it with the NULL.
> 
> I believe this is so the object starts out in a valid state, and we
> never have to worry (e.g. elsewhere in the code)  that members do not
> contain a valid Python object.

That's the general reason, sure. Anyway, I guess we can just be conservative
here. Here a second patch that fixes it up.

Stefan

# HG changeset patch
# User Stefan Behnel <scoder at users.berlios.de>
# Date 1200215467 -3600
# Node ID c53e564690d099264a894face5a0d2000475d1ab
# Parent  bac16e6f5023d048cb933fbf6b3a5e181e42b9f8
reset to None instead of NULL in tp_clear()

diff -r bac16e6f5023 -r c53e564690d0 Compiler/ModuleNode.py
--- a/Compiler/ModuleNode.py    Sat Jan 12 21:33:30 2008 +0100
+++ b/Compiler/ModuleNode.py    Sun Jan 13 10:11:07 2008 +0100
@@ -767,7 +767,8 @@ class ModuleNode(Nodes.Node, Nodes.Block
             code.putln("}")
         for entry in py_attrs:
             name = "p->%s" % entry.cname
-            code.putln("tmp = %s; %s = 0;" % (name, name))
+            code.putln("tmp = %s;" % name)
+            code.put_init_to_py_none(name, entry.type)
             code.putln("Py_XDECREF(tmp);")
         code.putln(
             "return 0;")

-------------- next part --------------
A non-text attachment was scrubbed...
Name: tp_clear-fixes.bundle
Type: application/octet-stream
Size: 9054 bytes
Desc: not available
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20080113/6f14db69/attachment-0001.obj 


More information about the Pyrex mailing list