py,extmod: Some casts and minor refactors to quiet compiler warnings.
diff --git a/extmod/utime_mphal.c b/extmod/utime_mphal.c
index e99ba46..0fe3a3b 100644
--- a/extmod/utime_mphal.c
+++ b/extmod/utime_mphal.c
@@ -38,7 +38,7 @@
STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {
#if MICROPY_PY_BUILTINS_FLOAT
- mp_hal_delay_ms(1000 * mp_obj_get_float(seconds_o));
+ mp_hal_delay_ms((mp_uint_t)(1000 * mp_obj_get_float(seconds_o)));
#else
mp_hal_delay_ms(1000 * mp_obj_get_int(seconds_o));
#endif
diff --git a/py/builtinimport.c b/py/builtinimport.c
index 7746e26..7a8474c 100644
--- a/py/builtinimport.c
+++ b/py/builtinimport.c
@@ -227,10 +227,11 @@
do_load_from_lexer(module_obj, lex);
return;
}
- #endif
+ #else
// If we get here then the file was not frozen and we can't compile scripts.
mp_raise_msg(&mp_type_ImportError, "script compilation not supported");
+ #endif
}
STATIC void chop_component(const char *start, const char **end) {
diff --git a/py/emitbc.c b/py/emitbc.c
index ec12a62..127bf0b 100644
--- a/py/emitbc.c
+++ b/py/emitbc.c
@@ -902,7 +902,7 @@
emit_write_bytecode_byte(emit, n_closed_over);
} else {
assert(n_closed_over <= 255);
- emit_bc_pre(emit, -2 - n_closed_over + 1);
+ emit_bc_pre(emit, -2 - (mp_int_t)n_closed_over + 1);
emit_write_bytecode_byte_raw_code(emit, MP_BC_MAKE_CLOSURE_DEFARGS, scope->raw_code);
emit_write_bytecode_byte(emit, n_closed_over);
}
diff --git a/py/formatfloat.c b/py/formatfloat.c
index b16746b..ea5a079 100644
--- a/py/formatfloat.c
+++ b/py/formatfloat.c
@@ -332,7 +332,7 @@
// Print the digits of the mantissa
for (int i = 0; i < num_digits; ++i, --dec) {
- int32_t d = f;
+ int32_t d = (int32_t)f;
*s++ = '0' + d;
if (dec == 0 && prec > 0) {
*s++ = '.';
diff --git a/py/lexer.c b/py/lexer.c
index abc1f3e..6e5cc18 100644
--- a/py/lexer.c
+++ b/py/lexer.c
@@ -672,7 +672,7 @@
lex->source_name = src_name;
lex->reader = reader;
lex->line = 1;
- lex->column = -2; // account for 3 dummy bytes
+ lex->column = (size_t)-2; // account for 3 dummy bytes
lex->emit_dent = 0;
lex->nested_bracket_level = 0;
lex->alloc_indent_level = MICROPY_ALLOC_LEXER_INDENT_INIT;
diff --git a/py/modbuiltins.c b/py/modbuiltins.c
index 57d471b..8fbf4da 100644
--- a/py/modbuiltins.c
+++ b/py/modbuiltins.c
@@ -91,10 +91,8 @@
MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin___build_class___obj, 2, mp_builtin___build_class__);
STATIC mp_obj_t mp_builtin_abs(mp_obj_t o_in) {
- if (0) {
- // dummy
-#if MICROPY_PY_BUILTINS_FLOAT
- } else if (mp_obj_is_float(o_in)) {
+ #if MICROPY_PY_BUILTINS_FLOAT
+ if (mp_obj_is_float(o_in)) {
mp_float_t value = mp_obj_float_get(o_in);
// TODO check for NaN etc
if (value < 0) {
@@ -102,17 +100,17 @@
} else {
return o_in;
}
-#if MICROPY_PY_BUILTINS_COMPLEX
+ #if MICROPY_PY_BUILTINS_COMPLEX
} else if (MP_OBJ_IS_TYPE(o_in, &mp_type_complex)) {
mp_float_t real, imag;
mp_obj_complex_get(o_in, &real, &imag);
return mp_obj_new_float(MICROPY_FLOAT_C_FUN(sqrt)(real*real + imag*imag));
-#endif
-#endif
- } else {
- // this will raise a TypeError if the argument is not integral
- return mp_obj_int_abs(o_in);
+ #endif
}
+ #endif
+
+ // this will raise a TypeError if the argument is not integral
+ return mp_obj_int_abs(o_in);
}
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_abs_obj, mp_builtin_abs);
diff --git a/py/objint.c b/py/objint.c
index 0b49041..2749ec5 100644
--- a/py/objint.c
+++ b/py/objint.c
@@ -106,7 +106,7 @@
#define MP_FLOAT_SIGN_SHIFT_I32 ((MP_FLOAT_FRAC_BITS + MP_FLOAT_EXP_BITS) % 32)
#define MP_FLOAT_EXP_SHIFT_I32 (MP_FLOAT_FRAC_BITS % 32)
- if (e & (1 << MP_FLOAT_SIGN_SHIFT_I32)) {
+ if (e & (1U << MP_FLOAT_SIGN_SHIFT_I32)) {
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
e |= u.i[MP_ENDIANNESS_BIG] != 0;
#endif
diff --git a/py/runtime.c b/py/runtime.c
index 0a3a4b1..a8a1f73 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -1410,16 +1410,13 @@
NORETURN void *m_malloc_fail(size_t num_bytes) {
DEBUG_printf("memory allocation failed, allocating %u bytes\n", (uint)num_bytes);
- if (0) {
- // dummy
#if MICROPY_ENABLE_GC
- } else if (gc_is_locked()) {
+ if (gc_is_locked()) {
mp_raise_msg(&mp_type_MemoryError, "memory allocation failed, heap is locked");
- #endif
- } else {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_MemoryError,
- "memory allocation failed, allocating %u bytes", (uint)num_bytes));
}
+ #endif
+ nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_MemoryError,
+ "memory allocation failed, allocating %u bytes", (uint)num_bytes));
}
NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const char *msg) {
diff --git a/py/vstr.c b/py/vstr.c
index 6a91552..f41bd2e 100644
--- a/py/vstr.c
+++ b/py/vstr.c
@@ -34,7 +34,7 @@
#include "py/mpprint.h"
// returned value is always at least 1 greater than argument
-#define ROUND_ALLOC(a) (((a) & ((~0) - 7)) + 8)
+#define ROUND_ALLOC(a) (((a) & ((~0U) - 7)) + 8)
// Init the vstr so it allocs exactly given number of bytes. Set length to zero.
void vstr_init(vstr_t *vstr, size_t alloc) {