Repository navigation
ctypes: bit field data does not survive round trip #97588
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Sep 27, 2022 - added a commit that references this issue
on Sep 27, 2022 matthiasgoergens commented
on Sep 27, 2022 ContributorAuthorMore actionsSince 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.
matthiasgoergens commented
on Sep 27, 2022 ContributorAuthorMore actionsAs far as I can tell the problem might be with
PyCField_FromDescincfield.c. The code looks both a bit complicated and is not expected to be a hot inner loop (it's only for setting up aStructurefrom a description.) So perhaps we might want to move most of its logic into Python.Let's me dig some more.
- changed the title
[-]ctypes: data does not survice round trip[/-][+]ctypes: bit field data does not survice round trip[/+]on Sep 27, 2022 - added a commit that references this issue
on Oct 1, 2022 @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.
matthiasgoergens commented
on Oct 8, 2022 ContributorAuthorMore actions@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.
- changed the title
[-]ctypes: bit field data does not survice round trip[/-][+]ctypes: bit field data does not survive round trip[/+]on Oct 9, 2022 matthiasgoergens commented
on Oct 9, 2022 ContributorAuthorMore actions@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?
@matthiasgoergens Could you review pull request !103052
matthiasgoergens commented
on Mar 27, 2023 ContributorAuthorMore actions@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 .
matthiasgoergens commented
on Mar 27, 2023 ContributorAuthorMore actionsOh, 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
matthiasgoergens commented
on Mar 27, 2023 ContributorAuthorMore actions@thesamprice I added your tests from #103052 to this PR, too. I hope you don't mind.
- added a commit that references this issue
on May 29, 2024 Thank you for the report, and the initial fix!
The layout calculation is now done in Python, and a test suite is in place, so we're in a better place to solve the other struct/union layout issues. I'll close this one.Reacted by Matthias GörgensReacted by Matthias Görgens- added a commit that references this issue
on Sep 12, 2024
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
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
mainare 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