8000 py/obj: Verify floating point type is correct for repr C. · jimmo/micropython@3d9ff68 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3d9ff68

Browse files
committed
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>
1 parent 89b3207 commit 3d9ff68

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

py/obj.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ static inline bool mp_obj_is_obj(mp_const_obj_t o) {
173173

174174
#elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C
175175

176+
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_NONE
177+
#error "MICROPY_OBJ_REPR_C requires float to be enabled."
178+
#endif
179+
176180
static inline bool mp_obj_is_small_int(mp_const_obj_t o) {
177181
return (((mp_int_t)(o)) & 1) != 0;
178182
}
@@ -189,6 +193,9 @@ static inline bool mp_obj_is_small_int(mp_const_obj_t o) {
189193
#endif
190194

191195
static inline bool mp_obj_is_float(mp_const_obj_t o) {
196+
// Ensure that 32-bit arch can only use single precision.
197+
MP_STATIC_ASSERT(sizeof(mp_float_t) <= sizeof(mp_obj_t));
198+
192199
return (((mp_uint_t)(o)) & 3) == 2 && (((mp_uint_t)(o)) & 0xff800007) != 0x00000006;
193200
}
194201
static inline mp_float_t mp_obj_float_get(mp_const_obj_t o) {

0 commit comments

Comments
 (0)
0