Skip to content

Commit e9b5af3

Browse files
committed
Test JI 1296.
1 parent f3ebc6f commit e9b5af3

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// There are built-in delegates for these, but we no longer generate them in Mono.Android.dll
2+
// because bool is not a blittable type. But we still need them for pre-existing bindings.
3+
using System;
4+
5+
[global::System.Runtime.InteropServices.UnmanagedFunctionPointer (global::System.Runtime.InteropServices.CallingConvention.Winapi)]
6+
delegate bool _JniMarshal_PP_Z (IntPtr jnienv, IntPtr klass);
7+
[global::System.Runtime.InteropServices.UnmanagedFunctionPointer (global::System.Runtime.InteropServices.CallingConvention.Winapi)]
8+
delegate bool _JniMarshal_PPL_Z (IntPtr jnienv, IntPtr klass, IntPtr p0);
9+
[global::System.Runtime.InteropServices.UnmanagedFunctionPointer (global::System.Runtime.InteropServices.CallingConvention.Winapi)]
10+
delegate bool _JniMarshal_PPJ_Z (IntPtr jnienv, IntPtr klass, long p0);
11+
[global::System.Runtime.InteropServices.UnmanagedFunctionPointer (global::System.Runtime.InteropServices.CallingConvention.Winapi)]
12+
delegate void _JniMarshal_PPLZ_V (IntPtr jnienv, IntPtr klass, IntPtr p0, bool p1);
13+
[global::System.Runtime.InteropServices.UnmanagedFunctionPointer (global::System.Runtime.InteropServices.CallingConvention.Winapi)]
14+
delegate bool _JniMarshal_PPLL_Z (IntPtr jnienv, IntPtr klass, IntPtr p0, IntPtr p1);
15+
[global::System.Runtime.InteropServices.UnmanagedFunctionPointer (global::System.Runtime.InteropServices.CallingConvention.Winapi)]
16+
delegate bool _JniMarshal_PPIL_Z (IntPtr jnienv, IntPtr klass, int p0, IntPtr p1);
17+
[global::System.Runtime.InteropServices.UnmanagedFunctionPointer (global::System.Runtime.InteropServices.CallingConvention.Winapi)]
18+
delegate bool _JniMarshal_PPLII_Z (IntPtr jnienv, IntPtr klass, IntPtr p0, int p1, int p2);
19+
[global::System.Runtime.InteropServices.UnmanagedFunctionPointer (global::System.Runtime.InteropServices.CallingConvention.Winapi)]
20+
delegate bool _JniMarshal_PPLLJ_Z (IntPtr jnienv, IntPtr klass, IntPtr p0, IntPtr p1, long p2);
21+
[global::System.Runtime.InteropServices.UnmanagedFunctionPointer (global::System.Runtime.InteropServices.CallingConvention.Winapi)]
22+
delegate bool _JniMarshal_PPLIL_Z (IntPtr jnienv, IntPtr klass, IntPtr p0, int p1, IntPtr p2);
23+
[global::System.Runtime.InteropServices.UnmanagedFunctionPointer (global::System.Runtime.InteropServices.CallingConvention.Winapi)]
24+
delegate bool _JniMarshal_PPLLL_Z (IntPtr jnienv, IntPtr klass, IntPtr p0, IntPtr p1, IntPtr p2);
25+
[global::System.Runtime.InteropServices.UnmanagedFunctionPointer (global::System.Runtime.InteropServices.CallingConvention.Winapi)]
26+
delegate IntPtr _JniMarshal_PPIZI_L (IntPtr jnienv, IntPtr klass, int p0, bool p1, int p2);
27+
[global::System.Runtime.InteropServices.UnmanagedFunctionPointer (global::System.Runtime.InteropServices.CallingConvention.Winapi)]
28+
delegate bool _JniMarshal_PPLZZL_Z (IntPtr jnienv, IntPtr klass, IntPtr p0, bool p1, bool p2, IntPtr p3);
29+
[global::System.Runtime.InteropServices.UnmanagedFunctionPointer (global::System.Runtime.InteropServices.CallingConvention.Winapi)]
30+
delegate void _JniMarshal_PPZIIII_V (IntPtr jnienv, IntPtr klass, bool p0, int p1, int p2, int p3, int p4);

src/Mono.Android/Mono.Android.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
<Compile Include="Android.Icu\DateIntervalFormat.cs" />
9797
<Compile Include="Android.Net.Wifi.P2p\WifiP2pManager.cs" />
9898
<Compile Include="Android.Runtime\DynamicMethodNameCounter.cs" />
99+
<Compile Include="Android.Runtime\ExtraDelegates.cs" />
99100
<Compile Include="Android.Runtime\IJavaObjectValueMarshaler.cs" />
100101
<Compile Include="Android.Telecom\InCallService.cs" />
101102
<Compile Include="Android.Telephony.Mbms\StreamingService.cs" />

src/Xamarin.Android.Build.Tasks/Utilities/MarshalMethodsClassifier.cs

+14-2
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public bool Matches (MethodDefinition method)
208208
return false;
209209
}
210210

211-
if (String.Compare (returnType, method.ReturnType.FullName, StringComparison.Ordinal) != 0) {
211+
if (!TypeMatches (returnType, method.ReturnType.FullName)) {
212212
log.LogWarning ($"Method '{method.FullName}' doesn't match native callback signature (invalid return type: expected '{returnType}', found '{method.ReturnType.FullName}')");
213213
return false;
214214
}
@@ -223,14 +223,26 @@ public bool Matches (MethodDefinition method)
223223
parameterTypeName = pd.ParameterType.FullName;
224224
}
225225

226-
if (String.Compare (parameterTypeName, paramTypes[i], StringComparison.Ordinal) != 0) {
226+
if (!TypeMatches (parameterTypeName, paramTypes[i])) {
227227
log.LogWarning ($"Method '{method.FullName}' doesn't match native callback signature, expected parameter type '{paramTypes[i]}' at position {i}, found '{parameterTypeName}'");
228228
return false;
229229
}
230230
}
231231

232232
return true;
233233
}
234+
235+
static bool TypeMatches (string type, string methodType)
236+
{
237+
if (String.Compare (type, methodType, StringComparison.Ordinal) == 0)
238+
return true;
239+
240+
// We marshal boolean as sbyte to be blittable, so we need to accept this mismatch
241+
if (type == "System.Boolean" && methodType == "System.SByte")
242+
return true;
243+
244+
return false;
245+
}
234246
}
235247

236248
TypeDefinitionCache tdCache;

0 commit comments

Comments
 (0)