[Pyrex] C-API implementation in Pyrex 0.9.6
Gustavo Sverzut Barbieri
barbieri at gmail.com
Fri Oct 12 18:40:55 CEST 2007
On 10/11/07, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> William Stein wrote:
> > (1) Suppose I would like to define a cdef'd function in a module
> > arith.pyx that I want
> > to call from other .pyx files, e.g.,
> >
> > cdef int fast_gcd(int a, int b):
> > ...
> >
> > Then I basically want to do this sort of thing from other .pyx files:
> > from arith cimport fast_gcd
> > int x = fast_gcd(5,7)
>
> Yes. You can do that by declaring fast_gcd in a .pxd file, e.g.
>
> # arith.pxd
> cdef int fast_gcd(int, int)
>
> # arith.pyx
> cdef int fast_gcd(int a, int b):
> ...
>
> # anothermodule.pyx
> from arith cimport fast_gcd
> x = fast_gcd(5,7)
>
> That's all you need to do. No linking is required.
Is this a 0.9.6 feature? I remember that before you couldn't get cdef
functions (not methods!) to be accessed by 3rd party modules, even if
defined as "public". And as you say we don't need linking, so this
must enter the python namespace and be discovered at run time, am I
correct? If this is the case, wouldn't be great to at least request
"public" in cdef declaration?
--
Gustavo Sverzut Barbieri
--------------------------------------
Jabber: barbieri at gmail.com
MSN: barbieri at gmail.com
ICQ#: 17249123
Skype: gsbarbieri
Mobile: +55 (81) 9927 0010
More information about the Pyrex
mailing list