New submission from Mike Castle <dalg...@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 <rep...@bugs.python.org>
<http://bugs.python.org/issue15453>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to