[Pyrex] C-methods in extension types
Helmut Jarausch
jarausch at skynet.be
Mon Feb 20 15:56:12 CET 2006
Hi,
I'm new to Pyrex and I don't understand the difference
between a Python method (declared by 'def') and a
C method (declared by 'cdef')
My very first example was this little iterator test
cdef class IT:
cdef int From
cdef int To
cdef int count
cdef int Step
def __new__(self,From,To,reversed=0):
if reversed:
self.Step= -1
self.From= To+1
self.To = From
else:
self.Step= 1
self.From= From-1
self.To = To
def __iter__(self):
self.count= self.From
return self
def __next__(self):
if self.count == self.To :
raise StopIteration
# return NULL # signal STopIteration
else :
self.count= self.count + self.Step
return self.count
which works just fine.
But when I try e.g.
cdef __new__(self,int From,int To,int reversed):
if reversed:
self.Step= -1
self.From= To+1
self.To = From
else:
self.Step= 1
self.From= From-1
self.To = To
Then pyrexc doesn't cry but compiles invalid code:
the function which is put into the tp_new slot
calls the __new__ method with only 3 arguments
(which gcc doesn't like)
What am I missing?
Many thanks for a hint,
Helmut Jarausch
Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
More information about the Pyrex
mailing list