[Pyrex] Cannot cdef __init__?
Paul Prescod
paul at prescod.net
Sun Jan 18 19:04:21 CET 2004
Andrew Bennetts wrote:
> On Sat, Jan 17, 2004 at 11:23:16PM -0800, Paul Prescod wrote:
>
>>Andrew Bennetts wrote:
>>
>>
>>>--- footest.pyx ---
>>>cdef extern from "foo.h":
>>> ctypedef struct pair
>>
>>I think that this should be "cdef struct pair" not "ctypedef struct pair".
>
>
> I get "Syntax error in C variable declaration" when I try this.
cdef extern from "foo.h":
cdef struct pair:
int x
int y
Sorry, I forgot to say that you should actually define some subset of
the structure. Otherwise, how will you set and get the members from
Pyrex code? I'll append the entire file that works for me.
Paul Prescod
cdef extern from "foo.h":
cdef struct pair:
int x
int y
cdef class Pair:
cdef pair p
cdef class Fred:
cdef Pair p
def __init__(self, Pair p):
self.p = p
cdef x(self):
pass
def foo(self):
return self.p.x + self.p.y
def test(a, b):
return Fred(Pair(a, b))
print test(3, 4)
struct pair{
int x;
int y;
};
More information about the Pyrex
mailing list