Commit 8bc46f37 authored by Stefan Behnel's avatar Stefan Behnel

Enable temps for C functions by using function pointers instead.

Closes GH-3418.
parent 6c9996c6
......@@ -21,6 +21,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)
......
......@@ -832,6 +832,9 @@ class FunctionState(object):
type = type.const_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.
......
......@@ -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)
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