changing the include definition to:<div><br></div><div>cdef extern from &quot;Python.h&quot;:</div><div>     int PyObject_GenericSetAttr(PyObject*, PyObject*, PyObject*) except -1 </div><div><br></div><div>Seems to solve the problem, with the inconvenience of needing to explicitly cast to &lt;PyObject*&gt; before calling it. However, the objects are no longer incref&#39;d before calling, so this may or not be an issue. </div>
<div><br></div><div><br></div><div><div class="gmail_quote">On Sun, Feb 13, 2011 at 3:39 PM, Chris Colbert <span dir="ltr">&lt;<a href="mailto:sccolbert@gmail.com">sccolbert@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I should mention, that these PyObject_Generic* functions are being used from with __getattribute__, __setattr__, and __delattr__ methods. I should have added that context in the begining.<div><div></div><div class="h5"><br>
<br><div class="gmail_quote">On Sun, Feb 13, 2011 at 3:37 PM, Chris Colbert <span dir="ltr">&lt;<a href="mailto:sccolbert@gmail.com" target="_blank">sccolbert@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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" target="_blank">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><div></div><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" target="_blank">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>
I have cython file which is using PyObject_GenericSetAttr <br></div><div>
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><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>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br></div>