Skip to content

Commit 145796f

Browse files
tomlogicdpgeorge
authored andcommitted
py,extmod: Some casts and minor refactors to quiet compiler warnings.
1 parent ed52955 commit 145796f

9 files changed

Lines changed: 20 additions & 24 deletions

File tree

extmod/utime_mphal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {
4040
#if MICROPY_PY_BUILTINS_FLOAT
41-
mp_hal_delay_ms(1000 * mp_obj_get_float(seconds_o));
41+
mp_hal_delay_ms((mp_uint_t)(1000 * mp_obj_get_float(seconds_o)));
4242
#else
4343
mp_hal_delay_ms(1000 * mp_obj_get_int(seconds_o));
4444
#endif

py/builtinimport.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,11 @@ STATIC void do_load(mp_obj_t module_obj, vstr_t *file) {
227227
do_load_from_lexer(module_obj, lex);
228228
return;
229229
}
230-
#endif
230+
#else
231231

232232
// If we get here then the file was not frozen and we can't compile scripts.
233233
mp_raise_msg(&mp_type_ImportError, "script compilation not supported");
234+
#endif
234235
}
235236

236237
STATIC void chop_component(const char *start, const char **end) {

py/emitbc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ void mp_emit_bc_make_closure(emit_t *emit, scope_t *scope, mp_uint_t n_closed_ov
902902
emit_write_bytecode_byte(emit, n_closed_over);
903903
} else {
904904
assert(n_closed_over <= 255);
905-
emit_bc_pre(emit, -2 - n_closed_over + 1);
905+
emit_bc_pre(emit, -2 - (mp_int_t)n_closed_over + 1);
906906
emit_write_bytecode_byte_raw_code(emit, MP_BC_MAKE_CLOSURE_DEFARGS, scope->raw_code);
907907
emit_write_bytecode_byte(emit, n_closed_over);
908908
}

py/formatfloat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
332332

333333
// Print the digits of the mantissa
334334
for (int i = 0; i < num_digits; ++i, --dec) {
335-
int32_t d = f;
335+
int32_t d = (int32_t)f;
336336
*s++ = '0' + d;
337337
if (dec == 0 && prec > 0) {
338338
*s++ = '.';

py/lexer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ mp_lexer_t *mp_lexer_new(qstr src_name, mp_reader_t reader) {
672672
lex->source_name = src_name;
673673
lex->reader = reader;
674674
lex->line = 1;
675-
lex->column = -2; // account for 3 dummy bytes
675+
lex->column = (size_t)-2; // account for 3 dummy bytes
676676
lex->emit_dent = 0;
677677
lex->nested_bracket_level = 0;
678678
lex->alloc_indent_level = MICROPY_ALLOC_LEXER_INDENT_INIT;

py/modbuiltins.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,28 +91,26 @@ STATIC mp_obj_t mp_builtin___build_class__(size_t n_args, const mp_obj_t *args)
9191
MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin___build_class___obj, 2, mp_builtin___build_class__);
9292

9393
STATIC mp_obj_t mp_builtin_abs(mp_obj_t o_in) {
94-
if (0) {
95-
// dummy
96-
#if MICROPY_PY_BUILTINS_FLOAT
97-
} else if (mp_obj_is_float(o_in)) {
94+
#if MICROPY_PY_BUILTINS_FLOAT
95+
if (mp_obj_is_float(o_in)) {
9896
mp_float_t value = mp_obj_float_get(o_in);
9997
// TODO check for NaN etc
10098
if (value < 0) {
10199
return mp_obj_new_float(-value);
102100
} else {
103101
return o_in;
104102
}
105-
#if MICROPY_PY_BUILTINS_COMPLEX
103+
#if MICROPY_PY_BUILTINS_COMPLEX
106104
} else if (MP_OBJ_IS_TYPE(o_in, &mp_type_complex)) {
107105
mp_float_t real, imag;
108106
mp_obj_complex_get(o_in, &real, &imag);
109107
return mp_obj_new_float(MICROPY_FLOAT_C_FUN(sqrt)(real*real + imag*imag));
110-
#endif
111-
#endif
112-
} else {
113-
// this will raise a TypeError if the argument is not integral
114-
return mp_obj_int_abs(o_in);
108+
#endif
115109
}
110+
#endif
111+
112+
// this will raise a TypeError if the argument is not integral
113+
return mp_obj_int_abs(o_in);
116114
}
117115
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_abs_obj, mp_builtin_abs);
118116

py/objint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ STATIC mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val) {
106106
#define MP_FLOAT_SIGN_SHIFT_I32 ((MP_FLOAT_FRAC_BITS + MP_FLOAT_EXP_BITS) % 32)
107107
#define MP_FLOAT_EXP_SHIFT_I32 (MP_FLOAT_FRAC_BITS % 32)
108108

109-
if (e & (1 << MP_FLOAT_SIGN_SHIFT_I32)) {
109+
if (e & (1U << MP_FLOAT_SIGN_SHIFT_I32)) {
110110
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
111111
e |= u.i[MP_ENDIANNESS_BIG] != 0;
112112
#endif

py/runtime.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,16 +1410,13 @@ mp_obj_t mp_parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t parse_i
14101410

14111411
NORETURN void *m_malloc_fail(size_t num_bytes) {
14121412
DEBUG_printf("memory allocation failed, allocating %u bytes\n", (uint)num_bytes);
1413-
if (0) {
1414-
// dummy
14151413
#if MICROPY_ENABLE_GC
1416-
} else if (gc_is_locked()) {
1414+
if (gc_is_locked()) {
14171415
mp_raise_msg(&mp_type_MemoryError, "memory allocation failed, heap is locked");
1418-
#endif
1419-
} else {
1420-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_MemoryError,
1421-
"memory allocation failed, allocating %u bytes", (uint)num_bytes));
14221416
}
1417+
#endif
1418+
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_MemoryError,
1419+
"memory allocation failed, allocating %u bytes", (uint)num_bytes));
14231420
}
14241421

14251422
NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const char *msg) {

py/vstr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "py/mpprint.h"
3535

3636
// returned value is always at least 1 greater than argument
37-
#define ROUND_ALLOC(a) (((a) & ((~0) - 7)) + 8)
37+
#define ROUND_ALLOC(a) (((a) & ((~0U) - 7)) + 8)
3838

3939
// Init the vstr so it allocs exactly given number of bytes. Set length to zero.
4040
void vstr_init(vstr_t *vstr, size_t alloc) {

0 commit comments

Comments
 (0)