Skip to content
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

Use PEP-697 interface to access stashed data in type objects #211

Merged
merged 4 commits into from
May 25, 2023
Merged

Conversation

wjakob
Copy link
Owner

@wjakob wjakob commented May 10, 2023

This commit currently fails because the CI still builds against Python 3.12a7 that doesn't yet have PEP697. It will be merged once the GHA setup-python action has caught up with 3.12 beta

PEP 697 introduced a new limited C API to extend opaque types. nanobind needs this feature because it stashes internal type data structures within Python type objects. Previously, we assumed a standard Python memory layout for such opaque types and did not do anything special besides adding an offset to get to the nanobind part.

However, such an approach is not acceptable when using nanobind to compile future-proof stable ABI wheels: the Python team may at some point significantly refactor the layout and internals of type objects, which would lead to undefined behavior in combination with our assumptions. This commit therefore switches to the recently introduced official interface that ensures long-term stability.

@wjakob wjakob force-pushed the pep_697 branch 2 times, most recently from 0bd03d2 to 7504a0d Compare May 25, 2023 14:32
wjakob added 4 commits May 25, 2023 16:37
PEP 697 introduced a new limited C API to extend opaque types. nanobind
needs this feature because it stashes internal type data structures
within Python ``type`` objects. Previously, we assumed a standard
Python memory layout for such opaque types and did not do anything
special besides adding an offset to get to the nanobind part.

However, such an approach is not acceptable when using nanobind to
compile future-proof stable ABI wheels: the Python team may at some
point significantly refactor the layout and internals of ``type``
objects, which would lead to undefined behavior in combination with our
assumptions. This commit therefore switches to the recently introduced
official interface that ensures long-term stability.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant