[pypy-commit] cffi sirtom67/float_complex: in test_c.py, add a test_call_function24 which
sirtom67
pypy.commits at gmail.com
Sun Feb 26 20:18:20 EST 2017
Author: Tom Krauss <thomas.p.krauss at gmail.com>
Branch: sirtom67/float_complex
Changeset: r2893:7b2c8b6072c2
Date: 2017-02-26 19:17 -0600
http://bitbucket.org/cffi/cffi/changeset/7b2c8b6072c2/
Log: in test_c.py, add a test_call_function24 which calls a C function
that returns a "float _Complex"
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- 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 @@
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 @@
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
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -1084,6 +1084,16 @@
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")
More information about the pypy-commit
mailing list