diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2023-02-05 17:10:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-05 17:10:53 (GMT) |
commit | 90d85a9b4136aa1feb02f88aab614a3c29f20ed3 (patch) | |
tree | be37c9c00a26da338ff35621e9e399315e2e64bb /Misc/ACKS | |
parent | 0672a6c23b2b72666e10d9c61fc025e66aad9c2b (diff) | |
download | cpython-90d85a9b4136aa1feb02f88aab614a3c29f20ed3.zip cpython-90d85a9b4136aa1feb02f88aab614a3c29f20ed3.tar.gz cpython-90d85a9b4136aa1feb02f88aab614a3c29f20ed3.tar.bz2 |
gh-76961: Fix the PEP3118 format string for ctypes.Structure (#5561)
The summary of this diff is that it:
* adds a `_ctypes_alloc_format_padding` function to append strings like `37x` to a format string to indicate 37 padding bytes
* removes the branches that amount to "give up on producing a valid format string if the struct is packed"
* combines the resulting adjacent `if (isStruct) {`s now that neither is `if (isStruct && !isPacked) {`
* invokes `_ctypes_alloc_format_padding` to add padding between structure fields, and after the last structure field. The computation used for the total size is unchanged from ctypes already used.
This patch does not affect any existing aligment computation; all it does is use subtraction to deduce the amount of paddnig introduced by the existing code.
---
Without this fix, it would never include padding bytes - an assumption that was only
valid in the case when `_pack_` was set - and this case was explicitly not implemented.
This should allow conversion from ctypes structs to numpy structs
Fixes https://github.com/numpy/numpy/issues/10528
Diffstat (limited to 'Misc/ACKS')
0 files changed, 0 insertions, 0 deletions