Some structures with bitfields not properly handled by ctypes
Brought to you by:
theller
Hello,
I just found that some very simple packed C structures containing bitfields are not managed as expected by ctypes.
Attached file test5.c defines this structure:
typedef struct __attribute__ ((packed)) { unsigned int F0:24; unsigned int F3:24; unsigned int F6:24; unsigned int F9:24; } StructF_T;
As expected, the memory layout seen by the C program is :
0x111111222222333333444444
Attached file test5.py defines this structure:
class StructF(ctypes.BigEndianStructure): _pack_ = 1 _fields_ = [ ('F0', ctypes.c_uint, 24), ('F3', ctypes.c_uint, 24), ('F6', ctypes.c_uint, 24), ('F9', ctypes.c_uint, 24), ]
The memory layout seen from Python is not consistent :
0x11111100222222003333330044444400
The layout is the same using ctypes.LittleEndianStructure.
Any idea ?
Marc
The missing attachment :
Last edit: Marc Le Roy 2017-11-08