Title: Ctypes Packing Bitfields Incorrectly - GCC both Linux and Cygwin
Type: behavior Stage: resolved
Components: ctypes Versions: Python 3.6
Status: closed Resolution: duplicate
Dependencies: Superseder: [Linux] ctypes packs bitfields Incorrectly
View: 29753
Assigned To: Nosy List: berker.peksag, mleroy003
Priority: normal Keywords:

Created on 2017-11-08 22:31 by mleroy003, last changed 2017-11-09 11:39 by berker.peksag. This issue is now closed.

Messages (2)
msg305914 - (view) Author: Marc Le Roy (mleroy003) Date: 2017-11-08 22:31
The structure :
typedef struct __attribute__ ((packed)) {
   unsigned int   F0:24;
   unsigned int   F3:24;
   unsigned int   F6:24;
   unsigned int   F9:24;
} StructF_T;
is mapped as expected by GCC under both Linux and Cygwin.
As expected, the memory layout seen by the C program is :

Using this definition :
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 :

It seems that the pack option is ignored by ctypes in such a case.
I found the same problem using both ctypes.BigEndianStructure and ctypes.LittleEndianStructure
msg305957 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-11-09 11:39
Thank you for your report. I believe this is a duplicate of issue 29753.
Date User Action Args
2017-11-09 11:39:58berker.peksagsetstatus: open -> closed

superseder: [Linux] ctypes packs bitfields Incorrectly
type: behavior

nosy: + berker.peksag
messages: + msg305957
resolution: duplicate
stage: resolved
2017-11-08 22:31:58mleroy003create