Skip to content

Don't expose PyASCIIObjectState on Python3.14 and newer #5133

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 3 commits into from
May 12, 2025

Conversation

ngoldbaum
Copy link
Contributor

Fixes #5131.

This changed in between alpha 7 and beta 1: python/cpython#133085

@ngoldbaum
Copy link
Contributor Author

Also set_interned is definitely wrong on the free-threaded build. But also why are we exposing setters at all? The C API doesn't expose setters.

@davidhewitt
Copy link
Member

I wonder, in 3.14 PyUnicode_KIND and PyUnicode_DATA are now exposed as symbols we can call instead of having to decode the bitfield.

Should we just rip out the bitfield decoding on 3.14 (and up) and instead use the API functions? I think we have to drop a couple of the APIs we currently offer, but overall would be a lot less code to maintain, less coupling to cpython details, and a lot sounder.

@ngoldbaum
Copy link
Contributor Author

Should we just rip out the bitfield decoding on 3.14 (and up) and instead use the API functions? I think we have to drop a couple of the APIs we currently offer, but overall would be a lot less code to maintain, less coupling to cpython details, and a lot sounder.

Ah neat, guess I should have checked that.

This seems like a good idea, let me see how hard it is...

@ngoldbaum
Copy link
Contributor Author

This seems like a good idea, let me see how hard it is...

I don't see how to implement PyUnicode_IS_ASCII, PyUnicode_IS_COMPACT and PyUnicode_IS_ASCII_COMPACT without having access to the bitfields....

@ngoldbaum
Copy link
Contributor Author

For whatever reason, ffi-check is broken on 3.14, but only on Windows 🙃

@ngoldbaum
Copy link
Contributor Author

I can't reproduce the 3.14 windows failures on my Windows setup.

@davidhewitt
Copy link
Member

This seems like a good idea, let me see how hard it is...

I don't see how to implement PyUnicode_IS_ASCII, PyUnicode_IS_COMPACT and PyUnicode_IS_ASCII_COMPACT without having access to the bitfields....

I was thinking maybe to make those functions inaccessible on 3.14 +?

I can't reproduce the 3.14 windows failures on my Windows setup.

I will try to find time to look on Monday.

@clin1234
Copy link
Contributor

@ngoldbaum Beat me to the punch; can you grant me commit access to your branch? I was thinking of adding a deprecation message to the entire PyASCIIObject (due to python/cpython#133085). Also this: clin1234@21ce132

@clin1234
Copy link
Contributor

Also, this: https://github.com/python/cpython/blob/3.14/Include/cpython/unicodeobject.h#L102-L162
The state member has to be aligned in 4-byte boundaries for non-GIL builds, and I don't think the numerous brittle bit-twiddling functions to convert between pyo3's u32 state and struct PyASCIIObjectState are suitable in the long-term.

@ngoldbaum ngoldbaum removed the CI-skip-changelog Skip checking changelog entry label May 11, 2025
@ngoldbaum ngoldbaum changed the title fix FFI PyUnicode bindings for 3.14.0b1 Don't expose PyASCIIObjectState on Python3.14 and newer May 11, 2025
@ngoldbaum
Copy link
Contributor Author

The last push removes PyASCIIObjectState on Python 3.14 and newer.

I think the mysterious Windows failures went away? The remaining failures are unrelated issues in the jiff tests.

@ngoldbaum
Copy link
Contributor Author

I think the mysterious Windows failures went away?

Spoke too soon. Somehow the thing we did with the bindgen ParseCallbacks to handle the anonymous struct in the ob_refcnt field seems to be breaking, but only on Windows, and only intermittently.

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks, couple of final tweaks and then I think good to merge 👍

The windows ffi check is at least not going to block merge, so I suggest we merge this, ship 0.25, and investigate / clean up separately.

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks!

@davidhewitt davidhewitt enabled auto-merge May 12, 2025 14:23
@davidhewitt davidhewitt added this pull request to the merge queue May 12, 2025
Merged via the queue into PyO3:main with commit f87b286 May 12, 2025
88 of 93 checks passed
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.

PyUnicode and PyASCII tests are failing on 3.14
3 participants