On Tue, Feb 17, 2009 at 2:32 AM, Robert Bradshaw
<[email protected]> wrote:
> On Feb 16, 2009, at 8:26 PM, Ondrej Certik wrote:
>
>> Currently I am using the following code and everything works for me:
>
> [...]
>
>> But it uses the PY_NEW macro:
>>
>> #define PY_NEW(zzz_type) \
>>     (((PyTypeObject*)(zzz_type))->tp_new((PyTypeObject*)(zzz_type),
>> global_empty_tuple, NULL))
>>
>> and global_empty_tuple() that I had to initialize, etc. I copied this
>> from Sage. Is there some better way to do the above, so that I don't
>> have to include the special macro above and the corresponding .h and
>> .c files in my project?
>
> How about
>
> cdef extern from *:
>     ctypedef struct RichPyTypeObject "PyTypeObject":
>         object tp_new(object, object, PyObject*)
>
> cdef inline PY_NEW(T):
>     return (<RichPyTypeObject*>x).tp_new(T, (), NULL)

This works, thanks! There were couple minor typos, e.g.:

object -> RichPyTypeObject*
T -> (<RichPyTypeObject*>T)
x -> T

So this is the correct code that works for me:

cdef extern from *:
    ctypedef struct RichPyTypeObject "PyTypeObject":
        object tp_new(RichPyTypeObject*, object, PyObject*)

cdef inline PY_NEW(T):
    return (<RichPyTypeObject*>T).tp_new((<RichPyTypeObject*>T), (), NULL)


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

Reply via email to