[issue29753] Ctypes Packing Bitfields Incorrectly - Linux
Sam Price
report at bugs.python.org
Thu Mar 5 11:19:19 EST 2020
Sam Price <thesamprice at gmail.com> added the comment:
I ran into this bug on mac and submitted a duplicate issue of 39858
If you add the check *pfield_size != *pbitofs it fixes this bug.
#ifndef MS_WIN32
} else if (bitsize /* this is a bitfield request */
&& *pfield_size /* we have a bitfield open */
&& *pfield_size != *pbitofs /* Current field has been filled, start new one */
&& dict->size * 8 >= *pfield_size
&& (*pbitofs + bitsize) <= dict->size * 8) {
/* expand bit field */
fieldtype = EXPAND_BITFIELD;
#endif
However this would not fix the results where you expand a bitfield around 3 bytes.
clang produces the 3 bytes if you try and expand around.
#include <stdint.h>
#include <stdio.h>
typedef struct testA{
uint8_t a0 : 7;
uint8_t a1 : 7;
uint8_t a2 : 7;
uint8_t a3 : 3;
} __attribute__((packed)) testA;
int main(){
printf("%d\n", sizeof(testA)); /* Prints out 3 */
return 0;
}
python prints out a size of 4.
----------
nosy: +thesamprice
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue29753>
_______________________________________
More information about the Python-bugs-list
mailing list