On Thu, Jul 15, 2010 at 11:07 AM, Robert Kern <[email protected]> wrote:
> On 7/15/10 12:43 PM, Stefan Behnel wrote:
>> Hi, note that this is a question for the cython-users mailing list.
>
> Sorry. Since I am also questioning the implementation, this seemed like a
> reasonable place. :-)
>
>> Robert Kern, 15.07.2010 19:38:
>>> What are the recommendations for the use of the "object" type versus 
>>> "PyObject
>>> *"? Ondrej pointed out a potential bug in my line_profiler package:
>>>
>>> http://github.com/certik/line_profiler/commit/dc3ad198f8a810d34da5da71ffccf01c5e05a161
>>>
>>> I have a cdef function that serves as the callback for the PyEval_SetTrace()
>>> functionality. It has a PyObject* argument that is sometimes NULL. This 
>>> argument
>>> happens to be unused. In the version of Cython I originally developed
>>> line_profile under , no code referenced this argument. In the development
>>> version of Cython that Ondrej used to compile line_profiler, a Py_INCREF is
>>> apparently generated. When the argument is NULL, this obviously fails.
>>>
>>> Is this intentional? Should "object" be avoided when the argument could 
>>> possibly
>>> be NULL? Or should the generated code use Py_XINCREF/Py_XDECREF instead to 
>>> avoid
>>> failure?
>>
>> In Cython, object and PyObject* are not compatible. The first is an
>> automatically ref-counted object, whereas the second is a plain pointer.
>> For an argument that can be NULL, you cannot use object.
>
> Would using Py_XINCREF/Py_XDECREF allow the automatic refcounting to simply
> ignore NULL pointers but still work for the usual case? Or would there be 
> other
> issues?

There would be lots of other issues. An object is assumed to be an
valid Python reference, ready for passing on to other functions,
insertion into a list, assigning to variables, etc.

- Robert
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to