Commit a5d5f19e authored by Stefan Behnel's avatar Stefan Behnel

pure mode: propagate @returns() declaration for @ccall functions

parent 9b40a7d6
......@@ -1897,7 +1897,7 @@ class AdjustDefByDirectives(CythonTransform, SkipDeclarations):
def visit_DefNode(self, node):
if 'ccall' in self.directives:
node = node.as_cfunction(overridable=True)
node = node.as_cfunction(overridable=True, returns=self.directives.get('returns'))
return self.visit(node)
if 'cfunc' in self.directives:
if self.in_py_class:
......
import cython
is_compiled = cython.compiled
NULL = 5
_NULL = NULL
......@@ -170,3 +172,27 @@ def test_declare_c_types(n):
#z01 = cython.declare(cython.floatcomplex, n+1j)
#z02 = cython.declare(cython.doublecomplex, n+1j)
#z03 = cython.declare(cython.longdoublecomplex, n+1j)
@cython.ccall
@cython.returns(cython.double)
def c_call(x):
"""
Test that a declared return type is honoured when compiled.
>>> result, return_type = call_ccall(1)
>>> (not is_compiled and 'double') or return_type
'double'
>>> (is_compiled and 'int') or return_type
'int'
>>> (not is_compiled and 1.0) or result
1.0
>>> (is_compiled and 1) or result
1
"""
return x
def call_ccall(x):
ret = c_call(x)
return ret, cython.typeof(ret)
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