-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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-97588: Move ctypes struct/union layout logic to Python #123352
Conversation
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.
First round of comments on the C side. I'll do the Python files now.
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.
The way you construct the layout depends on whether it's a union or a struct and whether it's gcc or ms layout. I'm not sure whether it's easier to maintain one huge function or if you want to create separate factories. AFACIT, it could be easier for instance to have a function that determines whether it's a gcc layout or not, one function that is responsible for parsing _align_
and one function responsible for the _pack_
attribute. For the rest, they can be kept inside the get_layout
function.
For the loop over the input fields, I don't know whether you want to keep a single one or factor it out (it could be clearer to review, but it will likely cause more code so I'm fine with the current implementation).
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
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.
Thank you for the review!
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Thank you for the reviews! |
RC2 is delayed. I'll merge now, if buildbots pass. |
The "now" being in at least 8 hours 😆 |
As discussed in #97702, moving this logic to Python should make it easier to fix the various struct layout bugs in ctypes.
This PR should be strictly a refactoring of the code in
main
, except the_ctypes.CField
class can now be instantiated from Python.