Skip to content

gh-92898: Make _Py_Cast C++ version compatible with cast operator #92951

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

Merged
merged 1 commit into from
May 21, 2022

Conversation

serge-sans-paille
Copy link
Contributor

Use the adequate kind of cast based on the macro argument: const ref, cont
pointer, ref or pointer.

This should be compatible with C++ overloads.

Fix #92898

@serge-sans-paille
Copy link
Contributor Author

cc @vstinner

@corona10 corona10 requested review from vstinner and corona10 May 19, 2022 13:24
@corona10 corona10 added skip news needs backport to 3.11 only security fixes and removed skip news labels May 19, 2022
Copy link
Member

@corona10 corona10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you like to add NEWS.d about compatible?

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@serge-sans-paille
Copy link
Contributor Author

@corona10 I'm not sure, there's already an entry

.. date: 2022-04-26-16-51-31
.. gh-issue: 91320
.. nonce: QDHmTv
.. section: C API

Fix C++ compiler warnings about "old-style cast" (``g++ -Wold-style-cast``)
in the Python C API. Use C++ ``reinterpret_cast<>`` and ``static_cast<>``
casts when the Python C API is used in C++. Patch by Victor Stinner.

And this is just patching that entry

@tacaswell
Copy link
Contributor

I am now seeing errors compiling numpy with this branch:

      In file included from /home/tcaswell/.pybuild/bleeding/include/python3.12/Python.h:38,
                       from numpy/core/include/numpy/npy_common.h:5,
                       from numpy/core/include/numpy/npy_math.h:8,
                       from numpy/core/src/npysort/selection.cpp:18:
      /home/tcaswell/.pybuild/bleeding/include/python3.12/pyport.h:31:1: error: template with C linkage
         31 | template <typename type, typename expr_type>
            | ^~~~~~~~
      numpy/core/include/numpy/npy_math.h:5:1: note: ‘extern "C"’ linkage started here
          5 | extern "C" {
            | ^~~~~~~~~~
      /home/tcaswell/.pybuild/bleeding/include/python3.12/pyport.h:36:1: error: template with C linkage
         36 | template <typename type, typename expr_type>
            | ^~~~~~~~
      numpy/core/include/numpy/npy_math.h:5:1: note: ‘extern "C"’ linkage started here
          5 | extern "C" {
            | ^~~~~~~~~~
      /home/tcaswell/.pybuild/bleeding/include/python3.12/pyport.h:41:1: error: template with C linkage
         41 | template <typename type, typename expr_type>
            | ^~~~~~~~
      numpy/core/include/numpy/npy_math.h:5:1: note: ‘extern "C"’ linkage started here
          5 | extern "C" {
            | ^~~~~~~~~~
      /home/tcaswell/.pybuild/bleeding/include/python3.12/pyport.h:46:1: error: template with C linkage
         46 | template <typename type, typename expr_type>
            | ^~~~~~~~
      numpy/core/include/numpy/npy_math.h:5:1: note: ‘extern "C"’ linkage started here
          5 | extern "C" {
            | ^~~~~~~~~~

g++ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DNPY_INTERNAL_BUILD=1 -DHAVE_NPY_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -DNO_ATLAS_INFO=1 -DHAVE_CBLAS -I/usr/local/include -I/home/tcaswell/.virtualenvs/bleeding/include -Ibuild/src.linux-x86_64-3.12/numpy/core/src/multiarray -Ibuild/src.linux-x86_64-3.12/numpy/core/src/common -Ibuild/src.linux-x86_64-3.12/numpy/core/src/umath -Inumpy/core/include -Ibuild/src.linux-x86_64-3.12/numpy/core/include/numpy -Ibuild/src.linux-x86_64-3.12/numpy/distutils/include -Ibuild/src.linux-x86_64-3.12/numpy/core/src/npysort -Inumpy/core/src/common -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -Inumpy/core/src/_simd -I/home/tcaswell/.virtualenvs/bleeding/include -I/home/tcaswell/.pybuild/bleeding/include/python3.12 -Ibuild/src.linux-x86_64-3.12/numpy/core/src/common -Ibuild/src.linux-x86_64-3.12/numpy/core/src/npymath -c numpy/core/src/npysort/selection.cpp -o build/temp.linux-x86_64-3.12/numpy/core/src/npysort/selection.o -MMD -MF build/temp.linux-x86_64-3.12/numpy/core/src/npysort/selection.o.d -msse -msse2 -msse3 -std=c++11 -D__STDC_VERSION__=0 -fno-exceptions -fno-rtti

@serge-sans-paille
Copy link
Contributor Author

@tacaswell indeed. I can work around this :-)

@tacaswell
Copy link
Contributor

@serge-sans-paille I should note this is with numpy main, I have not gone back to see if released versions work or not.

Use the adequate kind of cast based on the macro argument: const ref, cont
pointer, ref or pointer.

This should be compatible with C++ overloads.

Fix python#92898
@serge-sans-paille
Copy link
Contributor Author

@tacaswell should be good now?

@tacaswell
Copy link
Contributor

Through numpy, starting scipy. Will update if the whole environment builds cleanly (including greenlet main).

@tacaswell
Copy link
Contributor

It built clean including master-branch greenlet 👍🏻

@miss-islington
Copy link
Contributor

Thanks @serge-sans-paille for the PR, and @corona10 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry @serge-sans-paille and @corona10, I had trouble checking out the 3.11 backport branch.
Please backport using cherry_picker on command line.
cherry_picker 5b71b519f966e1017c868ea2b27c61a5eac38c1f 3.11

corona10 pushed a commit to corona10/cpython that referenced this pull request May 21, 2022
… operator (pythongh-92951)

(cherry picked from commit 5b71b51)

Co-authored-by: serge-sans-paille <serge.guelton@telecom-bretagne.eu>
@vstinner
Copy link
Member

I created a follow-up PR: #93111

@hauntsaninja hauntsaninja added needs backport to 3.11 only security fixes and removed needs backport to 3.11 only security fixes labels Dec 24, 2022
@miss-islington
Copy link
Contributor

Thanks @serge-sans-paille for the PR, and @corona10 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @serge-sans-paille and @corona10, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 5b71b519f966e1017c868ea2b27c61a5eac38c1f 3.11

@terryjreedy terryjreedy removed the needs backport to 3.11 only security fixes label Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

changes to PyObject casting macros causing build failures with python-greenlet
8 participants