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:
parent
dde3db21fc
commit
ccd92335a1
|
@ -506,6 +506,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
|
||||||
return mp_obj_new_bytearray_by_ref(uctypes_struct_agg_size(sub, self->flags, &dummy), self->addr + offset);
|
return mp_obj_new_bytearray_by_ref(uctypes_struct_agg_size(sub, self->flags, &dummy), self->addr + offset);
|
||||||
}
|
}
|
||||||
// Fall thru to return uctypes struct object
|
// Fall thru to return uctypes struct object
|
||||||
|
MP_FALLTHROUGH
|
||||||
}
|
}
|
||||||
case PTR: {
|
case PTR: {
|
||||||
mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t);
|
mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t);
|
||||||
|
@ -627,7 +628,7 @@ STATIC mp_obj_t uctypes_struct_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
||||||
return mp_obj_new_int((mp_int_t)(uintptr_t)p);
|
return mp_obj_new_int((mp_int_t)(uintptr_t)p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* fallthru */
|
MP_FALLTHROUGH
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return MP_OBJ_NULL; // op not supported
|
return MP_OBJ_NULL; // op not supported
|
||||||
|
|
|
@ -29,6 +29,7 @@ static const char *_compilecode(const char *re, ByteProg *prog, int sizecode)
|
||||||
prog->len++;
|
prog->len++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
MP_FALLTHROUGH
|
||||||
default:
|
default:
|
||||||
term = PC;
|
term = PC;
|
||||||
EMIT(PC++, Char);
|
EMIT(PC++, Char);
|
||||||
|
|
|
@ -22,6 +22,7 @@ recursiveloop(char *pc, const char *sp, Subject *input, const char **subp, int n
|
||||||
case Char:
|
case Char:
|
||||||
if(*sp != *pc++)
|
if(*sp != *pc++)
|
||||||
return 0;
|
return 0;
|
||||||
|
MP_FALLTHROUGH
|
||||||
case Any:
|
case Any:
|
||||||
sp++;
|
sp++;
|
||||||
continue;
|
continue;
|
||||||
|
|
1
py/gc.c
1
py/gc.c
|
@ -299,6 +299,7 @@ STATIC void gc_sweep(void) {
|
||||||
MP_STATE_MEM(gc_collected)++;
|
MP_STATE_MEM(gc_collected)++;
|
||||||
#endif
|
#endif
|
||||||
// fall through to free the head
|
// fall through to free the head
|
||||||
|
MP_FALLTHROUGH
|
||||||
|
|
||||||
case AT_TAIL:
|
case AT_TAIL:
|
||||||
if (free_tail) {
|
if (free_tail) {
|
||||||
|
|
|
@ -347,6 +347,7 @@ STATIC void parse_string_literal(mp_lexer_t *lex, bool is_raw) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Otherwise fall through.
|
// Otherwise fall through.
|
||||||
|
MP_FALLTHROUGH
|
||||||
case 'x': {
|
case 'x': {
|
||||||
mp_uint_t num = 0;
|
mp_uint_t num = 0;
|
||||||
if (!get_hex(lex, (c == 'x' ? 2 : c == 'u' ? 4 : 8), &num)) {
|
if (!get_hex(lex, (c == 'x' ? 2 : c == 'u' ? 4 : 8), &num)) {
|
||||||
|
|
|
@ -1643,6 +1643,13 @@ typedef double mp_float_t;
|
||||||
#endif
|
#endif
|
||||||
#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
|
#ifndef MP_HTOBE16
|
||||||
#if MP_ENDIANNESS_LITTLE
|
#if MP_ENDIANNESS_LITTLE
|
||||||
#define MP_HTOBE16(x) ((uint16_t)((((x) & 0xff) << 8) | (((x) >> 8) & 0xff)))
|
#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);
|
return MP_OBJ_NEW_SMALL_INT(hash);
|
||||||
}
|
}
|
||||||
|
MP_FALLTHROUGH
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
return MP_OBJ_NULL; // op not supported
|
return MP_OBJ_NULL; // op not supported
|
||||||
|
|
Loading…
Reference in New Issue