Skip to content

Commit ac407f0

Browse files
authored
Use '_cffi_float_complex_t' or '_cffi_double_complex_t' more systematically (#111)
* (2) Use '_cffi_float_complex_t' or '_cffi_double_complex_t' more systematically. Should fix the problem that FFI().typeof('float _Complex') stopped working. * test fixes
1 parent 88e67cc commit ac407f0

File tree

5 files changed

+15
-16
lines changed

5 files changed

+15
-16
lines changed

src/c/_cffi_backend.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
#define CT_UNION 0x080 /* union */
218218
#define CT_FUNCTIONPTR 0x100 /* pointer to function */
219219
#define CT_VOID 0x200 /* void */
220-
#define CT_PRIMITIVE_COMPLEX 0x400 /* float _Complex, double _Complex */
220+
#define CT_PRIMITIVE_COMPLEX 0x400 /* _cffi_float/double_complex_t */
221221

222222
/* other flags that may also be set in addition to the base flag: */
223223
#define CT_IS_VOIDCHAR_PTR 0x00001000
@@ -4728,8 +4728,8 @@ static PyObject *new_primitive_type(const char *name)
47284728
EPTYPE(f, float, CT_PRIMITIVE_FLOAT ) \
47294729
EPTYPE(d, double, CT_PRIMITIVE_FLOAT ) \
47304730
EPTYPE(ld, long double, CT_PRIMITIVE_FLOAT | CT_IS_LONGDOUBLE ) \
4731-
EPTYPE2(fc, "float _Complex", cffi_float_complex_t, CT_PRIMITIVE_COMPLEX ) \
4732-
EPTYPE2(dc, "double _Complex", cffi_double_complex_t, CT_PRIMITIVE_COMPLEX ) \
4731+
EPTYPE2(fc, "_cffi_float_complex_t", cffi_float_complex_t, CT_PRIMITIVE_COMPLEX)\
4732+
EPTYPE2(dc, "_cffi_double_complex_t", cffi_double_complex_t, CT_PRIMITIVE_COMPLEX)\
47334733
ENUM_PRIMITIVE_TYPES_WCHAR \
47344734
EPTYPE2(c16, "char16_t", cffi_char16_t, CT_PRIMITIVE_CHAR ) \
47354735
EPTYPE2(c32, "char32_t", cffi_char32_t, CT_PRIMITIVE_CHAR ) \
@@ -7656,14 +7656,13 @@ static int _testfunc23(char *p)
76567656
}
76577657

76587658
#if 0 /* libffi doesn't properly support complexes currently */
7659-
/* also, MSVC might not support _Complex... */
76607659
/* if this is enabled one day, remember to also add _Complex
76617660
* arguments in addition to return values. */
7662-
static float _Complex _testfunc24(float a, float b)
7661+
static _cffi_float_complex_t _testfunc24(float a, float b)
76637662
{
76647663
return a + I*2.0*b;
76657664
}
7666-
static double _Complex _testfunc25(double a, double b)
7665+
static _cffi_double_complex_t _testfunc25(double a, double b)
76677666
{
76687667
return a + I*2.0*b;
76697668
}

src/c/realize_c_type.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ static PyObject *build_primitive_type(int num)
151151
"uint_fast64_t",
152152
"intmax_t",
153153
"uintmax_t",
154-
"float _Complex",
155-
"double _Complex",
154+
"_cffi_float_complex_t",
155+
"_cffi_double_complex_t",
156156
"char16_t",
157157
"char32_t",
158158
};

src/c/test_c.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def test_float_types():
247247
def test_complex_types():
248248
INF = 1E200 * 1E200
249249
for name in ["float", "double"]:
250-
p = new_primitive_type(name + " _Complex")
250+
p = new_primitive_type("_cffi_" + name + "_complex_t")
251251
assert bool(cast(p, 0)) is False
252252
assert bool(cast(p, INF))
253253
assert bool(cast(p, -INF))
@@ -1246,7 +1246,7 @@ def test_call_function_9():
12461246

12471247
def test_call_function_24():
12481248
BFloat = new_primitive_type("float")
1249-
BFloatComplex = new_primitive_type("float _Complex")
1249+
BFloatComplex = new_primitive_type("_cffi_float_complex_t")
12501250
BFunc3 = new_function_type((BFloat, BFloat), BFloatComplex, False)
12511251
if 0: # libffi returning nonsense silently, so logic disabled for now
12521252
f = cast(BFunc3, _testfunc(24))
@@ -1260,7 +1260,7 @@ def test_call_function_24():
12601260

12611261
def test_call_function_25():
12621262
BDouble = new_primitive_type("double")
1263-
BDoubleComplex = new_primitive_type("double _Complex")
1263+
BDoubleComplex = new_primitive_type("_cffi_double_complex_t")
12641264
BFunc3 = new_function_type((BDouble, BDouble), BDoubleComplex, False)
12651265
if 0: # libffi returning nonsense silently, so logic disabled for now
12661266
f = cast(BFunc3, _testfunc(25))
@@ -4536,9 +4536,9 @@ def test_unaligned_types():
45364536
buf = buffer(pbuf)
45374537
#
45384538
for name in ['short', 'int', 'long', 'long long', 'float', 'double',
4539-
'float _Complex', 'double _Complex']:
4539+
'_cffi_float_complex_t', '_cffi_double_complex_t']:
45404540
p = new_primitive_type(name)
4541-
if name.endswith(' _Complex'):
4541+
if name.endswith('_complex_t'):
45424542
num = cast(p, 1.23 - 4.56j)
45434543
else:
45444544
num = cast(p, 0x0123456789abcdef)

testing/cffi1/test_parse_c_type.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ def test_simple():
167167
("long double", lib._CFFI_PRIM_LONGDOUBLE),
168168
(" float _Complex", lib._CFFI_PRIM_FLOATCOMPLEX),
169169
("double _Complex ", lib._CFFI_PRIM_DOUBLECOMPLEX),
170+
("_cffi_float_complex_t", lib._CFFI_PRIM_FLOATCOMPLEX),
171+
(" _cffi_double_complex_t", lib._CFFI_PRIM_DOUBLECOMPLEX),
170172
]:
171173
assert parse(simple_type) == ['->', Prim(expected)]
172174

testing/cffi1/test_realize_c_type.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ def test_funcptr_rewrite_args():
4545
check("int(*)(long[5])", "int(*)(long *)")
4646

4747
def test_all_primitives():
48-
mapping = {"_cffi_float_complex_t": "float _Complex",
49-
"_cffi_double_complex_t": "double _Complex"}
5048
for name in cffi_opcode.PRIMITIVE_TO_INDEX:
51-
check(name, mapping.get(name, name))
49+
check(name, name)
5250

5351
def check_func(input, expected_output=None):
5452
import _cffi_backend

0 commit comments

Comments
 (0)