mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 04:30:24 +01:00
py/obj: Add functions to retrieve large integers from mp_obj_t.
This commit provides helpers to retrieve integer values from mp_obj_t when the content does not fit in a 32 bits integer, without risking an implicit wrap due to an int overflow. Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
This commit is contained in:
committed by
Damien George
parent
49159ef6b7
commit
c4a88f2ce7
@@ -6,6 +6,16 @@ except NameError:
|
||||
|
||||
import errno
|
||||
import io
|
||||
import uctypes
|
||||
|
||||
# create an int-like variable used for coverage of `mp_obj_get_ll`
|
||||
buf = bytearray(b"\xde\xad\xbe\xef")
|
||||
struct = uctypes.struct(
|
||||
uctypes.addressof(buf),
|
||||
{"f32": uctypes.UINT32 | 0},
|
||||
uctypes.BIG_ENDIAN,
|
||||
)
|
||||
deadbeef = struct.f32
|
||||
|
||||
data = extra_coverage()
|
||||
|
||||
|
||||
@@ -94,6 +94,12 @@ data
|
||||
1
|
||||
0
|
||||
0.000000
|
||||
deadbeef
|
||||
c0ffee777c0ffee
|
||||
deadbeef
|
||||
0deadbeef
|
||||
c0ffee
|
||||
000c0ffee
|
||||
# runtime utils
|
||||
TypeError: unsupported type for __abs__: 'str'
|
||||
TypeError: unsupported types for __divmod__: 'str', 'str'
|
||||
@@ -102,6 +108,8 @@ TypeError: unsupported types for __divmod__: 'str', 'str'
|
||||
2
|
||||
OverflowError: overflow converting long int to machine word
|
||||
OverflowError: overflow converting long int to machine word
|
||||
TypeError: can't convert NoneType to int
|
||||
TypeError: can't convert NoneType to int
|
||||
ValueError:
|
||||
Warning: test
|
||||
# format float
|
||||
|
||||
Reference in New Issue
Block a user