Chris Colbert | 1 Jul 19:52
Picon

[Cython] how would I wrap something like this in a .pxd file

In wrapping a C library, I come across many #define statements that I
need to use elsewhere. When they simply define a constant, I use an
anonymous enum and all is well.

But how would I wrap something like this that shown up in a header
file that i'm cdef extern'ing from:

#define CV_TREE_NODE_FIELDS(node_type)                               \

    int       flags;                \

    int       header_size;          \

    struct    node_type* h_prev;      \

    struct    node_type* h_next;     \

    struct    node_type* v_prev;       \

    struct    node_type* v_next ;

or something like this:

#define CV_IS_STORAGE(storage)  \

    ((storage) != NULL &&       \

    (((CvMemStorage*)(storage))->signature & CV_MAGIC_MASK) ==
CV_STORAGE_MAGIC_VAL)

(Continue reading)

Chris Colbert | 1 Jul 20:24
Picon

Re: [Cython] how would I wrap something like this in a .pxd file

i just saw this line in the docs:

6. If the header file defines a function using a macro, declare it as
though it were an ordinary function, with appropriate argument and
result types.

So i'll start there.

Sorry for the bogus post.

On Wed, Jul 1, 2009 at 1:52 PM, Chris Colbert<sccolbert@...> wrote:
> In wrapping a C library, I come across many #define statements that I
> need to use elsewhere. When they simply define a constant, I use an
> anonymous enum and all is well.
>
> But how would I wrap something like this that shown up in a header
> file that i'm cdef extern'ing from:
>
> #define CV_TREE_NODE_FIELDS(node_type)                               \
>
>    int       flags;                \
>
>    int       header_size;          \
>
>    struct    node_type* h_prev;      \
>
>    struct    node_type* h_next;     \
>
>    struct    node_type* v_prev;       \
>
(Continue reading)

Lisandro Dalcin | 1 Jul 21:01
Picon
Gravatar

Re: [Cython] how would I wrap something like this in a .pxd file

On Wed, Jul 1, 2009 at 3:24 PM, Chris Colbert<sccolbert@...> wrote:
> i just saw this line in the docs:
>
> 6. If the header file defines a function using a macro, declare it as
> though it were an ordinary function, with appropriate argument and
> result types.
>
> So i'll start there.
>
> Sorry for the bogus post.
>

IMHO, your post was not bogus... Making Cython use such kind of macros
(which resembles a C++ template emulation) can be not so easy...
Perhaps the easiest way would be to define a helper struct (one of
each node_type) in some C header, and then include it using cdef
extern from "mydefs.h": ...

>
> On Wed, Jul 1, 2009 at 1:52 PM, Chris Colbert<sccolbert@...> wrote:
>> In wrapping a C library, I come across many #define statements that I
>> need to use elsewhere. When they simply define a constant, I use an
>> anonymous enum and all is well.
>>
>> But how would I wrap something like this that shown up in a header
>> file that i'm cdef extern'ing from:
>>
>> #define CV_TREE_NODE_FIELDS(node_type)                               \
>>
>>    int       flags;                \
(Continue reading)

Chris Colbert | 1 Jul 21:53
Picon

Re: [Cython] how would I wrap something like this in a .pxd file

Thanks Lisandro,

I may just end up declaring each struct like this with a 'pass'

and then implementing the fields on the python side (this is how ctypes does it)

Cheers!

On Wed, Jul 1, 2009 at 3:01 PM, Lisandro Dalcin<dalcinl@...> wrote:
> On Wed, Jul 1, 2009 at 3:24 PM, Chris Colbert<sccolbert@...> wrote:
>> i just saw this line in the docs:
>>
>> 6. If the header file defines a function using a macro, declare it as
>> though it were an ordinary function, with appropriate argument and
>> result types.
>>
>> So i'll start there.
>>
>> Sorry for the bogus post.
>>
>
> IMHO, your post was not bogus... Making Cython use such kind of macros
> (which resembles a C++ template emulation) can be not so easy...
> Perhaps the easiest way would be to define a helper struct (one of
> each node_type) in some C header, and then include it using cdef
> extern from "mydefs.h": ...
>
>
>>
>> On Wed, Jul 1, 2009 at 1:52 PM, Chris Colbert<sccolbert@...> wrote:
(Continue reading)

Chris Colbert | 1 Jul 23:35
Picon

Re: [Cython] how would I wrap something like this in a .pxd file

what about functions defined in a macro where i wont know the return
type in advance?

such as:

#define  CV_NEXT_GRAPH_EDGE( edge, vertex )                              \

     (assert((edge)->vtx[0] == (vertex) || (edge)->vtx[1] == (vertex)),  \

      (edge)->next[(edge)->vtx[1] == (vertex)])

should I just implement this as a python function, or is there a way
to wrap it?

I would wrapping wouldn't be possible since the type isn't determined
till runtime...

On Wed, Jul 1, 2009 at 3:53 PM, Chris Colbert<sccolbert@...> wrote:
> Thanks Lisandro,
>
> I may just end up declaring each struct like this with a 'pass'
>
> and then implementing the fields on the python side (this is how ctypes does it)
>
> Cheers!
>
> On Wed, Jul 1, 2009 at 3:01 PM, Lisandro Dalcin<dalcinl@...> wrote:
>> On Wed, Jul 1, 2009 at 3:24 PM, Chris Colbert<sccolbert@...> wrote:
>>> i just saw this line in the docs:
>>>
(Continue reading)

Lisandro Dalcin | 2 Jul 03:28
Picon
Gravatar

Re: [Cython] how would I wrap something like this in a .pxd file

I still think that the safest thing would be to use a C header
defining functions with different names for each type you intend to
use.

Until Cython does not provide some support for C++-ish templatized
declarations, I cannot warranty you that thinks will not break if we
try to be smart and use these macros directly...

On Wed, Jul 1, 2009 at 6:35 PM, Chris Colbert<sccolbert@...> wrote:
> what about functions defined in a macro where i wont know the return
> type in advance?
>
> such as:
>
> #define  CV_NEXT_GRAPH_EDGE( edge, vertex )                              \
>
>     (assert((edge)->vtx[0] == (vertex) || (edge)->vtx[1] == (vertex)),  \
>
>      (edge)->next[(edge)->vtx[1] == (vertex)])
>
> should I just implement this as a python function, or is there a way
> to wrap it?
>
> I would wrapping wouldn't be possible since the type isn't determined
> till runtime...
>
>
> On Wed, Jul 1, 2009 at 3:53 PM, Chris Colbert<sccolbert@...> wrote:
>> Thanks Lisandro,
>>
(Continue reading)


Gmane