Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling a .py file with an augmenting .pxd leads to a mangled function name for cdef public function. #2940

Open
Jivko1212 opened this issue Apr 30, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@Jivko1212
Copy link

commented Apr 30, 2019

I would like to use the .py, with augmenting .pxd method for my Cython project so I can debug and use an IDE while I develop. For some reason this method leads to mangled exported function names. The definition of the function in the .pxd is cdef public int count_cwrap(int limit) and the .h file produced has this definition __PYX_EXTERN_C int __pyx_f_19pythagorean_triples_count_cwrap(int); If I convert the file to .pyx and add the cython definition, the name is not mangled anymore. I tried it and this occurs in both Linux and Windows. I am attaching my source code to reproduce the issue.

pythagorean_triples.py:

# cython: language_level=3
import time
import cython
import numpy as np
 
def count(limit):
    if limit < 3:
       raise ValueError('Invalid limit value')
    arr = np.zeros(10)
    result : cython.int = 0
    a : cython.int
    b : cython.int
    c : cython.int
    for a in range(1, limit + 1):
        for b in range(a + 1, limit + 1):
            for c in range(b + 1, limit + 1):
                if c * c > a * a + b * b:
                    break
 
                if c * c == (a * a + b * b):
                    result += 1
    return result
	
def count_cwrap(limit):
    return count(limit)
 
if __name__ == '__main__':
    start = time.time()
    result = count(1000)
    duration = time.time() - start
    print(result, duration)

pythagorean_triples.pxd:

# cython: language_level=3
cdef public int count_cwrap(int limit)

setup.py:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
 
setup(
    ext_modules = cythonize(Extension('pythagorean_triples', sources = ['pythagorean_triples.py']))
)

Is this a bug or am I doing something wrong perhaps in the setup.py?

I built with python setup_py.py build_ext --inplace in windows or with
python3 setup_py.py build_ext --inplace in Linux

Thanks

@scoder

This comment has been minimized.

Copy link
Contributor

commented Apr 30, 2019

Thanks for the report. Could be that the private marker is simply not copied when adapting the Python function signature from the .pxd file in AlignFunctionDefinitions syntax tree transformation (ParseTreeTransforms.py). Probably easy to add there. PR welcome.

@scoder

This comment has been minimized.

Copy link
Contributor

commented Apr 30, 2019

Here is an example of a test file that you could borrow from. It's just a bunch of files stuffed into one that the test runner extracts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.