From 511df0e6428ae86696ac44e381ba0c736a3742fc Mon Sep 17 00:00:00 2001 From: Leo Singer Date: Wed, 17 Jun 2020 13:03:17 -0400 Subject: [PATCH] More C99 complex fixes, plus Python tests --- Examples/test-suite/complextest.i | 53 ++++++++++++++++++- Examples/test-suite/python/Makefile.in | 1 + .../test-suite/python/complextest_runme.py | 37 +++++++++---- Lib/javascript/jsc/ccomplex.i | 1 + Lib/javascript/v8/ccomplex.i | 1 + Lib/python/ccomplex.i | 1 + Source/CParse/parser.y | 2 +- 7 files changed, 83 insertions(+), 13 deletions(-) diff --git a/Examples/test-suite/complextest.i b/Examples/test-suite/complextest.i index 57d00a946..4d40bc524 100644 --- a/Examples/test-suite/complextest.i +++ b/Examples/test-suite/complextest.i @@ -68,20 +68,69 @@ %{ +#include %} %inline { - double complex Conj(complex a) + complex double Conj(complex double a) { return conj(a); } - float complex Conjf(float complex a) + complex float Conjf(complex float a) { return conjf(a); } + + + double complex Conj1(double complex a) + { + return conj(a); + } + + + float complex Conjf1(float complex a) + { + return conjf(a); + } + + + _Complex double Conj2(_Complex double a) + { + return conj(a); + } + + + _Complex float Conjf2(_Complex float a) + { + return conjf(a); + } + + + double _Complex Conj3(double _Complex a) + { + return conj(a); + } + + + float _Complex Conjf3(float _Complex a) + { + return conjf(a); + } + + + complex Conj4(complex a) + { + return conj(a); + } + + + _Complex Conj5(_Complex a) + { + return conj(a); + } } diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index 4c0507cbb..86d5e37f2 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -92,6 +92,7 @@ CPP11_TEST_CASES = \ cpp11_std_unordered_set \ C_TEST_CASES += \ + complextest \ file_test \ li_cstring \ li_cwstring \ diff --git a/Examples/test-suite/python/complextest_runme.py b/Examples/test-suite/python/complextest_runme.py index 5cfc7ccab..2b3d6fda9 100644 --- a/Examples/test-suite/python/complextest_runme.py +++ b/Examples/test-suite/python/complextest_runme.py @@ -14,17 +14,34 @@ if complextest.Conj2(a) != a.conjugate(): if complextest.Conjf2(a) != a.conjugate(): raise RuntimeError, "bad complex mapping" +if 'Conj3' in dir(complextest): + if complextest.Conj3(a) != a.conjugate(): + raise RuntimeError, "bad complex mapping" -v = (complex(1, 2), complex(2, 3), complex(4, 3), 1) +if 'Conjf3' in dir(complextest): + if complextest.Conjf3(a) != a.conjugate(): + raise RuntimeError, "bad complex mapping" -if len(complextest.CopyHalf(v)) != 2: - raise RuntimeError("CopyHalf failed") +if 'Conj4' in dir(complextest): + if complextest.Conj4(a) != a.conjugate(): + raise RuntimeError, "bad complex mapping" -if len(complextest.CopyHalfRef(v)) != 2: - raise RuntimeError("CopyHalfRef failed") +if 'Conj5' in dir(complextest): + if complextest.Conj5(a) != a.conjugate(): + raise RuntimeError, "bad complex mapping" -p = complextest.ComplexPair() -p.z1 = complex(0, 1) -p.z2 = complex(0, -1) -if complextest.Conj(p.z2) != p.z1: - raise RuntimeError, "bad complex mapping" +if 'CopyHalf' in dir(complextest): + + v = (complex(1, 2), complex(2, 3), complex(4, 3), 1) + + if len(complextest.CopyHalf(v)) != 2: + raise RuntimeError("CopyHalf failed") + + if len(complextest.CopyHalfRef(v)) != 2: + raise RuntimeError("CopyHalfRef failed") + + p = complextest.ComplexPair() + p.z1 = complex(0, 1) + p.z2 = complex(0, -1) + if complextest.Conj(p.z2) != p.z1: + raise RuntimeError, "bad complex mapping" diff --git a/Lib/javascript/jsc/ccomplex.i b/Lib/javascript/jsc/ccomplex.i index 00680d3b4..e58dbf719 100644 --- a/Lib/javascript/jsc/ccomplex.i +++ b/Lib/javascript/jsc/ccomplex.i @@ -12,6 +12,7 @@ #include %} +#define complex _Complex /* C complex constructor */ #define CCplxConst(r, i) ((r) + I*(i)) diff --git a/Lib/javascript/v8/ccomplex.i b/Lib/javascript/v8/ccomplex.i index a753ae180..b4b925da7 100644 --- a/Lib/javascript/v8/ccomplex.i +++ b/Lib/javascript/v8/ccomplex.i @@ -12,6 +12,7 @@ #include %} +#define complex _Complex /* C complex constructor */ #define CCplxConst(r, i) ((r) + I*(i)) diff --git a/Lib/python/ccomplex.i b/Lib/python/ccomplex.i index 1652816ca..b99f96a48 100644 --- a/Lib/python/ccomplex.i +++ b/Lib/python/ccomplex.i @@ -12,6 +12,7 @@ #include %} +#define complex _Complex /* C complex constructor */ #define CCplxConst(r, i) ((r) + I*(i)) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index cccd613fe..c48d3a6f2 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -6294,7 +6294,7 @@ type_specifier : TYPE_INT { $$.type = 0; } | TYPE_COMPLEX { - $$.type = NewString("complex"); + $$.type = NewString("_Complex"); $$.us = 0; } | TYPE_NON_ISO_INT8 {