Skip to content

Commit b161abc

Browse files
jimmodpgeorge
authored andcommitted
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 68f166d commit b161abc

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy