diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2020-03-21 14:52:15 +0100 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2020-03-21 14:52:15 +0100 |
commit | ba53f9398bb1cb20e201bfe080d295406d2300fa (patch) | |
tree | 15b16f2acb7b85ffd1a3a0175edf38c85aff6ede | |
parent | cdbd7923d60edce6cf280ebbec25dbfd01e826c0 (diff) | |
parent | 8bc46f37e55a3e36648ce522afa1f5e0d5f7934d (diff) | |
download | cython-ba53f9398bb1cb20e201bfe080d295406d2300fa.tar.gz |
Merge branch '0.29.x'
-rw-r--r-- | CHANGES.rst | 3 | ||||
-rw-r--r-- | Cython/Compiler/Code.py | 3 | ||||
-rw-r--r-- | tests/run/if_else_expr.pyx | 12 |
3 files changed, 18 insertions, 0 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index 35b8bf1a3..5f0a16111 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -210,6 +210,9 @@ Bugs fixed implemented functions. Patch by David Woods. (Github issue #3384) +* Using C functions as temporary values lead to invalid C code. + Original patch by David Woods. (Github issue #3418) + * Fix an unhandled C++ exception in comparisons. Patch by David Woods. (Github issue #3361) diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index 53e637ccd..06e2662fb 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -832,6 +832,9 @@ class FunctionState(object): type = type.cv_base_type elif type.is_reference and not type.is_fake_reference: type = type.ref_base_type + elif type.is_cfunction: + from . import PyrexTypes + type = PyrexTypes.c_ptr_type(type) # A function itself isn't an l-value if not type.is_pyobject and not type.is_memoryviewslice: # Make manage_ref canonical, so that manage_ref will always mean # a decref is needed. diff --git a/tests/run/if_else_expr.pyx b/tests/run/if_else_expr.pyx index df4ae6c80..41657ec5a 100644 --- a/tests/run/if_else_expr.pyx +++ b/tests/run/if_else_expr.pyx @@ -55,3 +55,15 @@ def test_syntax(): y = 0 if 1.0else 1 z = 0 if 1.else 1 return x, y, z + + +from libc cimport math + +def test_cfunc_ptrs(double x, bint round_down): + """ + >>> test_cfunc_ptrs(2.5, round_down=True) + 2.0 + >>> test_cfunc_ptrs(2.5, round_down=False) + 3.0 + """ + return (math.floor if round_down else math.ceil)(x) |