-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-97588: Move ctypes struct/union layout logic to Python #123352
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
Changes from 1 commit
Commits
Show all changes
95 commits
Select commit
Hold shift + click to select a range
ac1d0a3
Add classes that will implement the struct packing
encukou b35a97c
Instantiate the layout and take `_align_` from it
encukou 2cc8b40
Get base size and align; etc.
encukou a9fd94a
Sorta start creating CField objects
encukou c4d3c66
Turn constructor into initializer
encukou cbb3081
Use goto for error handling
encukou 1adb23a
Handle Py_DECREF(prop) in the error block
encukou 01ee4f8
Pass bit_size and name to CField
encukou eb7666c
Use name from prop
encukou be6113f
Use desc from prop
encukou a7f05f9
Use bit_size from prop; avoid pair
encukou ef24a0c
Pass None for undefined bit_size, not -1
encukou 728ec0a
Fix a refleak
encukou 5ef81b3
Move bitsize check to CField initializer
encukou 16c2d77
desc is proto
encukou 14fd92d
Remove the unused TYPEFLAG_HASBITFIELD and TYPEFLAG_HASUNION
encukou e3337c2
Use -1 for "not is_bitfield"
encukou f3c678d
Handle _swappedbytes_ in Python
encukou 0c47fa2
Put layout mode in the field
encukou 2eefab1
error handling
encukou 5b1723c
Take out is_bitfield arg
encukou 9507752
Keep _pack_ on the field
encukou dc859c3
Stick the index in the struct
encukou beeab0b
Add packstate struct, with pfield_size
encukou accb589
Put pbitoffs in the state
encukou 71fbfb8
Put the size in the state
encukou 9c6e3b0
Add offset to the state
encukou a6f8fdc
Put align in the state
encukou 6803815
Move getfunc/setfunc to __new__
encukou e0fc0af
Start verifying the internal pack state
encukou a6814b7
Put offset & align in for the simple cases
encukou 3771721
Remove unnecessary condition
encukou ca4d40f
Move bitsize calculation to the algorithm
encukou 3e3eec8
finish
encukou 3853c38
Copy the GCC/SysV algorithm to (ugly) Python code
encukou a8ad714
Copy the MS algorithm to (ugly) Python code
encukou 5be7edf
Remove the C code
encukou 7218287
Move assertion & big-endian adjustment
encukou addf44c
Move assertions out
encukou d92831a
Remove PyCField_InitFromDesc
encukou 466d82f
Remove field_size, bitofs, offset from the pack state
encukou 1af5db3
Remove pack from C code
encukou df3143d
Make _layout_ return an object with fields
encukou a22c557
Avoid self.* assignments
encukou 47150d2
Pass size and align from Python
encukou c244045
Remove some more of the packstate
encukou 903c0fa
Remove align from the state
encukou 551a6ed
Compute padding in Python
encukou 0bb7797
Move union_size to Python
encukou 9bc45c5
Remove the C state
encukou 7a76a8e
Set up for checking format
encukou cdd028c
Compute the format spec in Python
encukou 4de515f
Fix refcounting/error handling
encukou adbe019
Remove the format calculations from C
encukou c1644b6
Return the aligned size from Python
encukou 4c29379
layout_fields is a tuple
encukou c2e54a8
Borrow from the layout_fields tuple
encukou 61a33d3
Use stuff from prop, not pair
encukou f3f3622
Remove use of pair
encukou 34edfd8
Only pass fields to Python, do nothing else with it
encukou 833edf4
Don't pass forced_align
encukou 779fa81
Remove scaffolding members from CFieldObject
encukou 7b3926e
Unify the bit_size variable
encukou 5f351e7
Start simplifying the Python code
encukou d2f0da3
Remove state_align
encukou 4b346d4
Make it a bit clearer yet
encukou 95d9c54
More cleanup
encukou af5c52b
Simplify C call using borrowed references
encukou 51a4042
Use _Py_ID for the literals
encukou 5a805cd
Use floordiv, not int(truediv), for non-negative numbers
encukou 12fd84a
Use a data class + function
encukou e4ad839
Warning comment
encukou c1ba0e8
Remove test scaffolding
encukou 25ceb4b
CField is instantiable now
encukou 54640c3
PEP-8
encukou e62bb02
Move a comment over to its code
encukou e0b0de0
Remove unused function
encukou 51b7568
PEP-7, typo, align comments
encukou 60c5557
Merge in the main branch
encukou 1092d68
Regenerate global objects
encukou 6820d23
Avoid BytesWarning
encukou 12311ad
Move an assertion after a check
encukou 4921407
Remove unused field, bit_size
encukou ff4bcf5
Apply suggestions from code review
encukou 6b9a8b7
Move bit_size checks to assertions; they're checked in Python
encukou 991bab3
Move `i` declaration to for loops
encukou 298c822
Remove a clearly unneeded assert
encukou 3088e5d
Add rudimentary test for bitfields in Union
encukou 511e25d
Improve error message for _field_ element unpacking
encukou 0689e59
Use correct length modifier
encukou a7c3724
Avoid a case where MSC and GCC's __attribute__((ms_struct)) disagree
encukou bd53c28
Adjust Windows assertions
encukou b387d30
Apply suggestions from code review
encukou 9cf18cd
Remove unused last_field
encukou 96a5c0d
Remove the bitfield-in-union test, for now
encukou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Move union_size to Python
- Loading branch information
commit 0bb7797a57aacee01662a8335980fff7a20ddbaf
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.