diff options
author | Tom Krauss <thomas.p.krauss@gmail.com> | 2017-02-26 19:17:32 -0600 |
---|---|---|
committer | Tom Krauss <thomas.p.krauss@gmail.com> | 2017-02-26 19:17:32 -0600 |
commit | 2d5722910a38e4f967f096bebcf69593046adf27 (patch) | |
tree | 6b17d41f75888326e5ebda0bd4e477cfd18d35ea | |
parent | 265083abf7d86cd84e00c4af6779072fcc10507c (diff) | |
download | cffi-2d5722910a38e4f967f096bebcf69593046adf27.tar.gz |
in test_c.py, add a test_call_function24 which
calls a C function that returns a "float _Complex"
-rw-r--r-- | c/_cffi_backend.c | 7 | ||||
-rw-r--r-- | c/test_c.py | 10 |
2 files changed, 17 insertions, 0 deletions
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c index 90f6cd2..4ad9fae 100644 --- a/c/_cffi_backend.c +++ b/c/_cffi_backend.c @@ -62,6 +62,8 @@ #include "malloc_closure.h" +#include <complex.h> + #if PY_MAJOR_VERSION >= 3 # define STR_OR_BYTES "bytes" # define PyText_Type PyUnicode_Type @@ -6588,6 +6590,10 @@ static int _testfunc23(char *p) return 1000 * p[0]; return -42; } +static float _Complex _testfunc24(float a, float b) +{ + return a + I*2.0*b; +} static PyObject *b__testfunc(PyObject *self, PyObject *args) { @@ -6621,6 +6627,7 @@ static PyObject *b__testfunc(PyObject *self, PyObject *args) case 21: f = &_testfunc21; break; case 22: f = &_testfunc22; break; case 23: f = &_testfunc23; break; + case 24: f = &_testfunc24; break; default: PyErr_SetNone(PyExc_ValueError); return NULL; diff --git a/c/test_c.py b/c/test_c.py index f00cdf7..23e712e 100644 --- a/c/test_c.py +++ b/c/test_c.py @@ -1084,6 +1084,16 @@ def test_call_function_9(): BSShort = new_primitive_type("short") assert f(3, cast(BSChar, -3), cast(BUChar, 200), cast(BSShort, -5)) == 192 +def test_call_function_24(): + BFloat = new_primitive_type("float") + BFloatComplex = new_primitive_type("float _Complex") + BFunc3 = new_function_type((BFloat, BFloat), BFloatComplex, False) + f = cast(BFunc3, _testfunc(24)) + result = f(1.25, 5.1) + assert type(result) == complex + assert result.real == 1.25 # exact + assert (result.imag != 2*5.1) and (abs(result.imag - 2*5.1) < 1e-5) # inexact + def test_cannot_call_with_a_autocompleted_struct(): BSChar = new_primitive_type("signed char") BDouble = new_primitive_type("double") |