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
[BUG] Link-time issues when Cython output compiled as C++ #4111
Comments
This does look to turn up in our Appveyor CI logs (for Python version 3.7, 3.8, 3.9):
It's only an issue on Windows I think - presumably GCC doesn't mangle this kind of symbol. I think whether it's ultimately a Python bug or not, it should be fixed in Cython since there are enough Python versions with this unguarded code in the wild. |
Maybe we should use cython/Cython/Utility/ModuleSetupCode.c Lines 787 to 789 in cd6e29d
That has the advantage that it's both documented and in the correct C++ guards |
Okay, so would you like the
Would you like me to take a look at doing this? Plus, yes, it does have the correct guards. |
To me the It looks like this is already tested on appveyor (https://ci.appveyor.com/project/cython/cython) so I don't think there's any need to add specific tests. |
Or possibly don't do anything until a decision has been made on the Python bug... |
Okay, so given my PR got a positive review, it seems this is likely to go in ... However, we still have:
I can take a look at this |
…sues cython#4111 Signed-off-by: Andrew V. Jones <andrew.jones@vector.com>
I also searched for other occurrences of the The only difference that I can see is that Given that we are talking about either |
Overview
I recently created the following BPO:
as well as associated PR:
to fix (what I felt was) a bug in (at least) Python 3.8/Python 3.9.
However, I received push-back from at least one commenter on the Python mailing list that the issue was discussing was an "API misuse" of
Python.h
(maybe that's true).Anyway, since this came about because of Cython, I thought it was worth discussing it here.
Actual issue
If you Cythonate something like:
then you end-up with some code that looks like this in your output:
And where
Py_ISSPACE
has an expansion like:(in
pyctype.h
)and where the variable
_Py_ctype_table
looks like this:Problematically, the inclusion of (
cpython
)pyctype.h
inPython.h
does not guard_Py_ctype_table
against the case of C++ compilation.This then leads to the following issue:
/TP
if you're using Visual Studio)Python38.lib
This then falls apart because Python38.lib has a un-name-mangled version of
_Py_ctype_table
, while your Cythonated code has C++-name-managled version of_Py_ctype_table
, which means the linker cannot resolve the symbol, giving a link time error:Resolution
Without changing the use of
Py_ISSPACE
within Cython, I feel that the only solution is to change the generated C code to look like this:Personally, given that other files downstream of
Python.h
do haveextern "C"
, I felt that this really is a Python bug rather than a "user" bug.However, I'm sharing this in here in case my feelings are off-base and, indeed, this is a Cython bug.
If this is considered a Cython bug, I'm more than happy to make a PR with the above change.
The text was updated successfully, but these errors were encountered: