[Pyrex] Function decorations

Christian Heimes lists at cheimes.de
Sun Mar 18 01:13:52 UTC 2007


Peter Waller schrieb:
> Or even better, can I just embed plain C code in my pyrex?

You can split your extension in a C file and pyrex file. It's very easy
with pyrex and distutils. :]

For example I've written an optimized C version of my crypttea module
that implements the algorithms in C. I've a ctea.c and ctea.h file which
contain the C code for the decryption and encryption functions. The
_pyxtea.pyx file is the glue code between the C functions and Python.

My setup.py file looks like:

from setuptools import setup
from setuptools import Extension

cxtea = Extension('crypttea._pyxtea',
    ['src/crypttea/_pyxtea.pyx', 'src/crypttea/ctea.c']
    )

setup(...
     ext_modules=[cxtea],
     )

HTH
Christian




More information about the Pyrex mailing list