aboutsummaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorGareth Francis <gfrancis.dev@gmail.com>2019-06-21 16:55:30 +0100
committerGareth Francis <gfrancis.dev@gmail.com>2019-07-06 12:56:27 +0100
commit58863bba59b8314bf5f4a669c4133ac2135a2b2e (patch)
tree70e64202153dfca9b5a75596af6ff5c887d281b5 /Lib
parentd9cac176f6a03b9a57527ef5c1b5659b8857242a (diff)
downloadswig-58863bba59b8314bf5f4a669c4133ac2135a2b2e.tar.gz
Change C# bool[] typemaps to marshall as 1-byte
Default marshalling for bool[] now uses 1-byte entries in the array, to ensure array contents is as expected in C++. When running under mono csharp_lib_arrays_bool testcase will fail due to an apparent bug in mono. Works correctly under Microsoft's runtime. See https://github.com/mono/mono/issues/15592
Diffstat (limited to 'Lib')
-rw-r--r--Lib/csharp/arrays_csharp.i42
1 files changed, 41 insertions, 1 deletions
diff --git a/Lib/csharp/arrays_csharp.i b/Lib/csharp/arrays_csharp.i
index 237067a88..861da8386 100644
--- a/Lib/csharp/arrays_csharp.i
+++ b/Lib/csharp/arrays_csharp.i
@@ -103,7 +103,47 @@ CSHARP_ARRAYS(long long, long)
CSHARP_ARRAYS(unsigned long long, ulong)
CSHARP_ARRAYS(float, float)
CSHARP_ARRAYS(double, double)
-CSHARP_ARRAYS(bool, bool)
+
+// By default C# will marshal bools as 4 bytes
+// UnmanagedType.I1 will change this to 1 byte
+// FIXME - When running on mono ArraySubType appears to be ignored and bools will be marshalled as 4-byte
+// https://github.com/mono/mono/issues/15592
+
+// input only arrays
+%typemap(ctype) bool INPUT[] "bool*"
+%typemap(cstype) bool INPUT[] "bool[]"
+%typemap(imtype, inattributes="[global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray,ArraySubType=System.Runtime.InteropServices.UnmanagedType.I1)]") bool INPUT[] "bool[]"
+%typemap(csin) bool INPUT[] "$csinput"
+
+%typemap(in) bool INPUT[] %{
+$1 = $input;
+%}
+%typemap(freearg) bool INPUT[] ""
+%typemap(argout) bool INPUT[] ""
+
+// output only arrays
+%typemap(ctype) bool OUTPUT[] "bool*"
+%typemap(cstype) bool OUTPUT[] "bool[]"
+%typemap(imtype, inattributes="[global::System.Runtime.InteropServices.Out, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray,ArraySubType=System.Runtime.InteropServices.UnmanagedType.I1)]") bool OUTPUT[] "bool[]"
+%typemap(csin) bool OUTPUT[] "$csinput"
+
+%typemap(in) bool OUTPUT[] %{
+$1 = $input;
+%}
+%typemap(freearg) bool OUTPUT[] ""
+%typemap(argout) bool OUTPUT[] ""
+
+// inout arrays
+%typemap(ctype) bool INOUT[] "bool*"
+%typemap(cstype) bool INOUT[] "bool[]"
+%typemap(imtype, inattributes="[global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.Out, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray,ArraySubType=System.Runtime.InteropServices.UnmanagedType.I1)]") bool INOUT[] "bool[]"
+%typemap(csin) bool INOUT[] "$csinput"
+
+%typemap(in) bool INOUT[] %{
+$1 = $input;
+%}
+%typemap(freearg) bool INOUT[] ""
+%typemap(argout) bool INOUT[] ""
%define CSHARP_ARRAYS_FIXED( CTYPE, CSTYPE )