The problem with delattr (and thus PyObject_DelAttr) arises when you define a __delattr__ method on your class. There is not easy way to then call back into the &quot;normal&quot; python delattr semantics, except by doing object.__delattr__ (which is not optimized by Cython). <div>
<br></div><div>Futher, calling PyObject_GenericSetattr(obj, name, NULL) appears to be the proper use, given that it properly follows the descriptor chain and will call __delete__ if <a href="http://obj.name">obj.name</a> is a descriptor. </div>
<div><br></div><div>I would argue that there should be at least some way to pass a NULL pointer in Cython where a PyObject* is expected. </div><div><br></div><div><br><div class="gmail_quote">On Sun, Feb 13, 2011 at 3:31 PM, Greg Ewing <span dir="ltr">&lt;<a href="mailto:greg.ewing@canterbury.ac.nz">greg.ewing@canterbury.ac.nz</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Chris Colbert wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
I have cython file which is using PyObject_GenericSetAttr <br></div><div class="im">
Now in my script I am using that function to generically delete an attribute by passing a NULL as the last value (this is proper way to trigger a generic delattr in the Python c-api)<br>
</div></blockquote>
<br>
I would have thought the proper way to do that was to use<br>
PyObject_DelAttr, which Pyrex exposes as delattr().<br>
<br>
I don&#39;t think PyObject_GenericSetAttr is even meant to be<br>
called directly -- it&#39;s intended for filling the tp_setattr<br>
slot of type objects.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This causes a segfault because the NULL is getting increfed via Py_INCREF instead of Py_XINCREF.<br>
</blockquote>
<br></div>
I would recommend against trying to &quot;fix&quot; this. You got<br>
away with it before because you happened to be passing the<br>
NULL value directly to a function which is expecting it.<br>
But casting NULL to an object reference is not something<br>
that should be encouraged, because in any other context it<br>
would quickly lead to disaster.<br>
<br>
-- <br><font color="#888888">
Greg<br>
</font></blockquote></div><br></div>