[New-bugs-announce] [issue15453] ctype with packed bitfields does not match native compiler

Mike Castle report at bugs.python.org
Thu Jul 26 09:24:57 CEST 2012


New submission from Mike Castle <dalgoda at gmail.com>:

On debian/testing with python 2.7.3rc2 and gcc 4.7.1.

I was trying to use ctypeslib to wrap libdvdnav and running into some issues porting my test C code to Python, eventually tracking it down to this difference between how ctypes and gcc handles bitfields in packed structs (i.e., affects real world problems).

Basically, by default, gcc treats 8, 16 and 32 bit types in bit fields as 1 byte when using __attribute__ ((packed)) , while ctypes treats them each as 1, 2 and 4 bytes even when using _pack_ = 1.  (and libdvdnav using packed a lot)

Output from the attached programs:

$ ./a.out
1
1
1
$ ./t.py
1
2
4

Removing the packed attribute or building with gcc -mms-bitfields both match the ctypes expectations (though -mms-bitfields is probably rarely used in Linux).

----------
components: ctypes
files: t.py
messages: 166462
nosy: Mike.Castle
priority: normal
severity: normal
status: open
title: ctype with packed bitfields does not match native compiler
versions: Python 2.6, Python 2.7
Added file: http://bugs.python.org/file26521/t.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15453>
_______________________________________


More information about the New-bugs-announce mailing list