diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2023-04-24 11:26:48 +0200 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2023-04-24 18:56:11 +0200 |
commit | 3d68fce3350e209a7d9e3ce338cba53fc2f39f28 (patch) | |
tree | ca8123f154010573ff250ee2a41c499971b0052e | |
parent | 3fa5510872ee38b8019429b1bc360dce72ec2179 (diff) | |
download | cython-3d68fce3350e209a7d9e3ce338cba53fc2f39f28.tar.gz |
Disallow @cfunc together with @ccall on the same function.
-rw-r--r-- | Cython/Compiler/ParseTreeTransforms.py | 2 | ||||
-rw-r--r-- | tests/errors/pure_errors.py | 20 |
2 files changed, 22 insertions, 0 deletions
diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index 1ef6c2112..d90ea4391 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -2894,6 +2894,8 @@ class AdjustDefByDirectives(CythonTransform, SkipDeclarations): # backward compatible default: no exception check, unless there's also a "@returns" declaration except_val = (None, True if return_type_node else False) if 'ccall' in self.directives: + if 'cfunc' in self.directives: + error(node.pos, "cfunc and ccall directives cannot be combined") node = node.as_cfunction( overridable=True, modifiers=modifiers, nogil=nogil, returns=return_type_node, except_val=except_val) diff --git a/tests/errors/pure_errors.py b/tests/errors/pure_errors.py index b153bd2e6..a480d7abe 100644 --- a/tests/errors/pure_errors.py +++ b/tests/errors/pure_errors.py @@ -56,9 +56,29 @@ def test_cdef_return_object_broken(x: object) -> object: return x +@cython.ccall +@cython.cfunc +def test_contradicting_decorators1(x: object) -> object: + return x + + +@cython.cfunc +@cython.ccall +def test_contradicting_decorators2(x: object) -> object: + return x + + _ERRORS = """ 44:22: Calling gil-requiring function not allowed without gil 45:24: Calling gil-requiring function not allowed without gil 48:0: Python functions cannot be declared 'nogil' 53:0: Exception clause not allowed for function returning Python object +59:0: cfunc and ccall directives cannot be combined +65:0: cfunc and ccall directives cannot be combined +""" + +_WARNINGS = """ +# bugs: +59:0: 'test_contradicting_decorators1' redeclared +65:0: 'test_contradicting_decorators2' redeclared """ |