Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-111506: Add _Py_OPAQUE_PYOBJECT to hide PyObject layout & related API#136505

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
encukou merged 5 commits intopython:mainfromencukou:opaque-pyobject-priv
Jul 12, 2025

Conversation

encukou
Copy link
Member

@encukouencukou commentedJul 10, 2025
edited by bedevere-appbot
Loading

Make it so that defining_Py_OPAQUE_PYOBJECT before including<Python.h> will make thePyObject struct opaque, and hide all limited-API structs & functions that need access to it.

Also, allowPy_LIMITED_API withPy_GIL_DISABLED if_Py_OPAQUE_PYOBJECT is defined.

Opaque PyObject will be needed for most alternatives we have of defining a Stable ABI for free-threaded builds. SeeDiscourse thread for discussion. (We may want to either expose this to users asPy_OPAQUE_PYOBJECT, or define it implicitly for limited-API free-threaded builds.)
And if I'm wrong -- this is easy to remove, like likePy_GIL_DISABLED.

AsI mentioned, I'd like to put this inmain to avoid rebasing a fork and to make it easier to build on top.

API that's removed when _Py_OPAQUE_PYOBJECT is defined:    - PyObject_HEAD    - _PyObject_EXTRA_INIT    - PyObject_HEAD_INIT    - PyObject_VAR_HEAD    - struct _object (i.e. PyObject) (opaque)    - struct PyVarObject (opaque)    - Py_SIZE    - Py_SET_TYPE    - Py_SET_SIZE    - PyModuleDef_Base (opaque)    - PyModuleDef_HEAD_INIT    - PyModuleDef (opaque)    - _Py_IsImmortal    - _Py_IsStaticImmortalNote that the `_Py_IsImmortal` removal means _Py_OPAQUE_PYOBJECTonly works with limited API 3.14+ now.
@encukou
Copy link
MemberAuthor

We can also test this (with a workaround/hack in the test for themissing part).

@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@encukou for commit33d9ae7 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F136505%2Fmerge

If you want to schedule another build, you need to add the🔨 test-with-buildbots label again.

@bedevere-botbedevere-bot removed the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelJul 11, 2025
@encukou
Copy link
MemberAuthor

The tests aren'tthat straightforward, but the workaround can still be removed if we either scrap the “opaque PyObject” idea or implement PEP 793.
@vstinner, are you OK with having this workaround in tests in main, it order to test thatPython.h compiles with opaque PyObject (and except forPyModuleDef, it can produce working extensions)?

Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

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

I like the overall approach of the _Py_OPAQUE_PYOBJECT macro. I'm fine with testing it in test_cext.

encukou reacted with heart emoji
# Test with _Py_OPAQUE_PYOBJECT
self.check_build('_test_limited_opaque_cext', limited=True, opaque=True)

def check_build(self, extension_name, std=None, limited=False, opaque=False):
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to rename "opaque" to "opaque_pyobject" (also in _check_build).

@@ -45,6 +45,9 @@ def main():
std = os.environ.get("CPYTHON_TEST_STD", "")
module_name = os.environ["CPYTHON_TEST_EXT_NAME"]
limited = bool(os.environ.get("CPYTHON_TEST_LIMITED", ""))
opaque = bool(os.environ.get("CPYTHON_TEST_OPAQUE_PYOBJECT", ""))
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to rename opaque to opaque_pyobject.

@@ -75,6 +78,12 @@ def main():
version = sys.hexversion
cflags.append(f'-DPy_LIMITED_API={version:#x}')

# Define _Py_OPAQUE_PYOBJECT macro
if opaque:
version = sys.hexversion
Copy link
Member

Choose a reason for hiding this comment

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

version is not used, it can be removed.

@encukouencukou merged commitc7d24b8 intopython:mainJul 12, 2025
39 checks passed
@encukouencukou deleted the opaque-pyobject-priv branchJuly 12, 2025 07:55
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull requestJul 12, 2025
…lated API (pythonGH-136505)Allow Py_LIMITED_API for (Py_GIL_DISABLED && _Py_OPAQUE_PYOBJECT)API that's removed when _Py_OPAQUE_PYOBJECT is defined:    - PyObject_HEAD    - _PyObject_EXTRA_INIT    - PyObject_HEAD_INIT    - PyObject_VAR_HEAD    - struct _object (i.e. PyObject) (opaque)    - struct PyVarObject (opaque)    - Py_SIZE    - Py_SET_TYPE    - Py_SET_SIZE    - PyModuleDef_Base (opaque)    - PyModuleDef_HEAD_INIT    - PyModuleDef (opaque)    - _Py_IsImmortal    - _Py_IsStaticImmortalNote that the `_Py_IsImmortal` removal (and a few other issues) means _Py_OPAQUE_PYOBJECT only works with limitedAPI 3.14+ now.Co-authored-by: Victor Stinner <vstinner@python.org>
picnixz pushed a commit to picnixz/cpython that referenced this pull requestJul 13, 2025
…lated API (pythonGH-136505)Allow Py_LIMITED_API for (Py_GIL_DISABLED && _Py_OPAQUE_PYOBJECT)API that's removed when _Py_OPAQUE_PYOBJECT is defined:    - PyObject_HEAD    - _PyObject_EXTRA_INIT    - PyObject_HEAD_INIT    - PyObject_VAR_HEAD    - struct _object (i.e. PyObject) (opaque)    - struct PyVarObject (opaque)    - Py_SIZE    - Py_SET_TYPE    - Py_SET_SIZE    - PyModuleDef_Base (opaque)    - PyModuleDef_HEAD_INIT    - PyModuleDef (opaque)    - _Py_IsImmortal    - _Py_IsStaticImmortalNote that the `_Py_IsImmortal` removal (and a few other issues) means _Py_OPAQUE_PYOBJECT only works with limitedAPI 3.14+ now.Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@vstinnervstinnervstinner left review comments

@ericsnowcurrentlyericsnowcurrentlyAwaiting requested review from ericsnowcurrentlyericsnowcurrently is a code owner

Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@encukou@bedevere-bot@vstinner

[8]ページ先頭

©2009-2025 Movatter.jp