Merge commit '8245277ad3acd9308ce28c40508b999e9496b27e' into c99-complex
* commit '8245277ad3acd9308ce28c40508b999e9496b27e':
Remove test for unsupported complex or _Complex by itself
More C99 complex fixes, plus Python tests
Restore _Complex as standalone type
Small corrections for handling C99 _Complex
Properly handle C99 complex types even in C++ mode
Conflicts:
Examples/test-suite/python/complextest_runme.py
diff --git a/Examples/test-suite/complextest.i b/Examples/test-suite/complextest.i
index 592512b..622b380 100644
--- a/Examples/test-suite/complextest.i
+++ b/Examples/test-suite/complextest.i
@@ -68,20 +68,57 @@
%{
+#include <complex.h>
%}
%inline
{
- complex Conj(complex a)
+ complex double Conj(complex double a)
{
return conj(a);
}
- complex float 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);
+ }
}
diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in
index 0570954..7ca98b3 100644
--- a/Examples/test-suite/python/Makefile.in
+++ b/Examples/test-suite/python/Makefile.in
@@ -83,6 +83,7 @@
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 4257cb3..4e7d08f 100644
--- a/Examples/test-suite/python/complextest_runme.py
+++ b/Examples/test-suite/python/complextest_runme.py
@@ -14,17 +14,34 @@
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 50f0f95..e58dbf7 100644
--- a/Lib/javascript/jsc/ccomplex.i
+++ b/Lib/javascript/jsc/ccomplex.i
@@ -12,15 +12,16 @@
#include <complex.h>
%}
+#define complex _Complex
/* C complex constructor */
#define CCplxConst(r, i) ((r) + I*(i))
-%swig_cplxflt_convn(float complex, CCplxConst, creal, cimag);
-%swig_cplxdbl_convn(double complex, CCplxConst, creal, cimag);
-%swig_cplxdbl_convn(complex, CCplxConst, creal, cimag);
+%swig_cplxflt_convn(float _Complex, CCplxConst, creal, cimag);
+%swig_cplxdbl_convn(double _Complex, CCplxConst, creal, cimag);
+%swig_cplxdbl_convn(_Complex, CCplxConst, creal, cimag);
/* declaring the typemaps */
-%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float complex);
-%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double complex);
-%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, complex);
+%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float _Complex);
+%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double _Complex);
+%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, _Complex);
diff --git a/Lib/javascript/v8/ccomplex.i b/Lib/javascript/v8/ccomplex.i
index 8eda920..b4b925d 100644
--- a/Lib/javascript/v8/ccomplex.i
+++ b/Lib/javascript/v8/ccomplex.i
@@ -12,15 +12,16 @@
#include <complex.h>
%}
+#define complex _Complex
/* C complex constructor */
#define CCplxConst(r, i) ((r) + I*(i))
-%swig_cplxflt_convn(float complex, CCplxConst, creal, cimag);
-%swig_cplxdbl_convn(double complex, CCplxConst, creal, cimag);
-%swig_cplxdbl_convn(complex, CCplxConst, creal, cimag);
+%swig_cplxflt_convn(float _Complex, CCplxConst, creal, cimag);
+%swig_cplxdbl_convn(double _Complex, CCplxConst, creal, cimag);
+%swig_cplxdbl_convn(_Complex, CCplxConst, creal, cimag);
/* declaring the typemaps */
-%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float complex);
-%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double complex);
-%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, complex);
+%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float _Complex);
+%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double _Complex);
+%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, _Complex);
diff --git a/Lib/python/ccomplex.i b/Lib/python/ccomplex.i
index 28872b9..b99f96a 100644
--- a/Lib/python/ccomplex.i
+++ b/Lib/python/ccomplex.i
@@ -12,15 +12,16 @@
#include <complex.h>
%}
+#define complex _Complex
/* C complex constructor */
#define CCplxConst(r, i) ((r) + I*(i))
-%swig_cplxflt_convn(float complex, CCplxConst, creal, cimag);
-%swig_cplxdbl_convn(double complex, CCplxConst, creal, cimag);
-%swig_cplxdbl_convn(complex, CCplxConst, creal, cimag);
+%swig_cplxflt_convn(float _Complex, CCplxConst, creal, cimag);
+%swig_cplxdbl_convn(double _Complex, CCplxConst, creal, cimag);
+%swig_cplxdbl_convn(_Complex, CCplxConst, creal, cimag);
/* declaring the typemaps */
-%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float complex);
-%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double complex);
-%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, complex);
+%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float _Complex);
+%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double _Complex);
+%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, _Complex);
diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c
index 19a0138..a370270 100644
--- a/Source/CParse/cscanner.c
+++ b/Source/CParse/cscanner.c
@@ -908,7 +908,7 @@
if (strcmp(yytext, "class") == 0) {
Swig_warning(WARN_PARSE_CLASS_KEYWORD, cparse_file, cparse_line, "class keyword used, but not in C++ mode.\n");
}
- if (strcmp(yytext, "complex") == 0) {
+ if (strcmp(yytext, "_Complex") == 0) {
yylval.type = NewSwigType(T_COMPLEX);
return (TYPE_COMPLEX);
}
diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y
index 8029dee..c48d3a6 100644
--- a/Source/CParse/parser.y
+++ b/Source/CParse/parser.y
@@ -6232,19 +6232,19 @@
} else if (Cmp($1.type,"double") == 0) {
if (Cmp($2.type,"long") == 0) {
$$.type = NewString("long double");
- } else if (Cmp($2.type,"complex") == 0) {
- $$.type = NewString("double complex");
+ } else if (Cmp($2.type,"_Complex") == 0) {
+ $$.type = NewString("double _Complex");
} else {
err = 1;
}
} else if (Cmp($1.type,"float") == 0) {
- if (Cmp($2.type,"complex") == 0) {
- $$.type = NewString("float complex");
+ if (Cmp($2.type,"_Complex") == 0) {
+ $$.type = NewString("float _Complex");
} else {
err = 1;
}
- } else if (Cmp($1.type,"complex") == 0) {
- $$.type = NewStringf("%s complex", $2.type);
+ } else if (Cmp($1.type,"_Complex") == 0) {
+ $$.type = NewStringf("%s _Complex", $2.type);
} else {
err = 1;
}
@@ -6294,7 +6294,7 @@
$$.type = 0;
}
| TYPE_COMPLEX {
- $$.type = NewString("complex");
+ $$.type = NewString("_Complex");
$$.us = 0;
}
| TYPE_NON_ISO_INT8 {
diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c
index 7564db1..d6d6bcc 100644
--- a/Source/Swig/typesys.c
+++ b/Source/Swig/typesys.c
@@ -1453,11 +1453,11 @@
return T_DOUBLE;
if (strcmp(c, "long double") == 0)
return T_LONGDOUBLE;
- if (!cparse_cplusplus && (strcmp(c, "float complex") == 0))
+ if (!cparse_cplusplus && (strcmp(c, "float _Complex") == 0))
return T_FLTCPLX;
- if (!cparse_cplusplus && (strcmp(c, "double complex") == 0))
+ if (!cparse_cplusplus && (strcmp(c, "double _Complex") == 0))
return T_DBLCPLX;
- if (!cparse_cplusplus && (strcmp(c, "complex") == 0))
+ if (!cparse_cplusplus && (strcmp(c, "_Complex") == 0))
return T_COMPLEX;
if (strcmp(c, "void") == 0)
return T_VOID;