This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Mike.Castle
Recipients Mike.Castle
Date 2012-07-26.07:24:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1343287497.79.0.127552089432.issue15453@psf.upfronthosting.co.za>
In-reply-to
Content
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).
History
Date User Action Args
2012-07-26 07:24:57Mike.Castlesetrecipients: + Mike.Castle
2012-07-26 07:24:57Mike.Castlesetmessageid: <1343287497.79.0.127552089432.issue15453@psf.upfronthosting.co.za>
2012-07-26 07:24:57Mike.Castlelinkissue15453 messages
2012-07-26 07:24:56Mike.Castlecreate