Commit 827daa8f authored by Stefan Behnel's avatar Stefan Behnel

update "external C code" docs

parent 19244e2c
...@@ -224,11 +224,11 @@ and provide the Python user with Python functions of the same names. ...@@ -224,11 +224,11 @@ and provide the Python user with Python functions of the same names.
Cython provides a couple of different ways of solving this problem. The best Cython provides a couple of different ways of solving this problem. The best
way, especially if you have many C functions to wrap, is to put the extern way, especially if you have many C functions to wrap, is to put the extern
C function declarations into a ``.pxd`` file and thus a different namespace, C function declarations into a ``.pxd`` file and thus a different namespace,
using the facilities described in the section on sharing declarations between using the facilities described in :ref:`sharing declarations between Cython
Cython modules. Writing them into a ``.pxd`` file allows their reuse across modules <sharing-declarations>`. Writing them into a ``.pxd`` file allows
modules, avoids naming collisions in the normal Python way and even makes it their reuse across modules, avoids naming collisions in the normal Python way
easy to rename them on cimport. For example, if your ``decl.pxd`` file and even makes it easy to rename them on cimport. For example, if your
declared a C function ``eject_tomato``:: ``decl.pxd`` file declared a C function ``eject_tomato``::
cdef extern from "myheader.h": cdef extern from "myheader.h":
void eject_tomato(float speed) void eject_tomato(float speed)
...@@ -247,6 +247,9 @@ or simply cimport the ``.pxd`` file and use it as prefix:: ...@@ -247,6 +247,9 @@ or simply cimport the ``.pxd`` file and use it as prefix::
def eject_tomato(speed): def eject_tomato(speed):
decl.eject_tomato(speed) decl.eject_tomato(speed)
Note that this has no runtime lookup overhead, as it would in Python.
Cython resolves the names in the ``.pxd`` file at compile time.
For special cases where namespacing or renaming on import is not enough, For special cases where namespacing or renaming on import is not enough,
e.g. when a name in C conflicts with a Python keyword, you can use a C name e.g. when a name in C conflicts with a Python keyword, you can use a C name
specification to give different Cython and C names to the C function at specification to give different Cython and C names to the C function at
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment