David Cournapeau | 1 Dec 2008 13:40
Picon
Gravatar

Re: [Cython] Recursive structure, typedef

On Mon, Dec 1, 2008 at 9:31 PM, Lisandro Dalcin <dalcinl@...> wrote:
> Hi, David. Did you tried latest release,
> http://cython.org/Cython-0.10.2.tar.gz ? It contains fixes for
> recursive typedef struct. Please, give a try a let us know of any
> problem.
>

Yes, I use 0.10.2. I upgraded because indeed, before, the following
did not work:

cdef struct foo:
    foo *foo
ctypdef foo foo_t

It works on 0.10.2. But my problem is slightly different:

cdef struct foo:
    foo_t *foo
ctypdef foo foo_t

Notice how the recursive is referenced through a typedef. In C, this
is solved by forward declaring the struct through a typedef before the
struct declaration. But AFAIK, you can't do that in cython.

My question may be stupid: I know nothing about parsing languages, and
maybe this is just a problem in my own code generator which is
"hand-built" from the AST given by gccxml.

cheers,

(Continue reading)

Greg Ewing | 2 Dec 2008 00:27
Picon
Picon
Favicon

Re: [Cython] Recursive structure, typedef

David Cournapeau wrote:

> Notice how the recursive is referenced through a typedef. In C, this
> is solved by forward declaring the struct through a typedef before the
> struct declaration. But AFAIK, you can't do that in cython.

Not sure about Cython, but the following works in Pyrex:

   cdef struct foo

   ctypedef foo foo_t

   cdef struct foo:
     foo_t *f

i.e. although you can't forward-declare and typedef
in one go, you can forward declare the struct and
then typedef it.

--

-- 
Greg
Robert Bradshaw | 2 Dec 2008 06:07
Favicon

Re: [Cython] Recursive structure, typedef


On Dec 1, 2008, at 3:27 PM, Greg Ewing wrote:

> David Cournapeau wrote:
>
>> Notice how the recursive is referenced through a typedef. In C, this
>> is solved by forward declaring the struct through a typedef before  
>> the
>> struct declaration. But AFAIK, you can't do that in cython.
>
> Not sure about Cython, but the following works in Pyrex:
>
>    cdef struct foo
>
>    ctypedef foo foo_t
>
>    cdef struct foo:
>      foo_t *f

Yes, this works in Cython too.

- Robert

David Cournapeau | 3 Dec 2008 07:57
Picon
Gravatar

Re: [Cython] Recursive structure, typedef

On Tue, Dec 2, 2008 at 2:07 PM, Robert Bradshaw
<robertwb@...> wrote:

>> Not sure about Cython, but the following works in Pyrex:
>>
>>    cdef struct foo
>>
>>    ctypedef foo foo_t
>>
>>    cdef struct foo:
>>      foo_t *f
>
> Yes, this works in Cython too.

Ok, thanks, that should solve my problem.

David

Gmane