Commit 10b6817e authored by Robert Bradshaw's avatar Robert Bradshaw

First attempt at explicit fallthrough annotation.

parent e8a178e8
...@@ -3623,6 +3623,7 @@ class DefNodeWrapper(FuncDefNode): ...@@ -3623,6 +3623,7 @@ class DefNodeWrapper(FuncDefNode):
if i >= min_positional_args-1: if i >= min_positional_args-1:
code.put('case %2d: ' % (i+1)) code.put('case %2d: ' % (i+1))
code.putln("values[%d] = PyTuple_GET_ITEM(%s, %d);" % (i, Naming.args_cname, i)) code.putln("values[%d] = PyTuple_GET_ITEM(%s, %d);" % (i, Naming.args_cname, i))
code.putln('CYTHON_FALLTHROUGH')
if min_positional_args == 0: if min_positional_args == 0:
code.put('case 0: ') code.put('case 0: ')
code.putln('break;') code.putln('break;')
...@@ -3749,6 +3750,7 @@ class DefNodeWrapper(FuncDefNode): ...@@ -3749,6 +3750,7 @@ class DefNodeWrapper(FuncDefNode):
code.put('case %2d: ' % (i+1)) code.put('case %2d: ' % (i+1))
code.putln("values[%d] = PyTuple_GET_ITEM(%s, %d);" % ( code.putln("values[%d] = PyTuple_GET_ITEM(%s, %d);" % (
i, Naming.args_cname, i)) i, Naming.args_cname, i))
code.putln('CYTHON_FALLTHROUGH')
code.putln('case 0: break;') code.putln('case 0: break;')
if not self.star_arg: if not self.star_arg:
code.put('default: ') # more arguments than allowed code.put('default: ') # more arguments than allowed
...@@ -3817,6 +3819,8 @@ class DefNodeWrapper(FuncDefNode): ...@@ -3817,6 +3819,8 @@ class DefNodeWrapper(FuncDefNode):
self.name, pystring_cname)) self.name, pystring_cname))
code.putln(code.error_goto(self.pos)) code.putln(code.error_goto(self.pos))
code.putln('}') code.putln('}')
if max_positional_args > 0 and i < last_required_arg:
code.putln('CYTHON_FALLTHROUGH')
if max_positional_args > 0: if max_positional_args > 0:
code.putln('}') code.putln('}')
......
...@@ -356,6 +356,14 @@ ...@@ -356,6 +356,14 @@
#define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass) #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
#endif #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 // 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 // (mis-)using the "tp_reserved" type slot which is re-activated as "tp_as_async" in Py3.5
#if CYTHON_USE_ASYNC_SLOTS #if CYTHON_USE_ASYNC_SLOTS
...@@ -434,6 +442,19 @@ ...@@ -434,6 +442,19 @@
#include <stdint.h> #include <stdint.h>
#endif #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 /////////////// /////////////// CInitCode ///////////////
// inline attribute // inline attribute
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment