-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
ctypes: bit field data does not survive round trip #97588
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
Comments
Since I'm looking into bit-fields and ctypes anyway at the moment, I'll plan to work on a fix. But if someone else wants to give it a go, I'm happy to let them. |
As far as I can tell the problem might be with Let's me dig some more. |
@matthiasgoergens I think this is essentially the same issue as existing issues like #95496, #84039, #73939, #59324, etc; it would be good to try to consolidate some of these so we don't end up with an explosion of issues. |
@mdickinson Good idea. That's actually what I am already doing with the fix I have in the works, but consolidating the issues makes sense, too. |
@mdickinson I mentioned the issues that my PR fixes on the PR itself. Is there a way (or necessity) to also consolidate the issues themselves here? |
Mostly for testing against libraries like numpy.
@matthiasgoergens Could you review pull request !103052 |
@thesamprice I'll have a look, but keep in mind that I don't have any authority here. |
More interested if the one line change passes the tests you wrote . |
Oh, ok. Sure, I can run that against my tests. I guess I should publish my Python Hypothesis tests, too; and not just the tests in my PR. So you can run them yourself. Give me a bit of time! Edit: I'll answer over on #103052 |
@thesamprice I added your tests from #103052 to this PR, too. I hope you don't mind. |
Structure layout, and especially bitfields, sometimes resulted in clearly wrong behaviour like overlapping fields. This fixes Co-authored-by: Gregory P. Smith <[email protected]> Co-authored-by: Petr Viktorin <[email protected]>
Structure layout, and especially bitfields, sometimes resulted in clearly wrong behaviour like overlapping fields. This fixes Co-authored-by: Gregory P. Smith <[email protected]> Co-authored-by: Petr Viktorin <[email protected]>
Structure layout, and especially bitfields, sometimes resulted in clearly wrong behaviour like overlapping fields. This fixes Co-authored-by: Gregory P. Smith <[email protected]> Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
Thank you for the report, and the initial fix! |
Bit-fields in structures don't seem to give you back the data you put in?
The above should print
But it actually prints
For comparison and to test my understanding, I expect the following C code to be equivalent to the Python code above:
The C version prints what we expect:
Your environment
I am on ArchLinux with Python 3.10.7. Python 3.11 and
main
are also affected. I also randomly tried Python 3.6 with the same result. (Python 3.6 is the oldest one that was easy to install.)More comprehensive test case
Here's how I actually found the problem reported above. Using Hypothesis:
Thanks to @mdickinson for pointing me in this direction.
Linked PRs
The text was updated successfully, but these errors were encountered: