summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Bradshaw <robertwb@gmail.com>2017-07-10 10:41:41 -0700
committerGitHub <noreply@github.com>2017-07-10 10:41:41 -0700
commit5ac65106bc1df31daf1f8c16e660f8cf92767ffb (patch)
tree8673cc6fd8c4b752d74b2cfc4f11fb24feb434c0
parenta4fb856ace9c8be3ab84f2ae3b5c697d877f562f (diff)
parent10b6817e732ad58be6dda9c570dfc19a6e13e8c1 (diff)
downloadcython-5ac65106bc1df31daf1f8c16e660f8cf92767ffb.tar.gz
Merge pull request #1765 from robertwb/fallthrough
First attempt at explicit fallthrough annotation.
-rw-r--r--Cython/Compiler/Nodes.py4
-rw-r--r--Cython/Utility/ModuleSetupCode.c21
2 files changed, 25 insertions, 0 deletions
diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py
index 65f8d938d..6565b7fd8 100644
--- a/Cython/Compiler/Nodes.py
+++ b/Cython/Compiler/Nodes.py
@@ -3623,6 +3623,7 @@ class DefNodeWrapper(FuncDefNode):
if i >= min_positional_args-1:
code.put('case %2d: ' % (i+1))
code.putln("values[%d] = PyTuple_GET_ITEM(%s, %d);" % (i, Naming.args_cname, i))
+ code.putln('CYTHON_FALLTHROUGH')
if min_positional_args == 0:
code.put('case 0: ')
code.putln('break;')
@@ -3749,6 +3750,7 @@ class DefNodeWrapper(FuncDefNode):
code.put('case %2d: ' % (i+1))
code.putln("values[%d] = PyTuple_GET_ITEM(%s, %d);" % (
i, Naming.args_cname, i))
+ code.putln('CYTHON_FALLTHROUGH')
code.putln('case 0: break;')
if not self.star_arg:
code.put('default: ') # more arguments than allowed
@@ -3817,6 +3819,8 @@ class DefNodeWrapper(FuncDefNode):
self.name, pystring_cname))
code.putln(code.error_goto(self.pos))
code.putln('}')
+ if max_positional_args > 0 and i < last_required_arg:
+ code.putln('CYTHON_FALLTHROUGH')
if max_positional_args > 0:
code.putln('}')
diff --git a/Cython/Utility/ModuleSetupCode.c b/Cython/Utility/ModuleSetupCode.c
index f8c7760cf..80f304700 100644
--- a/Cython/Utility/ModuleSetupCode.c
+++ b/Cython/Utility/ModuleSetupCode.c
@@ -356,6 +356,14 @@
#define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
#endif
+#ifndef __has_attribute
+ #define __has_attribute(x) 0
+#endif
+
+#ifndef __has_cpp_attribute
+ #define __has_cpp_attribute(x) 0
+#endif
+
// backport of PyAsyncMethods from Py3.5 to older Py3.x versions
// (mis-)using the "tp_reserved" type slot which is re-activated as "tp_as_async" in Py3.5
#if CYTHON_USE_ASYNC_SLOTS
@@ -434,6 +442,19 @@
#include <stdint.h>
#endif
+
+#ifndef CYTHON_FALLTHROUGH
+ #if __has_cpp_attribute(fallthrough)
+ #define CYTHON_FALLTHROUGH [[fallthrough]]
+ #elif __has_cpp_attribute(clang::fallthrough)
+ #define CYTHON_FALLTHROUGH [[clang::fallthrough]]
+ #elif __has_attribute(fallthrough) || (defined(__GNUC__) && defined(__attribute__))
+ #define CYTHON_FALLTHROUGH __attribute__((fallthrough))
+ #else
+ #define CYTHON_FALLTHROUGH
+ #endif
+#endif
+
/////////////// CInitCode ///////////////
// inline attribute