Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit a5d5f19e29427c90de09624f9334730fc7212f3a 1 parent 9b40a7d
scoder authored
Showing with 27 additions and 1 deletion.
  1. +1 −1  Cython/Compiler/ParseTreeTransforms.py
  2. +26 −0 tests/run/pure_py.py
2  Cython/Compiler/ParseTreeTransforms.py
View
@@ -1897,7 +1897,7 @@ def visit_CompilerDirectivesNode(self, node):
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:
26 tests/run/pure_py.py
View
@@ -1,5 +1,7 @@
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)
Please sign in to comment.
Something went wrong with that request. Please try again.