Charles Machalow added the comment:

Some more debug with print statements in the c code seems to confirm my 
suspicion:

bitsize, pfield_size, bitofs, dict->size prints were added just above the if 
chain to determine fieldtype and fieldtype was just after that if chain. That 
code looks something like this:

printf("bitsize: %d\n" , (int)bitsize);
printf("pfield_size: %u\n", (size_t)*pfield_size);
printf("bitofs: %d\n", (int)*pbitofs);
printf("dict->size: %d\n", (int)dict->size);
    if (bitsize /* this is a bitfield request */
        && *pfield_size /* we have a bitfield open */
#ifdef MS_WIN32
        /* MSVC, GCC with -mms-bitfields */
        && dict->size * 8 == *pfield_size
#else
        /* GCC */
        && dict->size * 8 <= *pfield_size
#endif
        && (*pbitofs + bitsize) <= *pfield_size) {
        /* continue bit field */
        fieldtype = CONT_BITFIELD;
#ifndef MS_WIN32
    } else if (bitsize /* this is a bitfield request */
        && *pfield_size /* we have a bitfield open */
        && dict->size * 8 >= *pfield_size
        && (*pbitofs + bitsize) <= dict->size * 8) {
        /* expand bit field */
        fieldtype = EXPAND_BITFIELD;
#endif
    } else if (bitsize) {
        /* start new bitfield */
        fieldtype = NEW_BITFIELD;
        *pbitofs = 0;
        *pfield_size = dict->size * 8;
    } else {
        /* not a bit field */
        fieldtype = NO_BITFIELD;
        *pbitofs = 0;
        *pfield_size = 0;
    }

printf("Fieldtype: %d\n------\n", fieldtype);

And the run with the custom-built Python 2.7.13:

>>> from test import *
bitsize: 0
pfield_size: 0
bitofs: 255918304
dict->size: 2
Fieldtype: 0
------
bitsize: 9
pfield_size: 0
bitofs: 0
dict->size: 2
Fieldtype: 1
------
bitsize: 1
pfield_size: 16
bitofs: 9
dict->size: 2
Fieldtype: 2
------
bitsize: 1
pfield_size: 16
bitofs: 10
dict->size: 2
Fieldtype: 2
------
bitsize: 1
pfield_size: 16
bitofs: 11
dict->size: 2
Fieldtype: 2
------
bitsize: 1
pfield_size: 16
bitofs: 12
dict->size: 2
Fieldtype: 2
------
bitsize: 3
pfield_size: 16
bitofs: 13
dict->size: 2
Fieldtype: 2
------
bitsize: 10
pfield_size: 16
bitofs: 16
dict->size: 4
Fieldtype: 3
------
bitsize: 20
pfield_size: 32
bitofs: 26
dict->size: 4
Fieldtype: 1
------
bitsize: 2
pfield_size: 32
bitofs: 20
dict->size: 4
Fieldtype: 2
------
10
>>> MyStructure.P
<Field type=c_ushort, ofs=0, size=2>
>>> MyStructure.T
<Field type=c_uint, ofs=2:16, bits=10>
>>> MyStructure.R
<Field type=c_ushort, ofs=2:13, bits=3>
>>> MyStructure.P
<Field type=c_ushort, ofs=0, size=2>
>>> MyStructure.L
<Field type=c_ushort, ofs=2:0, bits=9>
>>> MyStructure.Pro
<Field type=c_ushort, ofs=2:9, bits=1>
>>> MyStructure.R
<Field type=c_ushort, ofs=2:13, bits=3>
>>> MyStructure.T
<Field type=c_uint, ofs=2:16, bits=10>
>>> MyStructure.C
<Field type=c_uint, ofs=6:0, bits=20>

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29753>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to