[Pyrex] C-methods in extension types

Helmut Jarausch jarausch at skynet.be
Tue Feb 21 13:58:14 CET 2006


Many thanks,

but how, then, can I solve the following problem?
I have

cdef extern from "estraier.h" :
  ctypedef struct ESTDOC :
    pass
  ESTDOC *est_mtdb_get_doc(int id)

cdef class Document:
  cdef ESTDOC *doc

Now, in some method of another class
I want to call est_mtdb_get_doc and
create a new instance of Document
where 'doc' holds the return value of
est_mtdb_get_doc

Is there a simple solution or do I need that
complicated business of (un)wrapping an opaque pointer
by PyCObject_FromVoidPtr or PyCObject_AsVoidPtr ?

Many thanks for a hint,
Helmut.



On 21 Feb, Greg Ewing wrote:
> 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.


-- 
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany




More information about the Pyrex mailing list