Skip to content

Commit ccd9233

Browse files
committed
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.
1 parent dde3db2 commit ccd9233

File tree

7 files changed

+16
-3
lines changed

7 files changed

+16
-3
lines changed

extmod/moductypes.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
506506
return mp_obj_new_bytearray_by_ref(uctypes_struct_agg_size(sub, self->flags, &dummy), self->addr + offset);
507507
}
508508
// Fall thru to return uctypes struct object
509+
MP_FALLTHROUGH
509510
}
510511
case PTR: {
511512
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) {
627628
return mp_obj_new_int((mp_int_t)(uintptr_t)p);
628629
}
629630
}
630-
/* fallthru */
631+
MP_FALLTHROUGH
631632

632633
default:
633634
return MP_OBJ_NULL; // op not supported

extmod/re1.5/compilecode.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static const char *_compilecode(const char *re, ByteProg *prog, int sizecode)
2929
prog->len++;
3030
break;
3131
}
32+
MP_FALLTHROUGH
3233
default:
3334
term = PC;
3435
EMIT(PC++, Char);

extmod/re1.5/recursiveloop.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ recursiveloop(char *pc, const char *sp, Subject *input, const char **subp, int n
2222
case Char:
2323
if(*sp != *pc++)
2424
return 0;
25+
MP_FALLTHROUGH
2526
case Any:
2627
sp++;
2728
continue;

py/gc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ STATIC void gc_sweep(void) {
298298
#if MICROPY_PY_GC_COLLECT_RETVAL
299299
MP_STATE_MEM(gc_collected)++;
300300
#endif
301-
// fall through to free the head
301+
// fall through to free the head
302+
MP_FALLTHROUGH
302303

303304
case AT_TAIL:
304305
if (free_tail) {

py/lexer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ STATIC void parse_string_literal(mp_lexer_t *lex, bool is_raw) {
346346
vstr_add_char(&lex->vstr, '\\');
347347
break;
348348
}
349-
// Otherwise fall through.
349+
// Otherwise fall through.
350+
MP_FALLTHROUGH
350351
case 'x': {
351352
mp_uint_t num = 0;
352353
if (!get_hex(lex, (c == 'x' ? 2 : c == 'u' ? 4 : 8), &num)) {

py/mpconfig.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,13 @@ typedef double mp_float_t;
16431643
#endif
16441644
#endif
16451645

1646+
// Explicitly annotate switch case fall throughs
1647+
#if defined(__GNUC__) && __GNUC__ >= 7
1648+
#define MP_FALLTHROUGH __attribute__((fallthrough));
1649+
#else
1650+
#define MP_FALLTHROUGH
1651+
#endif
1652+
16461653
#ifndef MP_HTOBE16
16471654
#if MP_ENDIANNESS_LITTLE
16481655
#define MP_HTOBE16(x) ((uint16_t)((((x) & 0xff) << 8) | (((x) >> 8) & 0xff)))

py/objset.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ STATIC mp_obj_t set_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
445445
}
446446
return MP_OBJ_NEW_SMALL_INT(hash);
447447
}
448+
MP_FALLTHROUGH
448449
#endif
449450
default:
450451
return MP_OBJ_NULL; // op not supported

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy