Skip to content

gh-135906: Use _PyObject_CAST in internal CPython headers #135892

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 7 commits into from
Jul 7, 2025

Conversation

clin1234
Copy link
Contributor

@clin1234 clin1234 commented Jun 24, 2025

Fixes build errors encountered in python-greenlet/greenlet#450 when building greenlet against CPython 3.14.0b3 free-threaded. Resolves #135906

@clin1234 clin1234 requested a review from Fidget-Spinner as a code owner June 24, 2025 13:32
@python-cla-bot
Copy link

python-cla-bot bot commented Jun 24, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Jun 24, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@picnixz
Copy link
Member

picnixz commented Jun 24, 2025

Please open an issue in this tracker.

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

Please also add a blurb entry, per the bot.

@ZeroIntensity ZeroIntensity added the build The build process and cross-build label Jun 24, 2025
@clin1234 clin1234 changed the title Use _Py_STATIC_CAST in internal CPython headers Use _PyObject_CAST in internal CPython headers Jun 25, 2025
@clin1234 clin1234 changed the title Use _PyObject_CAST in internal CPython headers gh-135906: Use _PyObject_CAST in internal CPython headers Jun 25, 2025
Copy link

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

looks good

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

I see some similar issues elsewhere:

PyObject *op = _PyFreeList_PopNoStats(fl);

PyObject *obj = FT_ATOMIC_LOAD_PTR(ref->wr_object);

PyObject *obj = FT_ATOMIC_LOAD_PTR(ref->wr_object);

Theoretically, we could test for this by including internal headers in test_cppext, but I haven't decided whether I think that's a good idea yet. I'm worried that we're going to be encouraging people to use the private API. Which APIs does Greenlet need?

…CWq.rst Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
@clin1234
Copy link
Contributor Author

clin1234 commented Jun 26, 2025

I see some similar issues elsewhere:

PyObject *op = _PyFreeList_PopNoStats(fl);

PyObject *obj = FT_ATOMIC_LOAD_PTR(ref->wr_object);

PyObject *obj = FT_ATOMIC_LOAD_PTR(ref->wr_object);

Theoretically, we could test for this by including internal headers in test_cppext, but I haven't decided whether I think that's a good idea yet. I'm worried that we're going to be encouraging people to use the private API. Which APIs does Greenlet need?

This:

https://github.com/python-greenlet/greenlet/blob/b24e39c992e1758032bd913bf7c03d239c29480b/src/greenlet/TGreenlet.hpp#L30-L37

@ZeroIntensity
Copy link
Member

Ok. For 3.15, please open an issue requesting that those private APIs be exposed as unstable APIs.

@Fidget-Spinner
Copy link
Member

Ok. For 3.15, please open an issue requesting that those private APIs be exposed as unstable APIs.

They don't need to open a new issue. This is a known issue with Cython reporting it as well #130931

@Fidget-Spinner
Copy link
Member

Fidget-Spinner commented Jun 27, 2025

I would be happy to merge this (I won't block it). However, we should have some way to make sure we don't regress. pycore_interpframe.h seems to be used by greenlet and Cython which makes it a big enough use case.

@ZeroIntensity
Copy link
Member

I think including pycore_interpframe.h (or pycore_interp_structs.h) in test_cppext would work as a good regression test.

@vstinner
Copy link
Member

vstinner commented Jul 3, 2025

I think including pycore_interpframe.h (or pycore_interp_structs.h) in test_cppext would work as a good regression test.

I wrote test_cppext to test the public C API (headers). Please don't include the internal C API in test_cppext, or add new tests.

Co-authored-by: Victor Stinner <vstinner@python.org>
@ZeroIntensity
Copy link
Member

Hm, why not? Wouldn't it be easier if we were able to catch regressions immediately instead of Cython or Greenlet complaining to us later?

@vstinner
Copy link
Member

vstinner commented Jul 3, 2025

I mean that I would prefer to leave existing test_cppext unchanged. But you can add new tests on the internal C API if you want.

@vstinner
Copy link
Member

vstinner commented Jul 3, 2025

I wrote #136247 to test the internal C API in test_cext.

So far, I failed to test the internal C API with C++, I get many compiler errors from mimalloc headers and I'm not sure how to handle them.

@ZeroIntensity
Copy link
Member

I think we can ignore mimalloc. Nobody--even Cython--is using that with the internal headers.

@vstinner
Copy link
Member

vstinner commented Jul 3, 2025

I think we can ignore mimalloc. Nobody--even Cython--is using that with the internal headers.

mimalloc is included indirectly by many internal headers such as pycore_interp.h.

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

This change on its own looks good to me. We'll figure out testing this in #136247.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@ZeroIntensity ZeroIntensity merged commit fe187fa into python:main Jul 7, 2025
46 checks passed
@miss-islington-app
Copy link

Thanks @clin1234 for the PR, and @ZeroIntensity for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 7, 2025
…35892) Fixes build errors encountered in python-greenlet/greenlet#450 when building greenlet on the free-threaded build. --------- (cherry picked from commit fe187fa) Co-authored-by: Charlie Lin <tuug@gmx.us> Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-app
Copy link

bedevere-app bot commented Jul 7, 2025

GH-136392 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Jul 7, 2025
@clin1234 clin1234 deleted the cpp_trivial branch July 7, 2025 17:03
ZeroIntensity added a commit that referenced this pull request Jul 7, 2025
GH-136392) gh-135906: Use `_PyObject_CAST` in internal headers (GH-135892) Fixes build errors encountered in python-greenlet/greenlet#450 when building greenlet on the free-threaded build. --------- (cherry picked from commit fe187fa) Co-authored-by: Charlie Lin <tuug@gmx.us> Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build The build process and cross-build
6 participants