[Pyrex] C-methods in extension types
Lenard Lindstrom
len-l at telus.net
Mon Feb 20 23:42:54 CET 2006
def methods are exposed to Python. cdef methods are callable only
from within a Pyrex module, but are a faster. The cdef __new__ bug is
already known. def __new__ is a special method that the Pyrex
compiler handles differently. Pyrex does't recognize cdef __new__ as
special.
Lenard Lindstrom
<len-l at telus.net>
On 20 Feb 2006 at 15:56, Helmut Jarausch wrote:
> 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
>
> _______________________________________________
> Pyrex mailing list
> Pyrex at lists.copyleft.no
> http://lists.copyleft.no/mailman/listinfo/pyrex
>
More information about the Pyrex
mailing list