Browse Source

Revert "all: Fix implicit casts of float/double, and signed comparison."

This reverts commit a2110bd3fc.  There's
nothing inherently wrong with it, but upcoming commits will apply similar
fixes in a slightly different way.
pull/5944/head
stijn 5 years ago
committed by Damien George
parent
commit
b909e8b2dd
  1. 4
      extmod/moductypes.c
  2. 4
      ports/unix/modffi.c
  3. 4
      ports/unix/modtime.c
  4. 8
      py/binary.c
  5. 2
      py/objarray.c
  6. 2
      py/parsenum.c

4
extmod/moductypes.c

@ -360,9 +360,9 @@ STATIC mp_obj_t get_aligned(uint val_type, void *p, mp_int_t index) {
return mp_obj_new_int_from_ll(((int64_t *)p)[index]); return mp_obj_new_int_from_ll(((int64_t *)p)[index]);
#if MICROPY_PY_BUILTINS_FLOAT #if MICROPY_PY_BUILTINS_FLOAT
case FLOAT32: case FLOAT32:
return mp_obj_new_float((mp_float_t)((float *)p)[index]); return mp_obj_new_float(((float *)p)[index]);
case FLOAT64: case FLOAT64:
return mp_obj_new_float((mp_float_t)((double *)p)[index]); return mp_obj_new_float(((double *)p)[index]);
#endif #endif
default: default:
assert(0); assert(0);

4
ports/unix/modffi.c

@ -167,11 +167,11 @@ STATIC mp_obj_t return_ffi_value(ffi_arg val, char type) {
union { ffi_arg ffi; union { ffi_arg ffi;
float flt; float flt;
} val_union = { .ffi = val }; } val_union = { .ffi = val };
return mp_obj_new_float((mp_float_t)val_union.flt); return mp_obj_new_float(val_union.flt);
} }
case 'd': { case 'd': {
double *p = (double *)&val; double *p = (double *)&val;
return mp_obj_new_float((mp_float_t)*p); return mp_obj_new_float(*p);
} }
#endif #endif
case 'O': case 'O':

4
ports/unix/modtime.c

@ -61,7 +61,7 @@ static inline int msec_sleep_tv(struct timeval *tv) {
#endif #endif
#if defined(MP_CLOCKS_PER_SEC) #if defined(MP_CLOCKS_PER_SEC)
#define CLOCK_DIV (MP_CLOCKS_PER_SEC / MICROPY_FLOAT_CONST(1000.0)) #define CLOCK_DIV (MP_CLOCKS_PER_SEC / 1000.0F)
#else #else
#error Unsupported clock() implementation #error Unsupported clock() implementation
#endif #endif
@ -84,7 +84,7 @@ STATIC mp_obj_t mod_time_clock(void) {
// float cannot represent full range of int32 precisely, so we pre-divide // float cannot represent full range of int32 precisely, so we pre-divide
// int to reduce resolution, and then actually do float division hoping // int to reduce resolution, and then actually do float division hoping
// to preserve integer part resolution. // to preserve integer part resolution.
return mp_obj_new_float((mp_float_t)(clock() / 1000) / CLOCK_DIV); return mp_obj_new_float((float)(clock() / 1000) / CLOCK_DIV);
#else #else
return mp_obj_new_int((mp_int_t)clock()); return mp_obj_new_int((mp_int_t)clock());
#endif #endif

8
py/binary.c

@ -176,9 +176,9 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, size_t index) {
#endif #endif
#if MICROPY_PY_BUILTINS_FLOAT #if MICROPY_PY_BUILTINS_FLOAT
case 'f': case 'f':
return mp_obj_new_float((mp_float_t)((float *)p)[index]); return mp_obj_new_float(((float *)p)[index]);
case 'd': case 'd':
return mp_obj_new_float((mp_float_t)((double *)p)[index]); return mp_obj_new_float(((double *)p)[index]);
#endif #endif
// Extension to CPython: array of objects // Extension to CPython: array of objects
case 'O': case 'O':
@ -244,12 +244,12 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte *p_base, byte *
union { uint32_t i; union { uint32_t i;
float f; float f;
} fpu = {val}; } fpu = {val};
return mp_obj_new_float((mp_float_t)fpu.f); return mp_obj_new_float(fpu.f);
} else if (val_type == 'd') { } else if (val_type == 'd') {
union { uint64_t i; union { uint64_t i;
double f; double f;
} fpu = {val}; } fpu = {val};
return mp_obj_new_float((mp_float_t)fpu.f); return mp_obj_new_float(fpu.f);
#endif #endif
} else if (is_signed(val_type)) { } else if (is_signed(val_type)) {
if ((long long)MP_SMALL_INT_MIN <= val && val <= (long long)MP_SMALL_INT_MAX) { if ((long long)MP_SMALL_INT_MIN <= val && val <= (long long)MP_SMALL_INT_MAX) {

2
py/objarray.c

@ -445,7 +445,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
} }
#endif #endif
if (len_adj > 0) { if (len_adj > 0) {
if ((size_t)len_adj > o->free) { if (len_adj > o->free) {
// TODO: alloc policy; at the moment we go conservative // TODO: alloc policy; at the moment we go conservative
o->items = m_renew(byte, o->items, (o->len + o->free) * item_sz, (o->len + len_adj) * item_sz); o->items = m_renew(byte, o->items, (o->len + o->free) * item_sz, (o->len + len_adj) * item_sz);
o->free = len_adj; o->free = len_adj;

2
py/parsenum.c

@ -220,7 +220,7 @@ mp_obj_t mp_parse_num_decimal(const char *str, size_t len, bool allow_imag, bool
if (str + 2 < top && (str[1] | 0x20) == 'n' && (str[2] | 0x20) == 'f') { if (str + 2 < top && (str[1] | 0x20) == 'n' && (str[2] | 0x20) == 'f') {
// inf // inf
str += 3; str += 3;
dec_val = (mp_float_t)INFINITY; dec_val = INFINITY;
if (str + 4 < top && (str[0] | 0x20) == 'i' && (str[1] | 0x20) == 'n' && (str[2] | 0x20) == 'i' && (str[3] | 0x20) == 't' && (str[4] | 0x20) == 'y') { if (str + 4 < top && (str[0] | 0x20) == 'i' && (str[1] | 0x20) == 'n' && (str[2] | 0x20) == 'i' && (str[3] | 0x20) == 't' && (str[4] | 0x20) == 'y') {
// infinity // infinity
str += 5; str += 5;

Loading…
Cancel
Save