2014-10-06 19:30:46 +00:00
|
|
|
import sys
|
2017-02-14 22:56:22 +00:00
|
|
|
try:
|
|
|
|
import uctypes
|
|
|
|
except ImportError:
|
|
|
|
print("SKIP")
|
|
|
|
sys.exit()
|
2014-06-28 00:03:47 +00:00
|
|
|
|
2014-10-06 17:35:46 +00:00
|
|
|
if sys.byteorder != "little":
|
|
|
|
print("SKIP")
|
|
|
|
sys.exit()
|
|
|
|
|
2014-06-28 00:03:47 +00:00
|
|
|
desc = {
|
|
|
|
"ptr": (uctypes.PTR | 0, uctypes.UINT8),
|
|
|
|
"ptr16": (uctypes.PTR | 0, uctypes.UINT16),
|
|
|
|
"ptr2": (uctypes.PTR | 0, {"b": uctypes.UINT8 | 0}),
|
|
|
|
}
|
|
|
|
|
|
|
|
bytes = b"01"
|
|
|
|
|
|
|
|
addr = uctypes.addressof(bytes)
|
2016-12-09 19:53:30 +00:00
|
|
|
buf = addr.to_bytes(uctypes.sizeof(desc), "little")
|
2014-06-28 00:03:47 +00:00
|
|
|
|
2015-06-06 19:57:31 +00:00
|
|
|
S = uctypes.struct(uctypes.addressof(buf), desc, uctypes.LITTLE_ENDIAN)
|
2014-06-28 00:03:47 +00:00
|
|
|
|
|
|
|
print(S.ptr[0])
|
|
|
|
assert S.ptr[0] == ord("0")
|
|
|
|
print(S.ptr[1])
|
|
|
|
assert S.ptr[1] == ord("1")
|
|
|
|
print(hex(S.ptr16[0]))
|
|
|
|
assert hex(S.ptr16[0]) == "0x3130"
|
|
|
|
print(S.ptr2[0].b, S.ptr2[1].b)
|
|
|
|
print (S.ptr2[0].b, S.ptr2[1].b)
|
|
|
|
print(hex(S.ptr16[0]))
|
|
|
|
assert (S.ptr2[0].b, S.ptr2[1].b) == (48, 49)
|