2014-10-06 15:30:46 -04:00
|
|
|
import sys
|
2021-04-20 01:22:44 -04:00
|
|
|
|
2017-02-14 17:56:22 -05:00
|
|
|
try:
|
|
|
|
import uctypes
|
|
|
|
except ImportError:
|
|
|
|
print("SKIP")
|
2017-06-10 13:14:16 -04:00
|
|
|
raise SystemExit
|
2014-06-27 20:03:47 -04:00
|
|
|
|
2014-10-06 13:35:46 -04:00
|
|
|
if sys.byteorder != "little":
|
|
|
|
print("SKIP")
|
2017-06-10 13:14:16 -04:00
|
|
|
raise SystemExit
|
2014-10-06 13:35:46 -04:00
|
|
|
|
2014-06-27 20:03:47 -04: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 14:53:30 -05:00
|
|
|
buf = addr.to_bytes(uctypes.sizeof(desc), "little")
|
2014-06-27 20:03:47 -04:00
|
|
|
|
2015-06-06 15:57:31 -04:00
|
|
|
S = uctypes.struct(uctypes.addressof(buf), desc, uctypes.LITTLE_ENDIAN)
|
2014-06-27 20:03:47 -04:00
|
|
|
|
2018-08-29 12:38:14 -04:00
|
|
|
print(addr == int(S.ptr))
|
|
|
|
print(addr == int(S.ptr2))
|
|
|
|
|
2014-06-27 20:03:47 -04: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)
|
2021-04-20 01:22:44 -04:00
|
|
|
print(S.ptr2[0].b, S.ptr2[1].b)
|
2014-06-27 20:03:47 -04:00
|
|
|
print(hex(S.ptr16[0]))
|
|
|
|
assert (S.ptr2[0].b, S.ptr2[1].b) == (48, 49)
|