Message163315
It looks as though there's a bug in the ctypes bitfield layout algorithm. After:
>>> from ctypes import Structure, c_int, c_short
>>> class BITS(Structure):
... _fields_ = [("A", c_int, 17), ("M", c_short, 1)]
...
I get:
>>> BITS.M
<Field type=c_short, ofs=2:17, bits=1>
which doesn't make a lot of sense (17th bit of a short?) This causes a negative shift operation when trying to access the .M field of an instance of this structure (see issue 9530 and in particular msg163303).
On this machine (OS X 10.6, 64-bit build of Python using the system gcc (4.2) with no special compiler flags), the corresponding struct in a simple C test program has size 4:
#include <stdio.h>
struct {
int A : 17;
short B: 1;
} flags;
int main(void) {
printf("sizeof flags is: %ld\n", sizeof(flags));
return 0;
}
So it looks like everything gets packed into that first int. At a guess, BITS.M should therefore look like <Field type=c_int, ofs=0:17, bits=1> instead.
System info:
Python 3.3.0a4+ (default:2035c5ad4239+, Jun 21 2012, 08:30:36)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information. |
|
Date |
User |
Action |
Args |
2012-06-21 09:13:35 | mark.dickinson | set | recipients:
+ mark.dickinson, meador.inge |
2012-06-21 09:13:35 | mark.dickinson | set | messageid: <1340270015.73.0.680065532366.issue15119@psf.upfronthosting.co.za> |
2012-06-21 09:13:34 | mark.dickinson | link | issue15119 messages |
2012-06-21 09:13:33 | mark.dickinson | create | |
|