2022-08-18 06:57:45 +00:00
|
|
|
import sys
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2017-02-14 22:56:22 +00:00
|
|
|
try:
|
|
|
|
import uctypes
|
|
|
|
except ImportError:
|
|
|
|
print("SKIP")
|
2017-06-10 17:14:16 +00:00
|
|
|
raise SystemExit
|
2014-06-28 00:03:47 +00:00
|
|
|
|
2022-08-18 06:57:45 +00:00
|
|
|
if sys.byteorder != "little":
|
2014-10-06 17:35:46 +00:00
|
|
|
print("SKIP")
|
2017-06-10 17:14:16 +00:00
|
|
|
raise SystemExit
|
2014-10-06 17:35:46 +00:00
|
|
|
|
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
|
|
|
|
2018-08-29 16:38:14 +00:00
|
|
|
print(addr == int(S.ptr))
|
|
|
|
print(addr == int(S.ptr2))
|
|
|
|
|
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)
|
2020-03-23 02:26:08 +00:00
|
|
|
print(S.ptr2[0].b, S.ptr2[1].b)
|
2014-06-28 00:03:47 +00:00
|
|
|
print(hex(S.ptr16[0]))
|
|
|
|
assert (S.ptr2[0].b, S.ptr2[1].b) == (48, 49)
|