Thanks to visit codestin.com
Credit goes to github.com

Skip to content

tree-wide: fix implicit casts #5773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ jobs:
- make ${MAKEOPTS} -C ports/unix
# OSX has poor time resolution and the following tests do not have the correct output
- (cd tests && ./run-tests --exclude 'uasyncio_(basic|heaplock|lock|wait_task)')
# check for additional compiler errors/warnings
- make ${MAKEOPTS} -C ports/unix VARIANT=coverage
after_failure:
- (cd tests && for exp in *.exp; do testbase=$(basename $exp .exp); echo -e "\nFAILURE $testbase"; diff -u $testbase.exp $testbase.out; done)

Expand Down
4 changes: 2 additions & 2 deletions extmod/moductypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
#if MICROPY_PY_BUILTINS_FLOAT
case FLOAT32:
return mp_obj_new_float(((float *)p)[index]);
return mp_obj_new_float((mp_float_t)((float *)p)[index]);
case FLOAT64:
return mp_obj_new_float(((double *)p)[index]);
return mp_obj_new_float((mp_float_t)((double *)p)[index]);
#endif
default:
assert(0);
Expand Down
4 changes: 2 additions & 2 deletions ports/unix/modffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ STATIC mp_obj_t return_ffi_value(ffi_arg val, char type) {
union { ffi_arg ffi;
float flt;
} val_union = { .ffi = val };
return mp_obj_new_float(val_union.flt);
return mp_obj_new_float((mp_float_t)val_union.flt);
}
case 'd': {
double *p = (double *)&val;
return mp_obj_new_float(*p);
return mp_obj_new_float((mp_float_t)*p);
}
#endif
case 'O':
Expand Down
4 changes: 2 additions & 2 deletions ports/unix/modtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static inline int msec_sleep_tv(struct timeval *tv) {
#endif

#if defined(MP_CLOCKS_PER_SEC)
#define CLOCK_DIV (MP_CLOCKS_PER_SEC / 1000.0F)
#define CLOCK_DIV (MP_CLOCKS_PER_SEC / MICROPY_FLOAT_CONST(1000.0))
#else
#error Unsupported clock() implementation
#endif
Expand All @@ -84,7 +84,7 @@ STATIC mp_obj_t mod_time_clock(void) {
// float cannot represent full range of int32 precisely, so we pre-divide
// int to reduce resolution, and then actually do float division hoping
// to preserve integer part resolution.
return mp_obj_new_float((float)(clock() / 1000) / CLOCK_DIV);
return mp_obj_new_float((mp_float_t)(clock() / 1000) / CLOCK_DIV);
#else
return mp_obj_new_int((mp_int_t)clock());
#endif
Expand Down
8 changes: 4 additions & 4 deletions py/binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, size_t index) {
#endif
#if MICROPY_PY_BUILTINS_FLOAT
case 'f':
return mp_obj_new_float(((float *)p)[index]);
return mp_obj_new_float((mp_float_t)((float *)p)[index]);
case 'd':
return mp_obj_new_float(((double *)p)[index]);
return mp_obj_new_float((mp_float_t)((double *)p)[index]);
#endif
// Extension to CPython: array of objects
case 'O':
Expand Down Expand Up @@ -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;
float f;
} fpu = {val};
return mp_obj_new_float(fpu.f);
return mp_obj_new_float((mp_float_t)fpu.f);
} else if (val_type == 'd') {
union { uint64_t i;
double f;
} fpu = {val};
return mp_obj_new_float(fpu.f);
return mp_obj_new_float((mp_float_t)fpu.f);
#endif
} else if (is_signed(val_type)) {
if ((long long)MP_SMALL_INT_MIN <= val && val <= (long long)MP_SMALL_INT_MAX) {
Expand Down
2 changes: 1 addition & 1 deletion py/objarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
if (len_adj > 0) {
if (len_adj > o->free) {
if ((size_t)len_adj > o->free) {
// 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->free = len_adj;
Expand Down
2 changes: 1 addition & 1 deletion py/parsenum.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,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') {
// inf
str += 3;
dec_val = INFINITY;
dec_val = (mp_float_t)INFINITY;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably also use MICROPY_FLOAT_CONST(x) here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work since MICROPY_FLOAT_CONST either passes the value through untouched or adds an F. So if mp_float_t is double, we still get a compile error or if mp_float_t is float, then we get undefined INFINITYF.

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
str += 5;
Expand Down