summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2022-10-18 00:18:54 +1100
committerDamien George <damien@micropython.org>2022-10-25 14:46:04 +1100
commitb161abc574b8e4fb2b00ef76be2b9c8967e18584 (patch)
tree66831ea9bf8216b11b26f3edfea8de910e932121
parent68f166dae9ad6dfd94038d5f4394defbb44238af (diff)
py/obj: Verify floating point type is correct for repr C.
Prevents double-precision floats being enabled on 32-bit architectures where they will not fit into the mp_obj_t encoding. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
-rw-r--r--py/obj.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/py/obj.h b/py/obj.h
index 8aa5b0a8e..8d62dd4f3 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -173,6 +173,10 @@ static inline bool mp_obj_is_obj(mp_const_obj_t o) {
#elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C
+#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_NONE
+#error "MICROPY_OBJ_REPR_C requires float to be enabled."
+#endif
+
static inline bool mp_obj_is_small_int(mp_const_obj_t o) {
return (((mp_int_t)(o)) & 1) != 0;
}
@@ -189,6 +193,9 @@ static inline bool mp_obj_is_small_int(mp_const_obj_t o) {
#endif
static inline bool mp_obj_is_float(mp_const_obj_t o) {
+ // Ensure that 32-bit arch can only use single precision.
+ MP_STATIC_ASSERT(sizeof(mp_float_t) <= sizeof(mp_obj_t));
+
return (((mp_uint_t)(o)) & 3) == 2 && (((mp_uint_t)(o)) & 0xff800007) != 0x00000006;
}
static inline mp_float_t mp_obj_float_get(mp_const_obj_t o) {