diff --git a/Include/pymem.h b/Include/pymem.h index 10b5bea5eb..ae7190a37d 100644 --- a/Include/pymem.h +++ b/Include/pymem.h @@ -72,9 +72,9 @@ PyAPI_FUNC(void) PyMem_Free(void *); /* Returns NULL to indicate error if a negative size or size larger than Py_ssize_t can represent is supplied. Helps prevents security holes. */ #define PyMem_MALLOC(n) ((size_t)(n) > (size_t)PY_SSIZE_T_MAX ? NULL \ - : malloc((n) ? (n) : 1)) + : malloc((n) != 0? (n) : 1)) #define PyMem_REALLOC(p, n) ((size_t)(n) > (size_t)PY_SSIZE_T_MAX ? NULL \ - : realloc((p), (n) ? (n) : 1)) + : realloc((p), (n) != 0? (n) : 1)) #define PyMem_FREE free #endif /* PYMALLOC_DEBUG */ diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index aa34478e92..15a9c45398 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -3704,6 +3704,9 @@ _build_callargs(PyCFuncPtrObject *self, PyObject *argtypes, *pinoutmask |= (1 << i); /* mark as inout arg */ (*pnumretvals)++; /* fall through to PARAMFLAG_FIN... */ +#if defined(__GNUC__) && __GNUC__ >= 7 + __attribute__ ((fallthrough)); +#endif case 0: case PARAMFLAG_FIN: /* 'in' parameter. Copy it from inargs. */ diff --git a/Modules/zlib/inflate.c b/Modules/zlib/inflate.c index 870f89bb4d..5dc4a3e020 100644 --- a/Modules/zlib/inflate.c +++ b/Modules/zlib/inflate.c @@ -85,6 +85,10 @@ #include "inflate.h" #include "inffast.h" +#if defined(__GNUC__) && __GNUC__ >= 7 +#pragma GCC diagnostic ignored "-Wimplicit-fallthrough" +#endif + #ifdef MAKEFIXED # ifndef BUILDFIXED # define BUILDFIXED diff --git a/Objects/stringobject.c b/Objects/stringobject.c index c1e12a7aae..1f913b7572 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -590,6 +590,7 @@ string_dealloc(PyObject *op) case SSTATE_INTERNED_IMMORTAL: Py_FatalError("Immortal interned string died."); + // fall through default: Py_FatalError("Inconsistent interned string state."); diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 08723ac9b8..39fe62118f 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -796,6 +796,9 @@ PyUnicode_FromFormatV(const char *format, va_list vargs) #endif /* fall through... */ } +#if defined(__GNUC__) && __GNUC__ >= 7 + __attribute__ ((fallthrough)); +#endif case '%': n++; break; diff --git a/Python/ast.c b/Python/ast.c index e5d7ac6600..e53c7f6ff8 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -549,6 +549,7 @@ ast_for_comp_op(struct compiling *c, const node *n) return In; if (strcmp(STR(n), "is") == 0) return Is; + break; default: PyErr_Format(PyExc_SystemError, "invalid comp_op: %s", STR(n)); @@ -563,6 +564,7 @@ ast_for_comp_op(struct compiling *c, const node *n) return NotIn; if (strcmp(STR(CHILD(n, 0)), "is") == 0) return IsNot; + break; default: PyErr_Format(PyExc_SystemError, "invalid comp_op: %s %s", STR(CHILD(n, 0)), STR(CHILD(n, 1))); @@ -2284,7 +2286,7 @@ ast_for_print_stmt(struct compiling *c, const node *n) dest = ast_for_expr(c, CHILD(n, 2)); if (!dest) return NULL; - start = 4; + start = 4; } values_count = (NCH(n) + 1 - start) / 2; if (values_count) { @@ -2417,6 +2419,7 @@ ast_for_flow_stmt(struct compiling *c, const node *n) return Raise(expr1, expr2, expr3, LINENO(n), n->n_col_offset, c->c_arena); } + break; default: PyErr_Format(PyExc_SystemError, "unexpected flow_stmt: %d", TYPE(ch)); @@ -2620,14 +2623,14 @@ ast_for_import_stmt(struct compiling *c, const node *n) alias_ty import_alias = alias_for_import_name(c, n, 1); if (!import_alias) return NULL; - asdl_seq_SET(aliases, 0, import_alias); + asdl_seq_SET(aliases, 0, import_alias); } else { for (i = 0; i < NCH(n); i += 2) { alias_ty import_alias = alias_for_import_name(c, CHILD(n, i), 1); if (!import_alias) return NULL; - asdl_seq_SET(aliases, i / 2, import_alias); + asdl_seq_SET(aliases, i / 2, import_alias); } } if (mod != NULL) diff --git a/Python/ceval.c b/Python/ceval.c index fa9e7e0ee0..35dab338b7 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -19,6 +19,12 @@ #include +#if defined(__GNUC__) && __GNUC__ >= 7 +#define fallthrough __attribute__((fallthrough)); +#else +#define fallthrough ; +#endif + #ifndef WITH_TSC #define READ_TIMESTAMP(var) @@ -724,12 +730,14 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) #define TARGET_NOARG(op) \ TARGET_##op: \ opcode = op; \ + fallthrough; \ case op:\ #define TARGET(op) \ TARGET_##op: \ opcode = op; \ oparg = NEXTARG(); \ + fallthrough; \ case op:\ @@ -2057,6 +2065,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) /* Fallthrough */ case 1: w = POP(); /* exc */ + // fall through case 0: /* Fallthrough */ why = do_raise(w, v, u); break; @@ -2685,7 +2694,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) JUMPTO(oparg); else break; - DISPATCH(); + DISPATCH(); } PREDICTED_WITH_ARG(POP_JUMP_IF_TRUE); @@ -2711,7 +2720,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) ; else break; - DISPATCH(); + DISPATCH(); } TARGET(JUMP_IF_FALSE_OR_POP) @@ -2736,7 +2745,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) JUMPTO(oparg); else break; - DISPATCH(); + DISPATCH(); } TARGET(JUMP_IF_TRUE_OR_POP) @@ -2762,7 +2771,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) } else break; - DISPATCH(); + DISPATCH(); } PREDICTED_WITH_ARG(JUMP_ABSOLUTE); @@ -2820,7 +2829,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) x = v = POP(); Py_DECREF(v); JUMPBY(oparg); - DISPATCH(); + DISPATCH(); } TARGET_NOARG(BREAK_LOOP) diff --git a/Python/compile.c b/Python/compile.c index 290075763a..51f89a30a2 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -3079,12 +3079,18 @@ compiler_visit_expr(struct compiler *c, expr_ty e) switch (e->v.Attribute.ctx) { case AugLoad: ADDOP(c, DUP_TOP); +#if defined(__GNUC__) && __GNUC__ >= 7 + __attribute__ ((fallthrough)); +#endif /* Fall through to load */ case Load: ADDOP_NAME(c, LOAD_ATTR, e->v.Attribute.attr, names); break; case AugStore: ADDOP(c, ROT_TWO); +#if defined(__GNUC__) && __GNUC__ >= 7 + __attribute__ ((fallthrough)); +#endif /* Fall through to save */ case Store: ADDOP_NAME(c, STORE_ATTR, e->v.Attribute.attr, names); diff --git a/Python/dtoa.c b/Python/dtoa.c index 73e23af010..5731008919 100644 --- a/Python/dtoa.c +++ b/Python/dtoa.c @@ -1527,6 +1527,9 @@ _Py_dg_strtod(const char *s00, char **se) switch (c) { case '-': sign = 1; +#if defined(__GNUC__) && __GNUC__ >= 7 + __attribute__ ((fallthrough)); +#endif /* no break */ case '+': c = *++s; @@ -1596,6 +1599,9 @@ _Py_dg_strtod(const char *s00, char **se) switch (c) { case '-': esign = 1; +#if defined(__GNUC__) && __GNUC__ >= 7 + __attribute__ ((fallthrough)); +#endif /* no break */ case '+': c = *++s; @@ -2514,6 +2520,9 @@ _Py_dg_dtoa(double dd, int mode, int ndigits, break; case 2: leftright = 0; +#if defined(__GNUC__) && __GNUC__ >= 7 + __attribute__ ((fallthrough)); +#endif /* no break */ case 4: if (ndigits <= 0) @@ -2522,6 +2531,9 @@ _Py_dg_dtoa(double dd, int mode, int ndigits, break; case 3: leftright = 0; +#if defined(__GNUC__) && __GNUC__ >= 7 + __attribute__ ((fallthrough)); +#endif /* no break */ case 5: i = ndigits + k + 1; diff --git a/Python/getargs.c b/Python/getargs.c index 81a27217bb..383653c5c7 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -1736,6 +1736,9 @@ skipitem(const char **p_format, va_list *p_va, int flags) /* after 'e', only 's' and 't' is allowed */ goto err; format++; +#if defined(__GNUC__) && __GNUC__ >= 7 + __attribute__ ((fallthrough)); +#endif /* explicit fallthrough to string cases */ } diff --git a/configure.ac b/configure.ac index 2c998b1ee9..b2aa06f88e 100644 --- a/configure.ac +++ b/configure.ac @@ -1121,6 +1121,9 @@ yes) BASECFLAGS="$BASECFLAGS -fno-strict-aliasing" fi + # disable cast function type warning for newer compilers + BASECFLAGS="$BASECFLAGS -Wno-cast-function-type" + # if using gcc on alpha, use -mieee to get (near) full IEEE 754 # support. Without this, treatment of subnormals doesn't follow # the standard.