[Pyrex] C-methods in extension types

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Feb 21 00:33:06 CET 2006


Helmut Jarausch wrote:

 > I don't understand the difference
 > between a Python method (declared by 'def') and a
 > C method (declared by 'cdef')

Python methods can be called from Python code,
whereas C methods can't.

 >   cdef __new__(self,int From,int To,int reversed):
 >
 > Then pyrexc doesn't cry but compiles invalid code:

That's a bug in Pyrex. Special methods like __new__
should never be declared with cdef, and Pyrex shouldn't
let you try.

Where methods are concered, cdef should only be
used for non-special methods of your own devising,
that will only be called by other Pyrex code. The
advantage is that calling cdef methods is much more
efficient, since it's just an indirect C function
call rather than a full-blown Python call.

Greg



More information about the Pyrex mailing list