New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ctypes bitfield problem #54198
Comments
The following program should print "0xdead" but instead prints "0x0". This came from the following stackoverflow question: import ctypes
class Blah(ctypes.Structure):
_fields_ = [("a", ctypes.c_uint64, 64),
("b", ctypes.c_uint16, 16),
("c", ctypes.c_uint8, 8),
("d", ctypes.c_uint8, 8)]
x = Blah(0xDEAD,0xBEEF,0x44,0x12)
print(hex(x.a)) |
An endian issue? (i.e. on OS X, it works on ppc but not Intel) $ more test_ctypes.py
import ctypes
class Blah2(ctypes.Structure):
_fields_ = [("x", ctypes.c_uint64, 64),
("y", ctypes.c_uint64)]
val = 0x0123456789ABCDEF
x = Blah2(val, val)
print(Blah2.x)
print(hex(x.x))
print(Blah2.y)
print(hex(x.y))
$ arch -i386 python2.7 test_ctypes.py
<Field type=c_ulonglong, ofs=0:0, bits=64>
0x0L
<Field type=c_ulonglong, ofs=8, size=8>
0x123456789abcdefL
$ arch -x86_64 python2.7 test_ctypes.py
<Field type=c_ulong, ofs=0:0, bits=64>
0x0L
<Field type=c_ulong, ofs=8, size=8>
0x123456789abcdefL
$ arch -ppc python2.7 test_ctypes.py
<Field type=c_ulonglong, ofs=0:0, bits=64>
0x123456789abcdefL
<Field type=c_ulonglong, ofs=8, size=8>
0x123456789abcdefL |
Could be. FWIW, I had tested and observed the problem on a 32-bit Intel Windows box and 64-bit Intel Linux box. |
I think this issue is duplicate of bpo-6493. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: