-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
gh-89188: replace bitfield with struct fields in PyASCIIObject #102589
Conversation
/* Padding to ensure that PyUnicode_DATA() is always aligned to | ||
4 bytes (see issue #19537 on m68k). */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment on alignment seemed important, so I created a test in _testinternalcapi.c
which I believe codifies this.
14c79d4
to
4dd82a4
Compare
Looks like I may not have got the gdb lib changes exactly right, I can take another look at those on a Linux system once I've had some input on whether this direction is feasible, i.e. I know it's worth me spending the time to debug. |
I don't find the Rust argument convincing -- we should expose good API functions, rather than make internal structs easy to use. Or is there a performance-sensitive use case? (If there is we might want to add some higher-level API for it, rather than making you play with bits.) I do think this should change. Exposing compiler-implementation-defined behavior in the API is a ticking bomb. IMO, if it changes it should change to bit masks. With this PR, there's no way to add an additional unrelated flag. (And one might be needed soon for static/immortal objects). Both a version with bit masks and the PR as is are an API change. Per PEP 387, it needs a deprecation warning period or a SC exception. Meanwhile, for Rust, you can expose the accessors as actual API functions, while keeping the |
Thanks @encukou, I wasn't aware that this struct would need the deprecation cycle applied. I'll replace this PR with one proposing API functions. To check I understand, as per the |
No, unlike vectorcall, they don't need to be in the limited API/stable ABI. (They can be added later if needed.) |
Superseded by #115211 (which may itself yet be superseded by something else, who knows!) |
Closes #89188
I noticed that
PyASCIIObject.state
is a 32-bit bitfield with 4 members, so I replaced it with 4 separateuint8_t
fields. The advantage of doing this is that C bitfield layout is implementation-defined, which makes it hard to interact with them from non-C languages (e.g. Rust).cc @encukou @vstinner as you participated in the discussion on the original issue, I'd be interested to hear if you think this looks like a suitable solution.