| 
9 | 9 | #endif  | 
10 | 10 | 
 
  | 
11 | 11 | 
 
  | 
 | 12 | +// Preprocessor check for a builtin preprocessor function. Always return 0  | 
 | 13 | +// if __has_builtin() macro is not defined.  | 
 | 14 | +//  | 
 | 15 | +// __has_builtin() is available on clang and GCC 10.  | 
 | 16 | +#ifdef __has_builtin  | 
 | 17 | +#  define _Py__has_builtin(x) __has_builtin(x)  | 
 | 18 | +#else  | 
 | 19 | +#  define _Py__has_builtin(x) 0  | 
 | 20 | +#endif  | 
 | 21 | + | 
 | 22 | +// Preprocessor check for a compiler __attribute__. Always return 0  | 
 | 23 | +// if __has_attribute() macro is not defined.  | 
 | 24 | +#ifdef __has_attribute  | 
 | 25 | +#  define _Py__has_attribute(x) __has_attribute(x)  | 
 | 26 | +#else  | 
 | 27 | +#  define _Py__has_attribute(x) 0  | 
 | 28 | +#endif  | 
 | 29 | + | 
12 | 30 | // Macro to use C++ static_cast<> in the Python C API.  | 
13 | 31 | #ifdef __cplusplus  | 
14 | 32 | #  define _Py_STATIC_CAST(type, expr) static_cast<type>(expr)  | 
@@ -532,16 +550,6 @@ extern "C" {  | 
532 | 550 | #endif  | 
533 | 551 | 
 
  | 
534 | 552 | 
 
  | 
535 |  | -// Preprocessor check for a builtin preprocessor function. Always return 0  | 
536 |  | -// if __has_builtin() macro is not defined.  | 
537 |  | -//  | 
538 |  | -// __has_builtin() is available on clang and GCC 10.  | 
539 |  | -#ifdef __has_builtin  | 
540 |  | -#  define _Py__has_builtin(x) __has_builtin(x)  | 
541 |  | -#else  | 
542 |  | -#  define _Py__has_builtin(x) 0  | 
543 |  | -#endif  | 
544 |  | - | 
545 | 553 | // _Py_TYPEOF(expr) gets the type of an expression.  | 
546 | 554 | //  | 
547 | 555 | // Example: _Py_TYPEOF(x) x_copy = (x);  | 
@@ -607,4 +615,21 @@ extern "C" {  | 
607 | 615 | #  define _SGI_MP_SOURCE  | 
608 | 616 | #endif  | 
609 | 617 | 
 
  | 
 | 618 | +// Explicit fallthrough in switch case to avoid warnings  | 
 | 619 | +// with compiler flag -Wimplicit-fallthrough.  | 
 | 620 | +//  | 
 | 621 | +// Usage example:  | 
 | 622 | +//  | 
 | 623 | +//     switch (value) {  | 
 | 624 | +//     case 1: _Py_FALLTHROUGH;  | 
 | 625 | +//     case 2: code; break;  | 
 | 626 | +//     }  | 
 | 627 | +//  | 
 | 628 | +// __attribute__((fallthrough)) was introduced in GCC 7.  | 
 | 629 | +#if _Py__has_attribute(fallthrough)  | 
 | 630 | +#  define _Py_FALLTHROUGH __attribute__((fallthrough))  | 
 | 631 | +#else  | 
 | 632 | +#  define _Py_FALLTHROUGH do { } while (0)  | 
 | 633 | +#endif  | 
 | 634 | + | 
610 | 635 | #endif /* Py_PYPORT_H */  | 
0 commit comments