cpython/Modules/_ctypes
Eric Wieser 90d85a9b41
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
2023-02-05 17:10:53 +00:00
..
_ctypes.c gh-99952: [ctypes] fix refcount issues in from_param() result. (#100169) 2023-01-26 00:28:34 -08:00
_ctypes_test.c gh-99952: [ctypes] fix refcount issues in from_param() result. (#100169) 2023-01-26 00:28:34 -08:00
_ctypes_test.h Copy ctypes-0.9.9.4 sources from external into the trunk. 2006-03-08 19:35:11 +00:00
callbacks.c GH-81061: Fix refcount issue when returning None from a ctypes.py_object callback (#13364) 2023-01-09 15:43:04 +05:30
callproc.c Fix ctypes typo in set_exception (#101040) 2023-01-15 20:42:37 +05:30
cfield.c gh-78878: Fix crash when creating an instance of _ctypes.CField (#14837) 2022-12-21 23:01:17 +05:30
ctypes.h gh-99337: Fix compile errors with gcc 12 on macOS (#99470) 2022-11-21 10:50:20 +01:00
malloc_closure.c gh-99337: Fix compile errors with gcc 12 on macOS (#99470) 2022-11-21 10:50:20 +01:00
stgdict.c gh-76961: Fix the PEP3118 format string for ctypes.Structure (#5561) 2023-02-05 17:10:53 +00:00