[Pyrex] Extension type initialization

khinsen at cea.fr khinsen at cea.fr
Mon Mar 14 10:40:46 CET 2005


I have been playing with extension types in Pyrex a bit and I have come 
to the conclusion that the __init__ method needs to be a Python 
function (def) rather than a C function (cdef). If I try cdef, I get 
either a crash or a wrong initialization.

First question: is this a design choice or a bug?

My reason for playing with this is that I would like to have an 
optimized way to create new objects from the methods inside my 
extension type. Object creation from Python might well be slow, that 
doesn't matter, but most of my objects will be created inside the 
methods, and I don't want to go through a series of conversions of ints 
and floats to Python objects for calling __init__ and then the inverse 
inside __init__, after useless typechecks.

Second question: is there a way to create an object from an extension 
type and initialize it in C code, without calling __init__, or more 
precisely without any Python overhead other than for object creation 
itself?

Konrad.
--
---------------------------------------------------------------------
Konrad Hinsen
Laboratoire Léon Brillouin, CEA Saclay,
91191 Gif-sur-Yvette Cedex, France
Tel.: +33-1 69 08 79 25
Fax: +33-1 69 08 82 61
E-Mail: khinsen at cea.fr
---------------------------------------------------------------------




More information about the Pyrex mailing list