-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Closed
Description
class Foo(ctypes.Structure):
_fields_ = [('one', ctypes.c_uint8), ('two', ctypes.c_uint32)]
_pack_ = 2
>>> ctypes.sizeof(Foo()) # packed to alignment 2
6
>>> np.dtype(Foo).itemsize # default alignment incorrectly used
8
Fix should be fairly straightforward by changing:
numpy/numpy/core/_dtype_ctypes.py
Lines 35 to 46 in 44810f0
def _from_ctypes_structure(t): | |
# TODO: gh-10533, gh-10532 | |
fields = [] | |
for item in t._fields_: | |
if len(item) > 2: | |
raise TypeError( | |
"ctypes bitfields have no dtype equivalent") | |
fname, ftyp = item | |
fields.append((fname, dtype_from_ctypes_type(ftyp))) | |
# by default, ctypes structs are aligned | |
return np.dtype(fields, align=True) |