Fix linkage problems in C# std::complex wrappers

Fix warnings and subsequent exception trying to use wrappers:
Warning C4190: 'CSharp_complextestNamespace_VectorStdCplx_getitemcopy'
has C-linkage specified, but returns UDT 'SwigSystemNumericsComplex'
which is incompatible with C

Rename swig_complex_typemaps macro to SWIG_COMPLEX_TYPEMAPS
This commit is contained in:
William S Fulton 2017-05-19 19:52:39 +01:00
commit 57ec5ec056

View file

@ -3,15 +3,23 @@
%} %}
%fragment("SwigSystemNumericsComplex", "header") { %fragment("SwigSystemNumericsComplex", "header") {
extern "C" {
// Identical to the layout of System.Numerics.Complex, but does assume that it is // Identical to the layout of System.Numerics.Complex, but does assume that it is
// LayoutKind.Sequential on the managed side // LayoutKind.Sequential on the managed side
struct SwigSystemNumericsComplex { struct SwigSystemNumericsComplex {
double real; double real;
double imag; double imag;
SwigSystemNumericsComplex(double r = 0.0, double i = 0.0) : real(r), imag(i) {}
}; };
} }
SWIGINTERN SwigSystemNumericsComplex SwigCreateSystemNumericsComplex(double real, double imag) {
SwigSystemNumericsComplex cpx;
cpx.real = real;
cpx.imag = imag;
return cpx;
}
}
namespace std { namespace std {
%naturalvar complex; %naturalvar complex;
@ -25,7 +33,7 @@ public:
} }
%define swig_complex_typemaps(T) %define SWIG_COMPLEX_TYPEMAPS(T)
%typemap(ctype, fragment="SwigSystemNumericsComplex") std::complex<T>, const std::complex<T> & "SwigSystemNumericsComplex" %typemap(ctype, fragment="SwigSystemNumericsComplex") std::complex<T>, const std::complex<T> & "SwigSystemNumericsComplex"
%typemap(imtype) std::complex<T>, const std::complex<T> & "System.Numerics.Complex" %typemap(imtype) std::complex<T>, const std::complex<T> & "System.Numerics.Complex"
%typemap(cstype) std::complex<T>, const std::complex<T> & "System.Numerics.Complex" %typemap(cstype) std::complex<T>, const std::complex<T> & "System.Numerics.Complex"
@ -34,11 +42,11 @@ public:
%{temp = std::complex< double >($input.real, $input.imag); %{temp = std::complex< double >($input.real, $input.imag);
$1 = &temp;%} $1 = &temp;%}
%typemap(out) std::complex<T> %typemap(out, null="SwigCreateSystemNumericsComplex(0.0, 0.0)") std::complex<T>
%{$result = SwigSystemNumericsComplex($1.real(), $1.imag());%} %{$result = SwigCreateSystemNumericsComplex($1.real(), $1.imag());%}
%typemap(out) const std::complex<T> & %typemap(out, null="SwigCreateSystemNumericsComplex(0.0, 0.0)") const std::complex<T> &
%{$result = SwigSystemNumericsComplex($1->real(), $1->imag());%} %{$result = SwigCreateSystemNumericsComplex($1->real(), $1->imag());%}
%typemap(cstype) std::complex<T>, const std::complex<T> & "System.Numerics.Complex" %typemap(cstype) std::complex<T>, const std::complex<T> & "System.Numerics.Complex"
@ -69,9 +77,9 @@ public:
// are defined, but one of them can be disabled by predefining the // are defined, but one of them can be disabled by predefining the
// corresponding symbol before including this file. // corresponding symbol before including this file.
#ifndef SWIG_NO_STD_COMPLEX_DOUBLE #ifndef SWIG_NO_STD_COMPLEX_DOUBLE
swig_complex_typemaps(double) SWIG_COMPLEX_TYPEMAPS(double)
#endif #endif
#ifndef SWIG_NO_STD_COMPLEX_FLOAT #ifndef SWIG_NO_STD_COMPLEX_FLOAT
swig_complex_typemaps(float) SWIG_COMPLEX_TYPEMAPS(float)
#endif #endif