https://github.com/python/cpython/commit/12af8ec864225248c3d2916cb142a5e7ee36cbe2
commit: 12af8ec864225248c3d2916cb142a5e7ee36cbe2
branch: main
author: Victor Stinner <vstin...@python.org>
committer: vstinner <vstin...@python.org>
date: 2024-06-27T09:58:44Z
summary:

gh-121040: Use __attribute__((fallthrough)) (#121044)

Fix warnings when using -Wimplicit-fallthrough compiler flag.

Annotate explicitly "fall through" switch cases with a new
_Py_FALLTHROUGH macro which uses __attribute__((fallthrough)) if
available. Replace "fall through" comments with _Py_FALLTHROUGH.

Add _Py__has_attribute() macro. No longer define __has_attribute()
macro if it's not defined. Move also _Py__has_builtin() at the top
of pyport.h.

Co-Authored-By: Nikita Sobolev <m...@sobolevn.me>

files:
M Include/exports.h
M Include/pyport.h
M Modules/_csv.c
M Modules/_ctypes/_ctypes.c
M Modules/_ctypes/stgdict.c
M Modules/_interpqueuesmodule.c
M Modules/_ssl.c
M Modules/_struct.c
M Modules/_testcapi/exceptions.c
M Modules/cjkcodecs/_codecs_iso2022.c
M Modules/overlapped.c
M Modules/socketmodule.c
M Modules/zlibmodule.c
M Objects/rangeobject.c
M Objects/stringlib/codecs.h
M Objects/unicodeobject.c
M Python/assemble.c
M Python/bytecodes.c
M Python/compile.c
M Python/crossinterp.c
M Python/dtoa.c
M Python/formatter_unicode.c
M Python/generated_cases.c.h
M Python/getargs.c
M Python/importdl.c
M Python/marshal.c
M Python/modsupport.c
M Python/pyhash.c
M Python/pystrtod.c

diff --git a/Include/exports.h b/Include/exports.h
index ce601216f17156..0c646d5beb6ad6 100644
--- a/Include/exports.h
+++ b/Include/exports.h
@@ -41,11 +41,8 @@
  * we may still need to support gcc >= 4, as some Ubuntu LTS and Centos 
versions
  * have 4 < gcc < 5.
  */
-    #ifndef __has_attribute
-      #define __has_attribute(x) 0  // Compatibility with non-clang compilers.
-    #endif
     #if (defined(__GNUC__) && (__GNUC__ >= 4)) ||\
-        (defined(__clang__) && __has_attribute(visibility))
+        (defined(__clang__) && _Py__has_attribute(visibility))
         #define Py_IMPORTED_SYMBOL __attribute__ ((visibility ("default")))
         #define Py_EXPORTED_SYMBOL __attribute__ ((visibility ("default")))
         #define Py_LOCAL_SYMBOL  __attribute__ ((visibility ("hidden")))
diff --git a/Include/pyport.h b/Include/pyport.h
index 1f7a9b41e0ae2b..2b6bd4c21110e5 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -9,6 +9,24 @@
 #endif
 
 
+// Preprocessor check for a builtin preprocessor function. Always return 0
+// if __has_builtin() macro is not defined.
+//
+// __has_builtin() is available on clang and GCC 10.
+#ifdef __has_builtin
+#  define _Py__has_builtin(x) __has_builtin(x)
+#else
+#  define _Py__has_builtin(x) 0
+#endif
+
+// Preprocessor check for a compiler __attribute__. Always return 0
+// if __has_attribute() macro is not defined.
+#ifdef __has_attribute
+#  define _Py__has_attribute(x) __has_attribute(x)
+#else
+#  define _Py__has_attribute(x) 0
+#endif
+
 // Macro to use C++ static_cast<> in the Python C API.
 #ifdef __cplusplus
 #  define _Py_STATIC_CAST(type, expr) static_cast<type>(expr)
@@ -532,16 +550,6 @@ extern "C" {
 #endif
 
 
-// Preprocessor check for a builtin preprocessor function. Always return 0
-// if __has_builtin() macro is not defined.
-//
-// __has_builtin() is available on clang and GCC 10.
-#ifdef __has_builtin
-#  define _Py__has_builtin(x) __has_builtin(x)
-#else
-#  define _Py__has_builtin(x) 0
-#endif
-
 // _Py_TYPEOF(expr) gets the type of an expression.
 //
 // Example: _Py_TYPEOF(x) x_copy = (x);
@@ -607,4 +615,21 @@ extern "C" {
 #  define _SGI_MP_SOURCE
 #endif
 
+// Explicit fallthrough in switch case to avoid warnings
+// with compiler flag -Wimplicit-fallthrough.
+//
+// Usage example:
+//
+//     switch (value) {
+//     case 1: _Py_FALLTHROUGH;
+//     case 2: code; break;
+//     }
+//
+// __attribute__((fallthrough)) was introduced in GCC 7.
+#if _Py__has_attribute(fallthrough)
+#  define _Py_FALLTHROUGH __attribute__((fallthrough))
+#else
+#  define _Py_FALLTHROUGH do { } while (0)
+#endif
+
 #endif /* Py_PYPORT_H */
diff --git a/Modules/_csv.c b/Modules/_csv.c
index 9d6b66d4938687..9964c383b8ad09 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -731,7 +731,7 @@ parse_process_char(ReaderObj *self, _csvstate 
*module_state, Py_UCS4 c)
         }
         /* normal character - handle as START_FIELD */
         self->state = START_FIELD;
-        /* fallthru */
+        _Py_FALLTHROUGH;
     case START_FIELD:
         /* expecting field */
         self->unquoted_field = true;
@@ -785,7 +785,7 @@ parse_process_char(ReaderObj *self, _csvstate 
*module_state, Py_UCS4 c)
     case AFTER_ESCAPED_CRNL:
         if (c == EOL)
             break;
-        /*fallthru*/
+        _Py_FALLTHROUGH;
 
     case IN_FIELD:
         /* in unquoted field */
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 222700b4b7cc69..1ff108a39320cf 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -4074,7 +4074,7 @@ _build_callargs(ctypes_state *st, PyCFuncPtrObject *self, 
PyObject *argtypes,
         case (PARAMFLAG_FIN | PARAMFLAG_FOUT):
             *pinoutmask |= (1 << i); /* mark as inout arg */
             (*pnumretvals)++;
-            /* fall through */
+            _Py_FALLTHROUGH;
         case 0:
         case PARAMFLAG_FIN:
             /* 'in' parameter.  Copy it from inargs. */
diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c
index 52d8ec92380b30..970f0a033fbb0b 100644
--- a/Modules/_ctypes/stgdict.c
+++ b/Modules/_ctypes/stgdict.c
@@ -485,10 +485,11 @@ PyCStructUnionType_update_stginfo(PyObject *type, 
PyObject *fields, int isStruct
             case FFI_TYPE_SINT16:
             case FFI_TYPE_SINT32:
                 if (info->getfunc != _ctypes_get_fielddesc("c")->getfunc
-                    && info->getfunc != _ctypes_get_fielddesc("u")->getfunc
-                    )
+                    && info->getfunc != _ctypes_get_fielddesc("u")->getfunc)
+                {
                     break;
-                /* else fall through */
+                }
+                _Py_FALLTHROUGH;  /* else fall through */
             default:
                 PyErr_Format(PyExc_TypeError,
                              "bit fields not allowed for type %s",
diff --git a/Modules/_interpqueuesmodule.c b/Modules/_interpqueuesmodule.c
index 556953db6b8039..c99111b861cc32 100644
--- a/Modules/_interpqueuesmodule.c
+++ b/Modules/_interpqueuesmodule.c
@@ -363,7 +363,7 @@ handle_queue_error(int err, PyObject *mod, int64_t qid)
 
     module_state *state;
     switch (err) {
-    case ERR_QUEUE_ALLOC:  // fall through
+    case ERR_QUEUE_ALLOC: _Py_FALLTHROUGH;
     case ERR_QUEUES_ALLOC:
         PyErr_NoMemory();
         break;
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index 9d50b576ba337f..14a8edfa67cec4 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -3472,8 +3472,8 @@ set_min_max_proto_version(PySSLContext *self, PyObject 
*arg, int what)
     }
 
     switch(self->protocol) {
-    case PY_SSL_VERSION_TLS_CLIENT:  /* fall through */
-    case PY_SSL_VERSION_TLS_SERVER:  /* fall through */
+    case PY_SSL_VERSION_TLS_CLIENT: _Py_FALLTHROUGH;
+    case PY_SSL_VERSION_TLS_SERVER: _Py_FALLTHROUGH;
     case PY_SSL_VERSION_TLS:
         break;
     default:
diff --git a/Modules/_struct.c b/Modules/_struct.c
index 905dcbdeeddc5a..6a68478dd45d36 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -1373,7 +1373,7 @@ whichtable(const char **pfmt)
     }
     default:
         --*pfmt; /* Back out of pointer increment */
-        /* Fall through */
+        _Py_FALLTHROUGH;
     case '@':
         return native_table;
     }
@@ -1475,7 +1475,7 @@ prepare_s(PyStructObject *self)
             return -1;
 
         switch (c) {
-            case 's': /* fall through */
+            case 's': _Py_FALLTHROUGH;
             case 'p': len++; ncodes++; break;
             case 'x': break;
             default: len += num; if (num) ncodes++; break;
diff --git a/Modules/_testcapi/exceptions.c b/Modules/_testcapi/exceptions.c
index 42a9915143e6fa..316ef0e7ad7e55 100644
--- a/Modules/_testcapi/exceptions.c
+++ b/Modules/_testcapi/exceptions.c
@@ -34,11 +34,11 @@ err_restore(PyObject *self, PyObject *args) {
         case 3:
             traceback = PyTuple_GetItem(args, 2);
             Py_INCREF(traceback);
-            /* fall through */
+            _Py_FALLTHROUGH;
         case 2:
             value = PyTuple_GetItem(args, 1);
             Py_INCREF(value);
-            /* fall through */
+            _Py_FALLTHROUGH;
         case 1:
             type = PyTuple_GetItem(args, 0);
             Py_INCREF(type);
diff --git a/Modules/cjkcodecs/_codecs_iso2022.c 
b/Modules/cjkcodecs/_codecs_iso2022.c
index e8835ad0909633..ef6faeb71274e1 100644
--- a/Modules/cjkcodecs/_codecs_iso2022.c
+++ b/Modules/cjkcodecs/_codecs_iso2022.c
@@ -806,7 +806,7 @@ jisx0213_encoder(const MultibyteCodec *codec, const Py_UCS4 
*data,
                                 jisx0213_pair_encmap, JISX0213_ENCPAIRS);
         if (coded != DBCINV)
             return coded;
-        /* fall through */
+        _Py_FALLTHROUGH;
 
     case -1: /* flush unterminated */
         *length = 1;
diff --git a/Modules/overlapped.c b/Modules/overlapped.c
index 77ee70ae133c85..308a0dab7fab1a 100644
--- a/Modules/overlapped.c
+++ b/Modules/overlapped.c
@@ -923,7 +923,7 @@ _overlapped_Overlapped_getresult_impl(OverlappedObject 
*self, BOOL wait)
             {
                 break;
             }
-            /* fall through */
+            _Py_FALLTHROUGH;
         default:
             return SetFromWindowsErr(err);
     }
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 0626d7934983db..6d161478be2d9d 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -1887,12 +1887,14 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
 
 #ifdef AF_RDS
     case AF_RDS:
-        /* RDS sockets use sockaddr_in: fall-through */
+        /* RDS sockets use sockaddr_in */
+        _Py_FALLTHROUGH;
 #endif /* AF_RDS */
 
 #ifdef AF_DIVERT
     case AF_DIVERT:
-        /* FreeBSD divert(4) sockets use sockaddr_in: fall-through */
+        /* FreeBSD divert(4) sockets use sockaddr_in */
+        _Py_FALLTHROUGH;
 #endif /* AF_DIVERT */
 
     case AF_INET:
@@ -2214,7 +2216,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
         switch (s->sock_proto) {
 #ifdef CAN_RAW
         case CAN_RAW:
-        /* fall-through */
+            _Py_FALLTHROUGH;
 #endif
 #ifdef CAN_BCM
         case CAN_BCM:
@@ -2590,7 +2592,8 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret)
 
 #ifdef AF_RDS
     case AF_RDS:
-        /* RDS sockets use sockaddr_in: fall-through */
+        /* RDS sockets use sockaddr_in */
+       _Py_FALLTHROUGH;
 #endif /* AF_RDS */
 
     case AF_INET:
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index b115f67f228ba7..c5aaf22eeb2948 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -489,8 +489,8 @@ zlib_decompress_impl(PyObject *module, Py_buffer *data, int 
wbits,
             Py_END_ALLOW_THREADS
 
             switch (err) {
-            case Z_OK:            /* fall through */
-            case Z_BUF_ERROR:     /* fall through */
+            case Z_OK: _Py_FALLTHROUGH;
+            case Z_BUF_ERROR: _Py_FALLTHROUGH;
             case Z_STREAM_END:
                 break;
             case Z_MEM_ERROR:
@@ -915,8 +915,8 @@ zlib_Decompress_decompress_impl(compobject *self, 
PyTypeObject *cls,
             Py_END_ALLOW_THREADS
 
             switch (err) {
-            case Z_OK:            /* fall through */
-            case Z_BUF_ERROR:     /* fall through */
+            case Z_OK: _Py_FALLTHROUGH;
+            case Z_BUF_ERROR: _Py_FALLTHROUGH;
             case Z_STREAM_END:
                 break;
             default:
@@ -1293,8 +1293,8 @@ zlib_Decompress_flush_impl(compobject *self, PyTypeObject 
*cls,
             Py_END_ALLOW_THREADS
 
             switch (err) {
-            case Z_OK:            /* fall through */
-            case Z_BUF_ERROR:     /* fall through */
+            case Z_OK: _Py_FALLTHROUGH;
+            case Z_BUF_ERROR: _Py_FALLTHROUGH;
             case Z_STREAM_END:
                 break;
             default:
@@ -1495,8 +1495,8 @@ decompress_buf(ZlibDecompressor *self, Py_ssize_t 
max_length)
             err = inflate(&self->zst, Z_SYNC_FLUSH);
             Py_END_ALLOW_THREADS
             switch (err) {
-            case Z_OK:            /* fall through */
-            case Z_BUF_ERROR:     /* fall through */
+            case Z_OK:  _Py_FALLTHROUGH;
+            case Z_BUF_ERROR: _Py_FALLTHROUGH;
             case Z_STREAM_END:
                 break;
             default:
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c
index 7da6162744ffd6..d5db48c143324f 100644
--- a/Objects/rangeobject.c
+++ b/Objects/rangeobject.c
@@ -83,7 +83,7 @@ range_from_array(PyTypeObject *type, PyObject *const *args, 
Py_ssize_t num_args)
     switch (num_args) {
         case 3:
             step = args[2];
-            /* fallthrough */
+            _Py_FALLTHROUGH;
         case 2:
             /* Convert borrowed refs to owned refs */
             start = PyNumber_Index(args[0]);
diff --git a/Objects/stringlib/codecs.h b/Objects/stringlib/codecs.h
index f98e71c3fc6ecf..440410d0aef17d 100644
--- a/Objects/stringlib/codecs.h
+++ b/Objects/stringlib/codecs.h
@@ -331,7 +331,7 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer,
             case _Py_ERROR_REPLACE:
                 memset(p, '?', endpos - startpos);
                 p += (endpos - startpos);
-                /* fall through */
+                _Py_FALLTHROUGH;
             case _Py_ERROR_IGNORE:
                 i += (endpos - startpos - 1);
                 break;
@@ -379,7 +379,7 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer,
                 }
                 startpos = k;
                 assert(startpos < endpos);
-                /* fall through */
+                _Py_FALLTHROUGH;
             default:
                 rep = unicode_encode_call_errorhandler(
                       errors, &error_handler_obj, "utf-8", "surrogates not 
allowed",
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index acdec61cfdb411..9738442ab962b0 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -5073,7 +5073,7 @@ unicode_decode_utf8_impl(_PyUnicodeWriter *writer,
                 /* Truncated surrogate code in range D800-DFFF */
                 goto End;
             }
-            /* fall through */
+            _Py_FALLTHROUGH;
         case 3:
         case 4:
             errmsg = "invalid continuation byte";
@@ -7108,7 +7108,7 @@ unicode_encode_ucs1(PyObject *unicode,
             case _Py_ERROR_REPLACE:
                 memset(str, '?', collend - collstart);
                 str += (collend - collstart);
-                /* fall through */
+                _Py_FALLTHROUGH;
             case _Py_ERROR_IGNORE:
                 pos = collend;
                 break;
@@ -7147,7 +7147,7 @@ unicode_encode_ucs1(PyObject *unicode,
                     break;
                 collstart = pos;
                 assert(collstart != collend);
-                /* fall through */
+                _Py_FALLTHROUGH;
 
             default:
                 rep = unicode_encode_call_errorhandler(errors, 
&error_handler_obj,
@@ -8699,7 +8699,7 @@ charmap_encoding_error(
                 return -1;
             }
         }
-        /* fall through */
+        _Py_FALLTHROUGH;
     case _Py_ERROR_IGNORE:
         *inpos = collendpos;
         break;
@@ -15673,7 +15673,7 @@ _PyUnicode_ClearInterned(PyInterpreterState *interp)
 #endif
             break;
         case SSTATE_NOT_INTERNED:
-            /* fall through */
+            _Py_FALLTHROUGH;
         default:
             Py_UNREACHABLE();
         }
diff --git a/Python/assemble.c b/Python/assemble.c
index 945c8ac39f53ac..f7b88b519f5f71 100644
--- a/Python/assemble.c
+++ b/Python/assemble.c
@@ -369,17 +369,17 @@ write_instr(_Py_CODEUNIT *codestr, instruction *instr, 
int ilen)
             codestr->op.code = EXTENDED_ARG;
             codestr->op.arg = (oparg >> 24) & 0xFF;
             codestr++;
-            /* fall through */
+            _Py_FALLTHROUGH;
         case 3:
             codestr->op.code = EXTENDED_ARG;
             codestr->op.arg = (oparg >> 16) & 0xFF;
             codestr++;
-            /* fall through */
+            _Py_FALLTHROUGH;
         case 2:
             codestr->op.code = EXTENDED_ARG;
             codestr->op.arg = (oparg >> 8) & 0xFF;
             codestr++;
-            /* fall through */
+            _Py_FALLTHROUGH;
         case 1:
             codestr->op.code = opcode;
             codestr->op.arg = oparg & 0xFF;
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 67061ac26323e8..8dfce77dfca297 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -885,10 +885,10 @@ dummy_func(
             switch (oparg) {
             case 2:
                 cause = PyStackRef_AsPyObjectSteal(args[1]);
-                /* fall through */
+                _Py_FALLTHROUGH;
             case 1:
                 exc = PyStackRef_AsPyObjectSteal(args[0]);
-                /* fall through */
+                _Py_FALLTHROUGH;
             case 0:
                 if (do_raise(tstate, exc, cause)) {
                     assert(oparg == 0);
diff --git a/Python/compile.c b/Python/compile.c
index cdac438393dc0c..69de0ec2996e00 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -4681,7 +4681,7 @@ check_subscripter(struct compiler *c, expr_ty e)
         {
             return SUCCESS;
         }
-        /* fall through */
+        _Py_FALLTHROUGH;
     case Set_kind:
     case SetComp_kind:
     case GeneratorExp_kind:
@@ -4714,7 +4714,7 @@ check_index(struct compiler *c, expr_ty e, expr_ty s)
         if (!(PyUnicode_Check(v) || PyBytes_Check(v) || PyTuple_Check(v))) {
             return SUCCESS;
         }
-        /* fall through */
+        _Py_FALLTHROUGH;
     case Tuple_kind:
     case List_kind:
     case ListComp_kind:
diff --git a/Python/crossinterp.c b/Python/crossinterp.c
index a03456a8bbfd6f..acb372af42408e 100644
--- a/Python/crossinterp.c
+++ b/Python/crossinterp.c
@@ -969,7 +969,7 @@ _PyXI_ApplyErrorCode(_PyXI_errcode code, PyInterpreterState 
*interp)
 {
     assert(!PyErr_Occurred());
     switch (code) {
-    case _PyXI_ERR_NO_ERROR:  // fall through
+    case _PyXI_ERR_NO_ERROR: _Py_FALLTHROUGH;
     case _PyXI_ERR_UNCAUGHT_EXCEPTION:
         // There is nothing to apply.
 #ifdef Py_DEBUG
diff --git a/Python/dtoa.c b/Python/dtoa.c
index 8bba06d3b23289..d0c89b2b468f75 100644
--- a/Python/dtoa.c
+++ b/Python/dtoa.c
@@ -1405,7 +1405,7 @@ _Py_dg_strtod(const char *s00, char **se)
     switch (c) {
     case '-':
         sign = 1;
-        /* fall through */
+        _Py_FALLTHROUGH;
     case '+':
         c = *++s;
     }
@@ -1474,7 +1474,7 @@ _Py_dg_strtod(const char *s00, char **se)
         switch (c) {
         case '-':
             esign = 1;
-            /* fall through */
+            _Py_FALLTHROUGH;
         case '+':
             c = *++s;
         }
@@ -2362,7 +2362,7 @@ _Py_dg_dtoa(double dd, int mode, int ndigits,
         break;
     case 2:
         leftright = 0;
-        /* fall through */
+        _Py_FALLTHROUGH;
     case 4:
         if (ndigits <= 0)
             ndigits = 1;
@@ -2370,7 +2370,7 @@ _Py_dg_dtoa(double dd, int mode, int ndigits,
         break;
     case 3:
         leftright = 0;
-        /* fall through */
+        _Py_FALLTHROUGH;
     case 5:
         i = ndigits + k + 1;
         ilim = i;
diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c
index 6af589f966a502..ebd67214f43042 100644
--- a/Python/formatter_unicode.c
+++ b/Python/formatter_unicode.c
@@ -320,7 +320,7 @@ parse_internal_render_format_spec(PyObject *obj,
                 format->thousands_separators = LT_UNDER_FOUR_LOCALE;
                 break;
             }
-            /* fall through */
+            _Py_FALLTHROUGH;
         default:
             invalid_thousands_separator_type(format->thousands_separators, 
format->type);
             return 0;
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 4a5468040f5cc8..14959fb31be201 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -5532,10 +5532,10 @@
             switch (oparg) {
                 case 2:
                 cause = PyStackRef_AsPyObjectSteal(args[1]);
-                /* fall through */
+                _Py_FALLTHROUGH;
                 case 1:
                 exc = PyStackRef_AsPyObjectSteal(args[0]);
-                /* fall through */
+                _Py_FALLTHROUGH;
                 case 0:
                 if (do_raise(tstate, exc, cause)) {
                     assert(oparg == 0);
diff --git a/Python/getargs.c b/Python/getargs.c
index 3e3828010bfaa2..b96ce3a22dae7c 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -2676,7 +2676,7 @@ skipitem(const char **p_format, va_list *p_va, int flags)
                 goto err;
             format++;
         }
-        /* fall through */
+        _Py_FALLTHROUGH;
 
     case 's': /* string */
     case 'z': /* string or None */
diff --git a/Python/importdl.c b/Python/importdl.c
index 7c42d37283c495..964648338394c2 100644
--- a/Python/importdl.c
+++ b/Python/importdl.c
@@ -248,14 +248,14 @@ _Py_ext_module_loader_result_set_error(
 {
 #ifndef NDEBUG
     switch (kind) {
-    case _Py_ext_module_loader_result_EXCEPTION:  /* fall through */
+    case _Py_ext_module_loader_result_EXCEPTION: _Py_FALLTHROUGH;
     case _Py_ext_module_loader_result_ERR_UNREPORTED_EXC:
         assert(PyErr_Occurred());
         break;
-    case _Py_ext_module_loader_result_ERR_MISSING:  /* fall through */
-    case _Py_ext_module_loader_result_ERR_UNINITIALIZED:  /* fall through */
-    case _Py_ext_module_loader_result_ERR_NONASCII_NOT_MULTIPHASE:  /* fall 
through */
-    case _Py_ext_module_loader_result_ERR_NOT_MODULE:  /* fall through */
+    case _Py_ext_module_loader_result_ERR_MISSING: _Py_FALLTHROUGH;
+    case _Py_ext_module_loader_result_ERR_UNINITIALIZED: _Py_FALLTHROUGH;
+    case _Py_ext_module_loader_result_ERR_NONASCII_NOT_MULTIPHASE: 
_Py_FALLTHROUGH;
+    case _Py_ext_module_loader_result_ERR_NOT_MODULE: _Py_FALLTHROUGH;
     case _Py_ext_module_loader_result_ERR_MISSING_DEF:
         assert(!PyErr_Occurred());
         break;
@@ -279,11 +279,11 @@ _Py_ext_module_loader_result_set_error(
         res->kind = _Py_ext_module_kind_INVALID;
         break;
     /* None of the rest affect the result kind. */
-    case _Py_ext_module_loader_result_EXCEPTION:  /* fall through */
-    case _Py_ext_module_loader_result_ERR_MISSING:  /* fall through */
-    case _Py_ext_module_loader_result_ERR_UNREPORTED_EXC:  /* fall through */
-    case _Py_ext_module_loader_result_ERR_NONASCII_NOT_MULTIPHASE:  /* fall 
through */
-    case _Py_ext_module_loader_result_ERR_NOT_MODULE:  /* fall through */
+    case _Py_ext_module_loader_result_EXCEPTION: _Py_FALLTHROUGH;
+    case _Py_ext_module_loader_result_ERR_MISSING: _Py_FALLTHROUGH;
+    case _Py_ext_module_loader_result_ERR_UNREPORTED_EXC: _Py_FALLTHROUGH;
+    case _Py_ext_module_loader_result_ERR_NONASCII_NOT_MULTIPHASE: 
_Py_FALLTHROUGH;
+    case _Py_ext_module_loader_result_ERR_NOT_MODULE: _Py_FALLTHROUGH;
     case _Py_ext_module_loader_result_ERR_MISSING_DEF:
         break;
     default:
@@ -307,14 +307,14 @@ _Py_ext_module_loader_result_apply_error(
 
 #ifndef NDEBUG
     switch (err.kind) {
-    case _Py_ext_module_loader_result_EXCEPTION:  /* fall through */
+    case _Py_ext_module_loader_result_EXCEPTION: _Py_FALLTHROUGH;
     case _Py_ext_module_loader_result_ERR_UNREPORTED_EXC:
         assert(err.exc != NULL);
         break;
-    case _Py_ext_module_loader_result_ERR_MISSING:  /* fall through */
-    case _Py_ext_module_loader_result_ERR_UNINITIALIZED:  /* fall through */
-    case _Py_ext_module_loader_result_ERR_NONASCII_NOT_MULTIPHASE:  /* fall 
through */
-    case _Py_ext_module_loader_result_ERR_NOT_MODULE:  /* fall through */
+    case _Py_ext_module_loader_result_ERR_MISSING: _Py_FALLTHROUGH;
+    case _Py_ext_module_loader_result_ERR_UNINITIALIZED: _Py_FALLTHROUGH;
+    case _Py_ext_module_loader_result_ERR_NONASCII_NOT_MULTIPHASE: 
_Py_FALLTHROUGH;
+    case _Py_ext_module_loader_result_ERR_NOT_MODULE: _Py_FALLTHROUGH;
     case _Py_ext_module_loader_result_ERR_MISSING_DEF:
         assert(err.exc == NULL);
         break;
diff --git a/Python/marshal.c b/Python/marshal.c
index a46fc0ce8813d7..fe97ccde2e5b13 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -1156,7 +1156,7 @@ r_object(RFILE *p)
 
     case TYPE_ASCII_INTERNED:
         is_interned = 1;
-        /* fall through */
+        _Py_FALLTHROUGH;
     case TYPE_ASCII:
         n = r_long(p);
         if (n < 0 || n > SIZE32_MAX) {
@@ -1170,7 +1170,7 @@ r_object(RFILE *p)
 
     case TYPE_SHORT_ASCII_INTERNED:
         is_interned = 1;
-        /* fall through */
+        _Py_FALLTHROUGH;
     case TYPE_SHORT_ASCII:
         n = r_byte(p);
         if (n == EOF) {
@@ -1198,7 +1198,7 @@ r_object(RFILE *p)
 
     case TYPE_INTERNED:
         is_interned = 1;
-        /* fall through */
+        _Py_FALLTHROUGH;
     case TYPE_UNICODE:
         {
         const char *buffer;
diff --git a/Python/modsupport.c b/Python/modsupport.c
index e9abf304e6502c..0fb7783345c78e 100644
--- a/Python/modsupport.c
+++ b/Python/modsupport.c
@@ -306,6 +306,7 @@ do_mkvalue(const char **p_format, va_list *p_va)
             return PyLong_FromSsize_t(va_arg(*p_va, Py_ssize_t));
 #endif
             /* Fall through from 'n' to 'l' if Py_ssize_t is long */
+            _Py_FALLTHROUGH;
         case 'l':
             return PyLong_FromLong(va_arg(*p_va, long));
 
diff --git a/Python/pyhash.c b/Python/pyhash.c
index 4145d9ef4fd7ef..1504fa201c9902 100644
--- a/Python/pyhash.c
+++ b/Python/pyhash.c
@@ -170,12 +170,12 @@ _Py_HashBytes(const void *src, Py_ssize_t len)
 
         switch(len) {
             /* ((hash << 5) + hash) + *p == hash * 33 + *p */
-            case 7: hash = ((hash << 5) + hash) + *p++; /* fallthrough */
-            case 6: hash = ((hash << 5) + hash) + *p++; /* fallthrough */
-            case 5: hash = ((hash << 5) + hash) + *p++; /* fallthrough */
-            case 4: hash = ((hash << 5) + hash) + *p++; /* fallthrough */
-            case 3: hash = ((hash << 5) + hash) + *p++; /* fallthrough */
-            case 2: hash = ((hash << 5) + hash) + *p++; /* fallthrough */
+            case 7: hash = ((hash << 5) + hash) + *p++; _Py_FALLTHROUGH;
+            case 6: hash = ((hash << 5) + hash) + *p++; _Py_FALLTHROUGH;
+            case 5: hash = ((hash << 5) + hash) + *p++; _Py_FALLTHROUGH;
+            case 4: hash = ((hash << 5) + hash) + *p++; _Py_FALLTHROUGH;
+            case 3: hash = ((hash << 5) + hash) + *p++; _Py_FALLTHROUGH;
+            case 2: hash = ((hash << 5) + hash) + *p++; _Py_FALLTHROUGH;
             case 1: hash = ((hash << 5) + hash) + *p++; break;
             default:
                 Py_UNREACHABLE();
@@ -391,13 +391,13 @@ siphash13(uint64_t k0, uint64_t k1, const void *src, 
Py_ssize_t src_sz) {
     t = 0;
     pt = (uint8_t *)&t;
     switch (src_sz) {
-        case 7: pt[6] = in[6]; /* fall through */
-        case 6: pt[5] = in[5]; /* fall through */
-        case 5: pt[4] = in[4]; /* fall through */
+        case 7: pt[6] = in[6]; _Py_FALLTHROUGH;
+        case 6: pt[5] = in[5]; _Py_FALLTHROUGH;
+        case 5: pt[4] = in[4]; _Py_FALLTHROUGH;
         case 4: memcpy(pt, in, sizeof(uint32_t)); break;
-        case 3: pt[2] = in[2]; /* fall through */
-        case 2: pt[1] = in[1]; /* fall through */
-        case 1: pt[0] = in[0]; /* fall through */
+        case 3: pt[2] = in[2]; _Py_FALLTHROUGH;
+        case 2: pt[1] = in[1]; _Py_FALLTHROUGH;
+        case 1: pt[0] = in[0]; break;
     }
     b |= _le64toh(t);
 
@@ -442,13 +442,13 @@ siphash24(uint64_t k0, uint64_t k1, const void *src, 
Py_ssize_t src_sz) {
     t = 0;
     pt = (uint8_t *)&t;
     switch (src_sz) {
-        case 7: pt[6] = in[6]; /* fall through */
-        case 6: pt[5] = in[5]; /* fall through */
-        case 5: pt[4] = in[4]; /* fall through */
+        case 7: pt[6] = in[6]; _Py_FALLTHROUGH;
+        case 6: pt[5] = in[5]; _Py_FALLTHROUGH;
+        case 5: pt[4] = in[4]; _Py_FALLTHROUGH;
         case 4: memcpy(pt, in, sizeof(uint32_t)); break;
-        case 3: pt[2] = in[2]; /* fall through */
-        case 2: pt[1] = in[1]; /* fall through */
-        case 1: pt[0] = in[0]; /* fall through */
+        case 3: pt[2] = in[2]; _Py_FALLTHROUGH;
+        case 2: pt[1] = in[1]; _Py_FALLTHROUGH;
+        case 1: pt[0] = in[0]; break;
     }
     b |= _le64toh(t);
 
diff --git a/Python/pystrtod.c b/Python/pystrtod.c
index 5c8be0447ace4b..2f2b588bd147d8 100644
--- a/Python/pystrtod.c
+++ b/Python/pystrtod.c
@@ -1234,7 +1234,7 @@ char * PyOS_double_to_string(double val,
     case 'E':
         float_strings = uc_float_strings;
         format_code = 'e';
-        /* Fall through. */
+        _Py_FALLTHROUGH;
     case 'e':
         mode = 2;
         precision++;
@@ -1244,7 +1244,7 @@ char * PyOS_double_to_string(double val,
     case 'F':
         float_strings = uc_float_strings;
         format_code = 'f';
-        /* Fall through. */
+        _Py_FALLTHROUGH;
     case 'f':
         mode = 3;
         break;
@@ -1253,7 +1253,7 @@ char * PyOS_double_to_string(double val,
     case 'G':
         float_strings = uc_float_strings;
         format_code = 'g';
-        /* Fall through. */
+        _Py_FALLTHROUGH;
     case 'g':
         mode = 2;
         /* precision 0 makes no sense for 'g' format; interpret as 1 */

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to