homepage

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 mark.dickinson
Recipients mark.dickinson, meador.inge
Date 2012年06月21日.09:13:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1340270015.73.0.680065532366.issue15119@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2012年06月21日 09:13:35mark.dickinsonsetrecipients: + mark.dickinson, meador.inge
2012年06月21日 09:13:35mark.dickinsonsetmessageid: <1340270015.73.0.680065532366.issue15119@psf.upfronthosting.co.za>
2012年06月21日 09:13:34mark.dickinsonlinkissue15119 messages
2012年06月21日 09:13:33mark.dickinsoncreate

AltStyle によって変換されたページ (->オリジナル) /