Skip to content

Commit 62f260d

Browse files
committed
Update C complex support
1 parent 86e49ef commit 62f260d

File tree

5 files changed

+12
-39
lines changed

5 files changed

+12
-39
lines changed

Examples/test-suite/complextest_c.i

Lines changed: 0 additions & 28 deletions
This file was deleted.

Examples/test-suite/fortran/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ C_TEST_CASES = \
3636
fortran_bindc_c \
3737
fortran_callback_c \
3838
fortran_global_const \
39-
complextest_c \
39+
ccomplextest \
4040

4141
FAILING_CPP_TESTS += \
4242
contract \

Examples/test-suite/fortran/complextest_c_runme.F90 renamed to Examples/test-suite/fortran/ccomplextest_runme.F90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
! File : complextest_c_runme.F90
1+
! File : ccomplextest_runme.F90
22

33
#include "fassert.h"
44

5-
program complextest_c_runme
6-
use complextest_c
5+
program ccomplextest_runme
6+
use ccomplextest
77
use ISO_C_BINDING
88
implicit none
99
complex(C_FLOAT_COMPLEX) :: cflt

Lib/fortran/ccomplex.i

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@
88
#define SWIG_ccomplex_construct(REAL, IMAG) ((REAL) + I * (IMAG))
99
%}
1010

11-
/* TODO: SWIG's parser defines "complex" but does *not* define _Complex;
12-
* this is the reverse of the standard. */
13-
#define _Complex complex
11+
// Avoid substituting the fortran type 'complex' until we've set up the typemaps
12+
#undef complex
1413

1514
%define %fortran_typemap_ccomplex(CTYPE, FKIND)
16-
%fortran_typemap_complex(complex CTYPE, SWIG_ccomplex_construct, CTYPE, FKIND)
15+
%fortran_typemap_complex(CTYPE _Complex, SWIG_ccomplex_construct, CTYPE, FKIND)
1716
%enddef
1817

1918
%fortran_typemap_ccomplex(float, C_FLOAT_COMPLEX)
2019
%fortran_typemap_ccomplex(double, C_DOUBLE_COMPLEX)
2120

22-
%typemap(out, fragment="SWIG_complex_float", noblock=1) complex float
21+
%typemap(out, fragment="SWIG_complex_float", noblock=1) _Complex float
2322
{$result = SWIG_create_complex_float(crealf($1), cimagf($1));}
24-
%typemap(out, fragment="SWIG_complex_double", noblock=1) complex double
23+
%typemap(out, fragment="SWIG_complex_double", noblock=1) _Complex double
2524
{$result = SWIG_create_complex_double(creal($1), cimag($1));}
2625

26+
/* Including <complex.h> defines 'complex' as _Complex */
27+
#define complex _Complex
2728

Lib/fortran/complex.i

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct SwigComplex_ ## CTYPE;
3232
%apply SwigComplex_ ## CTYPE ARRAY[] { CPPTYPE ARRAY[] };
3333
%apply SwigComplex_ ## CTYPE[ANY] { CPPTYPE[ANY] };
3434

35-
%typemap(ctype, in={SwigComplex_ ## CTYPE*}, null={SWIG_create_complex_ ## CTYPE(0, 0)}, fragment="SWIG_complex_"{CTYPE}, noblock=1) CPPTYPE {
35+
%typemap(ctype, in="SwigComplex_" #CTYPE "*", null="SWIG_create_complex_" # CTYPE "(0, 0)", fragment="SWIG_complex_"{CTYPE}, noblock=1) CPPTYPE {
3636
SwigComplex_ ## CTYPE
3737
}
3838
%typemap(in, noblock=1) CPPTYPE {

0 commit comments

Comments
 (0)