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
This commit is contained in:
Gareth Francis 2019-06-21 16:55:30 +01:00
commit 58863bba59
4 changed files with 202 additions and 1 deletions

View file

@ -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 )