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-120600: Make Py_TYPE() opaque in limited C API 3.14#120601

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
vstinner merged 2 commits intopython:mainfromvstinner:stable_abi_type
Jun 18, 2024

Conversation

@vstinner
Copy link
Member

@vstinnervstinner commentedJun 16, 2024
edited
Loading

In the limited C API 3.14 and newer, Py_TYPE() and Py_SET_TYPE() are now implemented as opaque function calls to hide implementation details.


📚 Documentation preview 📚:https://cpython-previews--120601.org.readthedocs.build/

In the limited C API 3.14 and newer, Py_TYPE() is now implemented asan opaque function call to hide implementation details.
@vstinner
Copy link
MemberAuthor

Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

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

There isPyObject_Type().

@vstinner
Copy link
MemberAuthor

There is PyObject_Type().

I don't understand your remark. Are you suggesting to reimplement Py_TYPE() on top of PyObject_Type()? Py_TYPE() returns a borrowed reference, PyObject_Type() returns a strong reference.

@serhiy-storchaka
Copy link
Member

Py_TYPE was defined as a macro, it depends on the internal structure of PyObject. If you need to use the limited C API, use PyObject_Type() instead of Py_TYPE().

@vstinner
Copy link
MemberAuthor

Py_TYPE was defined as a macro, it depends on the internal structure of PyObject. If you need to use the limited C API, use PyObject_Type() instead of Py_TYPE().

Py_TYPE() is very commonly used in C extensions. Having to switch to PyObject_Type() is a lot of work. I don't want to force C extensions maintainers to do that. I only want to hide the implementation details (access toPyObject.ob_type member, maybe with an atomic operation in Free Threading).

It's not convenient to have to release a reference when using PyObject_Type(), compared to Py_TYPE().

@serhiy-storchaka
Copy link
Member

Has not C API returning a borrowed reference been frowned upon lately? Strictly speaking, Py_TYPE() is incompatible with Free Threading.

If you want to use the limited C API, use PyObject_Type(). If you prefer performance and convenience, use Py_TYPE() and the GIL.

@vstinner
Copy link
MemberAuthor

I don't get it. The stable ABI is guaranteed to be stable. Py_TYPE() is part of the stable ABI. I'm not asking to add it. Only to change its implementation.

@serhiy-storchaka
Copy link
Member

Than what is the point of changingPy_TYPE()? If you do not use the limited C API, you rely on implementation details. If you do not want to rely on them, usePyObject_Type().

@vstinner
Copy link
MemberAuthor

Than what is the point of changing Py_TYPE()?

As written previously, I am trying to avoid accessing PyObject members directly. This change is part of this project, even if it doesn't disallow accessing PyObject members yet.

encukou reacted with thumbs up emoji

Copy link
Member

@encukouencukou left a comment

Choose a reason for hiding this comment

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

+1 from me. Even if we can't change the current version of the stable ABI, moving to functions makes sense.
Exposed structs arethe one biggest issue withabi4; if there's ever a new version of a stable ABI, it probably won't have them.
It would be great if modules compiled for thenext stable ABI are compatible with 3.14, and at the same time stayAPI-compatible.

zooba reacted with thumbs up emoji
@serhiy-storchakaserhiy-storchaka removed the request for review froma teamJune 18, 2024 13:40
Co-authored-by: Petr Viktorin <encukou@gmail.com>
@vstinnervstinnerenabled auto-merge (squash)June 18, 2024 13:42
@vstinnervstinner merged commit16f8e22 intopython:mainJun 18, 2024
@vstinnervstinner deleted the stable_abi_type branchJune 18, 2024 14:28
picnixz pushed a commit to picnixz/cpython that referenced this pull requestJun 19, 2024
…120601)In the limited C API 3.14 and newer, Py_TYPE() is now implemented asan opaque function call to hide implementation details.
mrahtz pushed a commit to mrahtz/cpython that referenced this pull requestJun 30, 2024
…120601)In the limited C API 3.14 and newer, Py_TYPE() is now implemented asan opaque function call to hide implementation details.
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull requestJul 11, 2024
…120601)In the limited C API 3.14 and newer, Py_TYPE() is now implemented asan opaque function call to hide implementation details.
estyxx pushed a commit to estyxx/cpython that referenced this pull requestJul 17, 2024
…120601)In the limited C API 3.14 and newer, Py_TYPE() is now implemented asan opaque function call to hide implementation details.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@encukouencukouencukou approved these changes

@serhiy-storchakaserhiy-storchakaserhiy-storchaka approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@vstinner@serhiy-storchaka@encukou

[8]ページ先頭

©2009-2025 Movatter.jp