mirror of
https://github.com/micropython/micropython.git
synced 2026-01-08 21:20:13 +01:00
py, extmod: Introduce and use MP_FALLTHROUGH macro.
Newer GCC versions are able to warn about switch cases that fall through. This is usually a sign of a forgotten break statement, but in the few cases where a fall through is intended we annotate it with this macro to avoid the warning.
This commit is contained in:
3
py/gc.c
3
py/gc.c
@@ -298,7 +298,8 @@ STATIC void gc_sweep(void) {
|
||||
#if MICROPY_PY_GC_COLLECT_RETVAL
|
||||
MP_STATE_MEM(gc_collected)++;
|
||||
#endif
|
||||
// fall through to free the head
|
||||
// fall through to free the head
|
||||
MP_FALLTHROUGH
|
||||
|
||||
case AT_TAIL:
|
||||
if (free_tail) {
|
||||
|
||||
@@ -346,7 +346,8 @@ STATIC void parse_string_literal(mp_lexer_t *lex, bool is_raw) {
|
||||
vstr_add_char(&lex->vstr, '\\');
|
||||
break;
|
||||
}
|
||||
// Otherwise fall through.
|
||||
// Otherwise fall through.
|
||||
MP_FALLTHROUGH
|
||||
case 'x': {
|
||||
mp_uint_t num = 0;
|
||||
if (!get_hex(lex, (c == 'x' ? 2 : c == 'u' ? 4 : 8), &num)) {
|
||||
|
||||
@@ -1643,6 +1643,13 @@ typedef double mp_float_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Explicitly annotate switch case fall throughs
|
||||
#if defined(__GNUC__) && __GNUC__ >= 7
|
||||
#define MP_FALLTHROUGH __attribute__((fallthrough));
|
||||
#else
|
||||
#define MP_FALLTHROUGH
|
||||
#endif
|
||||
|
||||
#ifndef MP_HTOBE16
|
||||
#if MP_ENDIANNESS_LITTLE
|
||||
#define MP_HTOBE16(x) ((uint16_t)((((x) & 0xff) << 8) | (((x) >> 8) & 0xff)))
|
||||
|
||||
@@ -445,6 +445,7 @@ STATIC mp_obj_t set_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
||||
}
|
||||
return MP_OBJ_NEW_SMALL_INT(hash);
|
||||
}
|
||||
MP_FALLTHROUGH
|
||||
#endif
|
||||
default:
|
||||
return MP_OBJ_NULL; // op not supported
|
||||
|
||||
Reference in New Issue
Block a user