Discussion:
[Cython] [Desired feature] Process .pxd before .py
Alexandru Ionut Grama
2014-08-26 15:45:41 UTC
Permalink
Hello to all

I've start to use cython in order to use call some API modules written in
python from C/C++. Those modules written in python must remain untouched,
and all .py files should be "decorated" with their counterpart .pxd files.
I would like to mark as public some API functions from .py files, following
the indications from http://docs.cython.org/src/tutorial/pxd_files.html.
I've started to write a little example:

suma_alex.py:
def suma_Alex(a,b):
return a+b

suma_alex.pxd:
cdef public int suma_Alex(int a,int b)


The combination of those two files should turn into something like this for
the compiler:

cdef public int suma_Alex(int a,int b):
return a+b

On generated .h file I should obtain a function prototype like this:
__PYX_EXTERN_C DL_IMPORT(int) suma_Alex(int, int);

Instead of that, I obtain a prototype like this:
__PYX_EXTERN_C DL_IMPORT(int) __pyx_f_10suma_alex_suma_Alex(int, int);

Digging into code and executing cythonize with pdb, I followed that is
executed a pipeline for .py file before .pxd file's pipeline. Correct me if
I'm wrong, but this makes the name of .c function be generated according to
py file instead of pxd file. That makes an add of string
"__pyx_f_10suma_alex_" before function name, because the compiler doesn't
know about "public" key (on python doesn't exists). Including public key on
a pxd file for this function makes the compiler remove "static" key and
generate a .h file, but doesn't change the name prototype into a simple
"suma_Alex".

If I use cython on a pyx file containing the code below, it works perfectly
as expected.
cdef public int suma_Alex(int a,int b):
return a+b

The questions are:
- I'm doing what I want to do on a right way?
- Is this feature included on cython development version? I've tried on
0.20.2
- If is not implemented, I want to colaborate implementing it. Could you
please provide me some guidelines with the methods/modules that I should
modify?

King regards,
Alexandru.
--
*---------------------------------------------------------------Alexandru
Ionut Grama**email: gramaalexandruionut-***@public.gmane.org
<gramaalexandruionut-***@public.gmane.org>*
Stefan Behnel
2014-08-28 14:57:44 UTC
Permalink
Post by Alexandru Ionut Grama
I've start to use cython in order to use call some API modules written in
python from C/C++. Those modules written in python must remain untouched,
and all .py files should be "decorated" with their counterpart .pxd files.
I would like to mark as public some API functions from .py files, following
the indications from http://docs.cython.org/src/tutorial/pxd_files.html.
return a+b
cdef public int suma_Alex(int a,int b)
The combination of those two files should turn into something like this for
return a+b
__PYX_EXTERN_C DL_IMPORT(int) suma_Alex(int, int);
__PYX_EXTERN_C DL_IMPORT(int) __pyx_f_10suma_alex_suma_Alex(int, int);
Looks like a bug to me. There is a step in the pipeline that merges the
.pxd file declarations into those found in the main source file. Either the
"public" modifier is not properly copied over or the cname needs to be
updated when merging in the override declarations.

Stefan
Alexandru Ionut Grama
2014-08-28 18:35:04 UTC
Permalink
Post by Alexandru Ionut Grama
Post by Alexandru Ionut Grama
I've start to use cython in order to use call some API modules written in
python from C/C++. Those modules written in python must remain untouched,
and all .py files should be "decorated" with their counterpart .pxd
files.
Post by Alexandru Ionut Grama
I would like to mark as public some API functions from .py files,
following
Post by Alexandru Ionut Grama
the indications from http://docs.cython.org/src/tutorial/pxd_files.html.
return a+b
cdef public int suma_Alex(int a,int b)
The combination of those two files should turn into something like this
for
Post by Alexandru Ionut Grama
return a+b
__PYX_EXTERN_C DL_IMPORT(int) suma_Alex(int, int);
__PYX_EXTERN_C DL_IMPORT(int) __pyx_f_10suma_alex_suma_Alex(int, int);
Looks like a bug to me.
There is a step in the pipeline that merges the
Post by Alexandru Ionut Grama
.pxd file declarations into those found in the main source file. Either the
"public" modifier is not properly copied over or the cname needs to be
updated when merging in the override declarations.
Hi Stefan,
Thanks for the answer at first.
If is a bug, do you need more information in order to check it? Could you
tell me the methods that are used to merge the override declarations for
investigate by myself and create a patch to correct the bug?

Is there a workaround that maybe solve this?

King regards,
Alexandru
Post by Alexandru Ionut Grama
Stefan
_______________________________________________
cython-devel mailing list
https://mail.python.org/mailman/listinfo/cython-devel
--
*---------------------------------------------------------------Alexandru
Ionut Grama**email: gramaalexandruionut-***@public.gmane.org
<gramaalexandruionut-***@public.gmane.org>*
Loading...