[Pyrex] Extension types
Greg Ewing
greg.ewing at canterbury.ac.nz
Thu Sep 22 03:57:31 CEST 2005
Nitin Madnani wrote:
> So I am thinking about implementing all the data structures that I need
> as extension types in Pyrex. Is this going to be equivalent to writing
> my structures in pure C and using swig to create a pyhon module? Is one
> better than the other? Are there any overheads?
If you make all the attributes of your extension type
C attributes and use nothing but C operations on them,
then yes, it will be equivalent.
There will be no more overhead than with SWIG, and
probably less, since your extension type will directly
provide a subclassable OO interface without the need
for Python shadow classes.
Another advantage over SWIG is that Pyrex extension
types are as type-safe as built-in Python types.
(SWIG uses some dubious techniques that make
it possible to crash a SWIG-generated module from
Python code.)
On the other side, SWIG can often be made to generate
a Python interface from existing C header files with
less work than it would take using Pyrex -- although
the resulting interface will be more C-like than
Python-like.
SWIG can also generate modules for other languages
besides Python from the same description, whereas
Pyrex is Python-only. But if you're only interested
in making a Python module, this won't matter.
--
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
greg.ewing at canterbury.ac.nz +--------------------------------------+
More information about the Pyrex
mailing list