Browse Source

py: Clean up formatting of union definitions.

Signed-off-by: Damien George <damien@micropython.org>
pull/9058/head
Damien George 2 years ago
parent
commit
3d65101a8a
  1. 12
      py/binary.c
  2. 6
      py/obj.h

12
py/binary.c

@ -241,12 +241,14 @@ 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;
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;
union {
uint64_t i;
double f;
} fpu = {val};
return mp_obj_new_float_from_d(fpu.f);
@ -308,7 +310,8 @@ 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;
union {
uint32_t i;
float f;
} fp_sp;
fp_sp.f = mp_obj_get_float_to_f(val_in);
@ -316,7 +319,8 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p
break;
}
case 'd': {
union { uint64_t i64;
union {
uint64_t i64;
uint32_t i32[2];
double f;
} fp_dp;

6
py/obj.h

@ -283,8 +283,10 @@ 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;
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)}

Loading…
Cancel
Save