]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-121040: Use __attribute__((fallthrough)) (#121044)
authorVictor Stinner <vstinner@python.org>
Thu, 27 Jun 2024 09:58:44 +0000 (11:58 +0200)
committerGitHub <noreply@github.com>
Thu, 27 Jun 2024 09:58:44 +0000 (09:58 +0000)
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 <mail@sobolevn.me>
29 files changed:
Include/exports.h
Include/pyport.h
Modules/_csv.c
Modules/_ctypes/_ctypes.c
Modules/_ctypes/stgdict.c
Modules/_interpqueuesmodule.c
Modules/_ssl.c
Modules/_struct.c
Modules/_testcapi/exceptions.c
Modules/cjkcodecs/_codecs_iso2022.c
Modules/overlapped.c
Modules/socketmodule.c
Modules/zlibmodule.c
Objects/rangeobject.c
Objects/stringlib/codecs.h
Objects/unicodeobject.c
Python/assemble.c
Python/bytecodes.c
Python/compile.c
Python/crossinterp.c
Python/dtoa.c
Python/formatter_unicode.c
Python/generated_cases.c.h
Python/getargs.c
Python/importdl.c
Python/marshal.c
Python/modsupport.c
Python/pyhash.c
Python/pystrtod.c

index ce601216f171563df33cec3e2ed5cbe42aad5a00..0c646d5beb6ad6be5e04b90a0031a10c8f610896 100644 (file)
  * 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")))
index 1f7a9b41e0ae2b387abd7e1557fe427dda6daa64..2b6bd4c21110e543104ca884b14ddba60b7a92fa 100644 (file)
@@ -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 */
index 9d6b66d4938687ce79f834dff7e29446ae4e7b71..9964c383b8ad092ec98f17776793f3ed1684e0e9 100644 (file)
@@ -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 */
index 222700b4b7cc694d624a40f0a179c168afde21d8..1ff108a39320cffb2e92886db553b03d751fddc5 100644 (file)
@@ -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. */
index 52d8ec92380b3067f21afc8ed6887f6cc1d494cc..970f0a033fbb0b6849ace7b1a043d2811ee9e025 100644 (file)
@@ -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",
index 556953db6b803940d63a019bb29e570d274b2083..c99111b861cc327d36f4cd4b9b6ac0f02c628fdc 100644 (file)
@@ -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;
index 9d50b576ba337f4ce0784b9d694a5e201cdcc470..14a8edfa67cec4764a8f56423bd38cef44ed7c02 100644 (file)
@@ -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:
index 905dcbdeeddc5a9e84072ffc63997f6d817f35bf..6a68478dd45d36e1f15444a35e2b7b2fece105f8 100644 (file)
@@ -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;
index 42a9915143e6fa7eae3d0e7a56353c89a5d67f4d..316ef0e7ad7e55be2ca821527e4b136074aa9c9d 100644 (file)
@@ -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);
index e8835ad0909633df124da6d85f777cdb24c27346..ef6faeb71274e1d192e13fd3d7db39cce4535ff7 100644 (file)
@@ -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;
index 77ee70ae133c858586460ec920b6ca96950f8238..308a0dab7fab1aea1c43c22521f36f4afcabbff0 100644 (file)
@@ -923,7 +923,7 @@ _overlapped_Overlapped_getresult_impl(OverlappedObject *self, BOOL wait)
             {
                 break;
             }
-            /* fall through */
+            _Py_FALLTHROUGH;
         default:
             return SetFromWindowsErr(err);
     }
index 0626d7934983db1e146cf3c0d433358c3fafcafa..6d161478be2d9dd72646f61493c710947183ee88 100644 (file)
@@ -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:
index b115f67f228ba7d55b6f643e1c9d1e5998b47621..c5aaf22eeb294876c85bea24559d12a7334c341e 100644 (file)
@@ -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:
index 7da6162744ffd6fc360debd5b3c99a019688e4ba..d5db48c143324fff193ad9f586107465920e8b23 100644 (file)
@@ -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]);
index f98e71c3fc6ecf2a4943dbe8829bae037794610e..440410d0aef17d33ab793a746db329607e4bdaa7 100644 (file)
@@ -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",
index acdec61cfdb4115acbfd18c3208bd69a5999b7a6..9738442ab962b0de5371fda20c6eaa03ab595c3d 100644 (file)
@@ -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();
         }
index 945c8ac39f53acd65c3a73e9adb511ece2103120..f7b88b519f5f7131a568669cccdca3b71a24f4ee 100644 (file)
@@ -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;
index 67061ac26323e889b492dbddc8075de00715b0ce..8dfce77dfca29717ab1c9be9088288b0316b0104 100644 (file)
@@ -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);
index cdac438393dc0c8f95697f7b614075f9ce6d89e7..69de0ec2996e00995143ce217da07c0591f9da31 100644 (file)
@@ -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:
index a03456a8bbfd6f6f16fefa56bae3d36ce0020317..acb372af42408e74b4960a510fa201cc0cc7cbe2 100644 (file)
@@ -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
index 8bba06d3b232898f2010ec0548895d9580be99a8..d0c89b2b468f75ed964a61e23e17a9f3ec499de0 100644 (file)
@@ -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;
index 6af589f966a502a53f18088933be5883b5a68d83..ebd67214f43042932f61672cc728312821125443 100644 (file)
@@ -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;
index 4a5468040f5cc8b6d33930c752b3a4318273db54..14959fb31be2013a79b324df6743e585246f61ad 100644 (file)
             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);
index 3e3828010bfaa2367c0551c13f619aab613c0379..b96ce3a22dae7c457f059a365c449dbfcd6a9aa1 100644 (file)
@@ -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 */
index 7c42d37283c4954538711bd9fc71119c8c7a35c4..964648338394c202c972c433965742c4cf4b653d 100644 (file)
@@ -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;
index a46fc0ce8813d74362b6ad939c7457fb1a1f04e2..fe97ccde2e5b131c95234a7ea87f96ceeb841a90 100644 (file)
@@ -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;
index e9abf304e6502c6725f669b88651d3c79a98dbf9..0fb7783345c78eb8cf6e3feaf81c508762210e8d 100644 (file)
@@ -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));
 
index 4145d9ef4fd7ef90ff8a1688da24da7fa598acdf..1504fa201c9902f9a2fc6a870a92eff2fc75072e 100644 (file)
@@ -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);
 
index 5c8be0447ace4bbd13788b9a7f6990072ed06f7b..2f2b588bd147d8998f33efda9b919807e3b42d0b 100644 (file)
@@ -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 */