summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2022-08-23 13:09:57 +1000
committerDamien George <damien@micropython.org>2022-08-23 13:09:57 +1000
commit3d65101a8a55550bdbaa4df4e216edba238fa299 (patch)
tree0ad14ee94b939f5c3840aa2e662a0c8c58f75b30
parent7c8ec85fa34279950e44072b22ac26fe41b91886 (diff)
py: Clean up formatting of union definitions.
Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r--py/binary.c22
-rw-r--r--py/obj.h8
2 files changed, 18 insertions, 12 deletions
diff --git a/py/binary.c b/py/binary.c
index f59e89ca4..4c8b6ffcd 100644
--- a/py/binary.c
+++ b/py/binary.c
@@ -241,13 +241,15 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte *p_base, byte *
return mp_obj_new_str(s_val, strlen(s_val));
#if MICROPY_PY_BUILTINS_FLOAT
} else if (val_type == 'f') {
- union { uint32_t i;
- float f;
+ union {
+ uint32_t i;
+ float f;
} fpu = {val};
return mp_obj_new_float_from_f(fpu.f);
} else if (val_type == 'd') {
- union { uint64_t i;
- double f;
+ union {
+ uint64_t i;
+ double f;
} fpu = {val};
return mp_obj_new_float_from_d(fpu.f);
#endif
@@ -308,17 +310,19 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p
break;
#if MICROPY_PY_BUILTINS_FLOAT
case 'f': {
- union { uint32_t i;
- float f;
+ union {
+ uint32_t i;
+ float f;
} fp_sp;
fp_sp.f = mp_obj_get_float_to_f(val_in);
val = fp_sp.i;
break;
}
case 'd': {
- union { uint64_t i64;
- uint32_t i32[2];
- double f;
+ union {
+ uint64_t i64;
+ uint32_t i32[2];
+ double f;
} fp_dp;
fp_dp.f = mp_obj_get_float_to_d(val_in);
if (MP_BYTES_PER_OBJ_WORD == 8) {
diff --git a/py/obj.h b/py/obj.h
index 598d6508d..645fae79f 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -283,9 +283,11 @@ static inline bool mp_obj_is_obj(mp_const_obj_t o) {
#define MP_OBJ_FROM_PTR(p) ((mp_obj_t)((uintptr_t)(p)))
// rom object storage needs special handling to widen 32-bit pointer to 64-bits
-typedef union _mp_rom_obj_t { uint64_t u64;
- struct { const void *lo, *hi;
- } u32;
+typedef union _mp_rom_obj_t {
+ uint64_t u64;
+ struct {
+ const void *lo, *hi;
+ } u32;
} mp_rom_obj_t;
#define MP_ROM_INT(i) {MP_OBJ_NEW_SMALL_INT(i)}
#define MP_ROM_QSTR(q) {MP_OBJ_NEW_QSTR(q)}