Skip to content

Commit 56955d9

Browse files
authored
[generator] Use custom delegates instead of Func/Action. (#632)
Fixes: #631 Context: dotnet/runtime#32963 Context: https://github.com/dotnet/csharplang/blob/master/proposals/function-pointers.md *Of `Delegate`s and JNI Callbacks…* ~~ Background ~~ In order for Java code to invoke Managed Code such as C#, several things must happen: 1. There must be a Java class which declares `native` methods. 2. The Java class' `native` methods must be [*resolvable*][0] Java `native` method resolution can be done by [C function name][1] *or* by using [`JNIEnv::RegisterNatives()`][2]: // C++ struct JNINativeMethod { const char *name; const char *signature; const void *fnPtr; }; /* partial */ struct JNIEnv { jint RegisterNatives(jclass clazz, const JNINativeMethod *methods, jint nMethods); }; `JNINativeMethods::fnPtr` is a pointer to a *C callable function* that accepts [JNI Native Method Arguments][3]. Java.Interop doesn't currently support resolution via C function name, and instead binds the `JNINativeMethod` struct as `JniNativeMethodRegistration`, and `JNIEnv::RegisterNatives()` as `Java.Interop.JniEnvironment.Types.RegisterNatives()`: // C# public partial struct JniNativeMethodRegistration { public string Name; public string Signature; public Delegate Marshaler; } public partial class JniEnvironment { public partial class Types { public static void RegisterNatives (JniObjectReference type, JniNativeMethodRegistration [] methods); } } Through the glory that is [Platform Invoke Delegate Marshaling][4] and/or [`Marshal.GetFunctionPointerForDelegate()`][5], managed code can provide a `Delegate` instance in `JniNativeMethodRegistration.Marshaler` and have JNI invoke that delegate when the corresponding Java `native` method is invoked. `tools/generator` is responsible for emitting this glue code, e.g. in order to support registering overrides of [`java.lang.Object.equals()`][6]: // C# emitted by `tools/generator`: namespace Java.Lang { partial class Object { static Delegate cb_equals_Ljava_lang_Object_; static Delegate GetEquals_Ljava_lang_Object_Handler () { if (cb_equals_Ljava_lang_Object_ == null) cb_equals_Ljava_lang_Object_ = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, IntPtr, bool>) n_Equals_Ljava_lang_Object_); return cb_equals_Ljava_lang_Object_; } static bool n_Equals_Ljava_lang_Object_ (IntPtr jnienv, IntPtr native__this, IntPtr native_obj) { var __this = global::Java.Lang.Object.GetObject<Java.Lang.Object> (jnienv, native__this, JniHandleOwnership.DoNotTransfer); var obj = global::Java.Lang.Object.GetObject<Java.Lang.Object> (native_obj, JniHandleOwnership.DoNotTransfer); bool __ret = __this.Equals (obj); return __ret; } } } `Object.n_Equals_Ljava_lang_Object()` is stored in a `Func<IntPtr, IntPtr, IntPtr, bool>` -- which conforms to JNI Native Method Arguments -- and is then provided to [`JNINativeWrapper.CreateDelegate()`][7], which uses `System.Reflection.Emit` to "wrap" `n_Equals_Ljava_lang_Object()` for exception propagation purposes. Eventually and ultimately, when a C# class overrides `Java.Lang.Object.Equals()`, `Object.GetEquals_Ljava_lang_Object_Handler()` will be invoked at runtime, and `Object.cb_equals_Ljava_lang_Object` will be stored into `JniNativeMethodRegistration.Marshaler`. ~~ `Action<…>` and `Func<…>` ~~ There is one problem with the above approach: its use of the `System.Action<…>` and `System.Func<…>` types used at the core of registering native methods with JNI. There are two problems with using these sets of types: 1. These delegate types only permit up to 16 parameters. Given that *two* parameters are always "eaten" by the `JNIEnv*` pointer and a `jobject` to Java's `this` or a `jclass` to the declaring class, that means that we can only bind methods taking up to 14 methods. Java methods which take more than 14 methods are skipped. 2. .NET Framework and CoreCLR don't support using generic types with the Platform Invoke marshaler and [`Marshal.GetFunctionPointerForDelegate()`][8]. (1) has been a longstanding problem, which we've been ignoring. (2) isn't *yet* a problem, and is something @jonpryor has been keen to address for awhile. ~~ C# Function Pointers? ~~ There is a proposal to [add Function Pointers to the C# language][9]. This would permit reduced overheads and improved efficiencies in obtaining a function pointer to pass into Java code. Unfortunately: 1. The proposal is still ongoing, with no known release date. 2. .NET Framework 4.x won't support them. 3. They can't be used within the current Xamarin.Android architecture. There doesn't appear to be a way to obtain a `Delegate` from a `delegate*`, which means `JNINativeWrapper.CreateDelegate()` cannot be used with Function Pointers. In order to use Function Pointers, we would likely need to *require* use of `tools/jnimarshalmethod-gen.exe` (176240d) so that appropriate JNI Native Method Argument-conforming methods with the `NativeCallableAttribute` can be generated at app build time, *avoiding* the current Reflection-heavy registration path which involves e.g. `Object.GetEquals_Ljava_lang_Object_Handler()`. Unfortunately, `jnimarshalmethod-gen.exe` isn't "done": it doesn't work on Windows, and it's use of `AppDomain`s and `System.Reflection.Emit` look to complicate a future .NET 5 port. ~~ Solution: Generate Delegates ~~ If `Action<…>` and `Func<…>` are to be avoided, and Function Pointers are out, how do we support more than 14 parameters? By updating `generator` to emit the required delegate types. When `Action<…>` or `Func<…>` would previously have been generated, instead emit *and record the name of* a delegate which follows the pattern: * Type name prefix: `_JniMarshal_PP` * Parameter types, using JNI encoding, e.g. `Z` for boolean, `I` for int, etc. *Reference types*, normally encoded as `L…;` and Arrays, encoded as `[`, are each encoded as `L`. Kotlin unsigned types are encoded as *lower-case* forms of the corresponding JNI types, e.g. `i` is an unsigned `I`. * Another `_`. * The above type encoding for the return type. For example, `Object.n_Equals_Ljava_lang_Object()` used `Func<IntPtr, IntPtr, IntPtr, bool>`. This would become `_JniMarshal_PPL_Z`. After the initial binding stage is complete and all required delegate types are recorded, the `_JniMarshal*` types are emitted into `__NamespaceMapping__.cs`: internal delegate bool _JniMarshal_PPL_Z (IntPtr jnienv, IntPtr klass, IntPtr a); The cost to declaring all these types is that a binding assembly contains more types. `Mono.Android.dll`, for example, grows ~20KB in size from all the required delegate declarations, pre-linking. ~~ Other ~~ Remove `tools/generator/generator.sln` and replace it with a `tools/generator/generator.slnf` solution filter file which makes it easier to work with `generator` in Visual Studio by only loading needed projects from `Java.Interop.sln`. [0]: https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/design.html#compiling_loading_and_linking_native_methods [1]: https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/design.html#resolving_native_method_names [2]: https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#RegisterNatives [3]: https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/design.html#native_method_arguments [4]: https://docs.microsoft.com/en-us/dotnet/framework/interop/marshaling-a-delegate-as-a-callback-method [5]: https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.marshal.getfunctionpointerfordelegate?view=netcore-3.1 [6]: https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#equals%28java.lang.Object%29 [7]: https://github.com/xamarin/xamarin-android/blob/42822e0488185cdf4bca7c0bd05b21ad03dfbd7e/src/Mono.Android/Android.Runtime/JNINativeWrapper.cs#L34-L97 [8]: dotnet/runtime#32963 [9]: https://github.com/dotnet/csharplang/blob/master/proposals/function-pointers.md
1 parent 0a77166 commit 56955d9

File tree

195 files changed

+668
-464
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

195 files changed

+668
-464
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
using System;
2+
13
[assembly:global::Android.Runtime.NamespaceMapping (Java = "java.lang", Managed="Java.Lang")]
24
[assembly:global::Android.Runtime.NamespaceMapping (Java = "xamarin.test.invalidnames", Managed="Xamarin.Test.Invalidnames")]
5+

tests/generator-Tests/Tests-Core/expected.ji/Android.Text.ISpannable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public ISpannableInvoker (IntPtr handle, JniHandleOwnership transfer) : base (Va
6767
static Delegate GetGetSpanFlags_Ljava_lang_Object_Handler ()
6868
{
6969
if (cb_getSpanFlags_Ljava_lang_Object_ == null)
70-
cb_getSpanFlags_Ljava_lang_Object_ = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, IntPtr, int>) n_GetSpanFlags_Ljava_lang_Object_);
70+
cb_getSpanFlags_Ljava_lang_Object_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_I) n_GetSpanFlags_Ljava_lang_Object_);
7171
return cb_getSpanFlags_Ljava_lang_Object_;
7272
}
7373

tests/generator-Tests/Tests-Core/expected.ji/Android.Text.ISpanned.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public ISpannedInvoker (IntPtr handle, JniHandleOwnership transfer) : base (Vali
7272
static Delegate GetGetSpanFlags_Ljava_lang_Object_Handler ()
7373
{
7474
if (cb_getSpanFlags_Ljava_lang_Object_ == null)
75-
cb_getSpanFlags_Ljava_lang_Object_ = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, IntPtr, int>) n_GetSpanFlags_Ljava_lang_Object_);
75+
cb_getSpanFlags_Ljava_lang_Object_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_I) n_GetSpanFlags_Ljava_lang_Object_);
7676
return cb_getSpanFlags_Ljava_lang_Object_;
7777
}
7878

tests/generator-Tests/Tests-Core/expected.ji/Android.Text.SpannableString.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public unsafe SpannableString (string source)
7878
static Delegate GetGetSpanFlags_Ljava_lang_Object_Handler ()
7979
{
8080
if (cb_getSpanFlags_Ljava_lang_Object_ == null)
81-
cb_getSpanFlags_Ljava_lang_Object_ = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, IntPtr, int>) n_GetSpanFlags_Ljava_lang_Object_);
81+
cb_getSpanFlags_Ljava_lang_Object_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_I) n_GetSpanFlags_Ljava_lang_Object_);
8282
return cb_getSpanFlags_Ljava_lang_Object_;
8383
}
8484

tests/generator-Tests/Tests-Core/expected.ji/Android.Text.SpannableStringInternal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected SpannableStringInternal (IntPtr javaReference, JniHandleOwnership tran
3535
static Delegate GetGetSpanFlags_Ljava_lang_Object_Handler ()
3636
{
3737
if (cb_getSpanFlags_Ljava_lang_Object_ == null)
38-
cb_getSpanFlags_Ljava_lang_Object_ = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, IntPtr, int>) n_GetSpanFlags_Ljava_lang_Object_);
38+
cb_getSpanFlags_Ljava_lang_Object_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_I) n_GetSpanFlags_Ljava_lang_Object_);
3939
return cb_getSpanFlags_Ljava_lang_Object_;
4040
}
4141

tests/generator-Tests/Tests-Core/expected.ji/Android.Views.View.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public IOnClickListenerInvoker (IntPtr handle, JniHandleOwnership transfer) : ba
7575
static Delegate GetOnClick_Landroid_view_View_Handler ()
7676
{
7777
if (cb_onClick_Landroid_view_View_ == null)
78-
cb_onClick_Landroid_view_View_ = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, IntPtr>) n_OnClick_Landroid_view_View_);
78+
cb_onClick_Landroid_view_View_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_V) n_OnClick_Landroid_view_View_);
7979
return cb_onClick_Landroid_view_View_;
8080
}
8181

@@ -154,7 +154,7 @@ protected View (IntPtr javaReference, JniHandleOwnership transfer) : base (javaR
154154
static Delegate GetSetOnClickListener_Landroid_view_View_OnClickListener_Handler ()
155155
{
156156
if (cb_setOnClickListener_Landroid_view_View_OnClickListener_ == null)
157-
cb_setOnClickListener_Landroid_view_View_OnClickListener_ = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, IntPtr>) n_SetOnClickListener_Landroid_view_View_OnClickListener_);
157+
cb_setOnClickListener_Landroid_view_View_OnClickListener_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_V) n_SetOnClickListener_Landroid_view_View_OnClickListener_);
158158
return cb_setOnClickListener_Landroid_view_View_OnClickListener_;
159159
}
160160

@@ -184,7 +184,7 @@ public virtual unsafe void SetOnClickListener (Android.Views.View.IOnClickListen
184184
static Delegate GetSetOn123Listener_Landroid_view_View_OnClickListener_Handler ()
185185
{
186186
if (cb_setOn123Listener_Landroid_view_View_OnClickListener_ == null)
187-
cb_setOn123Listener_Landroid_view_View_OnClickListener_ = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, IntPtr>) n_SetOn123Listener_Landroid_view_View_OnClickListener_);
187+
cb_setOn123Listener_Landroid_view_View_OnClickListener_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_V) n_SetOn123Listener_Landroid_view_View_OnClickListener_);
188188
return cb_setOn123Listener_Landroid_view_View_OnClickListener_;
189189
}
190190

@@ -214,7 +214,7 @@ public virtual unsafe void SetOn123Listener (Android.Views.View.IOnClickListener
214214
static Delegate GetAddTouchables_Ljava_util_ArrayList_Handler ()
215215
{
216216
if (cb_addTouchables_Ljava_util_ArrayList_ == null)
217-
cb_addTouchables_Ljava_util_ArrayList_ = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, IntPtr>) n_AddTouchables_Ljava_util_ArrayList_);
217+
cb_addTouchables_Ljava_util_ArrayList_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_V) n_AddTouchables_Ljava_util_ArrayList_);
218218
return cb_addTouchables_Ljava_util_ArrayList_;
219219
}
220220

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
using System;
2+
13
[assembly:global::Android.Runtime.NamespaceMapping (Java = "android.view", Managed="Android.Views")]
24
[assembly:global::Android.Runtime.NamespaceMapping (Java = "android.text", Managed="Android.Text")]
35
[assembly:global::Android.Runtime.NamespaceMapping (Java = "java.lang", Managed="Java.Lang")]
6+
7+
delegate int _JniMarshal_PPL_I (IntPtr jnienv, IntPtr klass, IntPtr p0);
8+
delegate void _JniMarshal_PPL_V (IntPtr jnienv, IntPtr klass, IntPtr p0);

tests/generator-Tests/Tests-Core/expected/Android.Text.ISpannable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public ISpannableInvoker (IntPtr handle, JniHandleOwnership transfer) : base (Va
5858
static Delegate GetGetSpanFlags_Ljava_lang_Object_Handler ()
5959
{
6060
if (cb_getSpanFlags_Ljava_lang_Object_ == null)
61-
cb_getSpanFlags_Ljava_lang_Object_ = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, IntPtr, int>) n_GetSpanFlags_Ljava_lang_Object_);
61+
cb_getSpanFlags_Ljava_lang_Object_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_I) n_GetSpanFlags_Ljava_lang_Object_);
6262
return cb_getSpanFlags_Ljava_lang_Object_;
6363
}
6464

tests/generator-Tests/Tests-Core/expected/Android.Text.ISpanned.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public ISpannedInvoker (IntPtr handle, JniHandleOwnership transfer) : base (Vali
6363
static Delegate GetGetSpanFlags_Ljava_lang_Object_Handler ()
6464
{
6565
if (cb_getSpanFlags_Ljava_lang_Object_ == null)
66-
cb_getSpanFlags_Ljava_lang_Object_ = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, IntPtr, int>) n_GetSpanFlags_Ljava_lang_Object_);
66+
cb_getSpanFlags_Ljava_lang_Object_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_I) n_GetSpanFlags_Ljava_lang_Object_);
6767
return cb_getSpanFlags_Ljava_lang_Object_;
6868
}
6969

tests/generator-Tests/Tests-Core/expected/Android.Text.SpannableString.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public unsafe SpannableString (string source)
9292
static Delegate GetGetSpanFlags_Ljava_lang_Object_Handler ()
9393
{
9494
if (cb_getSpanFlags_Ljava_lang_Object_ == null)
95-
cb_getSpanFlags_Ljava_lang_Object_ = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, IntPtr, int>) n_GetSpanFlags_Ljava_lang_Object_);
95+
cb_getSpanFlags_Ljava_lang_Object_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_I) n_GetSpanFlags_Ljava_lang_Object_);
9696
return cb_getSpanFlags_Ljava_lang_Object_;
9797
}
9898

tests/generator-Tests/Tests-Core/expected/Android.Text.SpannableStringInternal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected SpannableStringInternal (IntPtr javaReference, JniHandleOwnership tran
3030
static Delegate GetGetSpanFlags_Ljava_lang_Object_Handler ()
3131
{
3232
if (cb_getSpanFlags_Ljava_lang_Object_ == null)
33-
cb_getSpanFlags_Ljava_lang_Object_ = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, IntPtr, int>) n_GetSpanFlags_Ljava_lang_Object_);
33+
cb_getSpanFlags_Ljava_lang_Object_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_I) n_GetSpanFlags_Ljava_lang_Object_);
3434
return cb_getSpanFlags_Ljava_lang_Object_;
3535
}
3636

tests/generator-Tests/Tests-Core/expected/Android.Views.View.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public IOnClickListenerInvoker (IntPtr handle, JniHandleOwnership transfer) : ba
6666
static Delegate GetOnClick_Landroid_view_View_Handler ()
6767
{
6868
if (cb_onClick_Landroid_view_View_ == null)
69-
cb_onClick_Landroid_view_View_ = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, IntPtr>) n_OnClick_Landroid_view_View_);
69+
cb_onClick_Landroid_view_View_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_V) n_OnClick_Landroid_view_View_);
7070
return cb_onClick_Landroid_view_View_;
7171
}
7272

@@ -141,7 +141,7 @@ protected View (IntPtr javaReference, JniHandleOwnership transfer) : base (javaR
141141
static Delegate GetSetOnClickListener_Landroid_view_View_OnClickListener_Handler ()
142142
{
143143
if (cb_setOnClickListener_Landroid_view_View_OnClickListener_ == null)
144-
cb_setOnClickListener_Landroid_view_View_OnClickListener_ = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, IntPtr>) n_SetOnClickListener_Landroid_view_View_OnClickListener_);
144+
cb_setOnClickListener_Landroid_view_View_OnClickListener_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_V) n_SetOnClickListener_Landroid_view_View_OnClickListener_);
145145
return cb_setOnClickListener_Landroid_view_View_OnClickListener_;
146146
}
147147

@@ -177,7 +177,7 @@ public virtual unsafe void SetOnClickListener (Android.Views.View.IOnClickListen
177177
static Delegate GetSetOn123Listener_Landroid_view_View_OnClickListener_Handler ()
178178
{
179179
if (cb_setOn123Listener_Landroid_view_View_OnClickListener_ == null)
180-
cb_setOn123Listener_Landroid_view_View_OnClickListener_ = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, IntPtr>) n_SetOn123Listener_Landroid_view_View_OnClickListener_);
180+
cb_setOn123Listener_Landroid_view_View_OnClickListener_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_V) n_SetOn123Listener_Landroid_view_View_OnClickListener_);
181181
return cb_setOn123Listener_Landroid_view_View_OnClickListener_;
182182
}
183183

@@ -213,7 +213,7 @@ public virtual unsafe void SetOn123Listener (Android.Views.View.IOnClickListener
213213
static Delegate GetAddTouchables_Ljava_util_ArrayList_Handler ()
214214
{
215215
if (cb_addTouchables_Ljava_util_ArrayList_ == null)
216-
cb_addTouchables_Ljava_util_ArrayList_ = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, IntPtr>) n_AddTouchables_Ljava_util_ArrayList_);
216+
cb_addTouchables_Ljava_util_ArrayList_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_V) n_AddTouchables_Ljava_util_ArrayList_);
217217
return cb_addTouchables_Ljava_util_ArrayList_;
218218
}
219219

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
using System;
2+
13
[assembly:global::Android.Runtime.NamespaceMapping (Java = "android.view", Managed="Android.Views")]
24
[assembly:global::Android.Runtime.NamespaceMapping (Java = "android.text", Managed="Android.Text")]
35
[assembly:global::Android.Runtime.NamespaceMapping (Java = "java.lang", Managed="Java.Lang")]
6+
7+
delegate int _JniMarshal_PPL_I (IntPtr jnienv, IntPtr klass, IntPtr p0);
8+
delegate void _JniMarshal_PPL_V (IntPtr jnienv, IntPtr klass, IntPtr p0);

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/Common/WriteInterfaceMethodInvokers.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ static Delegate cb_GetCountForKey_Ljava_lang_String_;
33
static Delegate GetGetCountForKey_Ljava_lang_String_Handler ()
44
{
55
if (cb_GetCountForKey_Ljava_lang_String_ == null)
6-
cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, IntPtr, int>) n_GetCountForKey_Ljava_lang_String_);
6+
cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_I) n_GetCountForKey_Ljava_lang_String_);
77
return cb_GetCountForKey_Ljava_lang_String_;
88
}
99

@@ -34,7 +34,7 @@ static Delegate cb_Key;
3434
static Delegate GetKeyHandler ()
3535
{
3636
if (cb_Key == null)
37-
cb_Key = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, IntPtr>) n_Key);
37+
cb_Key = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_L) n_Key);
3838
return cb_Key;
3939
}
4040

@@ -58,7 +58,7 @@ static Delegate cb_AbstractMethod;
5858
static Delegate GetAbstractMethodHandler ()
5959
{
6060
if (cb_AbstractMethod == null)
61-
cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr>) n_AbstractMethod);
61+
cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_V) n_AbstractMethod);
6262
return cb_AbstractMethod;
6363
}
6464

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/Common/WriteInterfaceMethodInvokersWithSkips.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ static Delegate cb_GetCountForKey_Ljava_lang_String_;
33
static Delegate GetGetCountForKey_Ljava_lang_String_Handler ()
44
{
55
if (cb_GetCountForKey_Ljava_lang_String_ == null)
6-
cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, IntPtr, int>) n_GetCountForKey_Ljava_lang_String_);
6+
cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_I) n_GetCountForKey_Ljava_lang_String_);
77
return cb_GetCountForKey_Ljava_lang_String_;
88
}
99

@@ -34,7 +34,7 @@ static Delegate cb_Key;
3434
static Delegate GetKeyHandler ()
3535
{
3636
if (cb_Key == null)
37-
cb_Key = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, IntPtr>) n_Key);
37+
cb_Key = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_L) n_Key);
3838
return cb_Key;
3939
}
4040

@@ -58,7 +58,7 @@ static Delegate cb_AbstractMethod;
5858
static Delegate GetAbstractMethodHandler ()
5959
{
6060
if (cb_AbstractMethod == null)
61-
cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr>) n_AbstractMethod);
61+
cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_V) n_AbstractMethod);
6262
return cb_AbstractMethod;
6363
}
6464

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/Common/WriteInterfacePropertyInvokers.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ static Delegate cb_get_Count;
33
static Delegate Getget_CountHandler ()
44
{
55
if (cb_get_Count == null)
6-
cb_get_Count = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, int>) n_get_Count);
6+
cb_get_Count = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_I) n_get_Count);
77
return cb_get_Count;
88
}
99

@@ -19,7 +19,7 @@ static Delegate cb_set_Count_I;
1919
static Delegate Getset_Count_IHandler ()
2020
{
2121
if (cb_set_Count_I == null)
22-
cb_set_Count_I = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, int>) n_set_Count_I);
22+
cb_set_Count_I = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPI_V) n_set_Count_I);
2323
return cb_set_Count_I;
2424
}
2525

@@ -52,7 +52,7 @@ static Delegate cb_get_Key;
5252
static Delegate Getget_KeyHandler ()
5353
{
5454
if (cb_get_Key == null)
55-
cb_get_Key = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, IntPtr>) n_get_Key);
55+
cb_get_Key = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_L) n_get_Key);
5656
return cb_get_Key;
5757
}
5858

@@ -68,7 +68,7 @@ static Delegate cb_set_Key_Ljava_lang_String_;
6868
static Delegate Getset_Key_Ljava_lang_String_Handler ()
6969
{
7070
if (cb_set_Key_Ljava_lang_String_ == null)
71-
cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, IntPtr>) n_set_Key_Ljava_lang_String_);
71+
cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_V) n_set_Key_Ljava_lang_String_);
7272
return cb_set_Key_Ljava_lang_String_;
7373
}
7474

@@ -104,7 +104,7 @@ static Delegate cb_get_StaticCount;
104104
static Delegate Getget_StaticCountHandler ()
105105
{
106106
if (cb_get_StaticCount == null)
107-
cb_get_StaticCount = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, int>) n_get_StaticCount);
107+
cb_get_StaticCount = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_I) n_get_StaticCount);
108108
return cb_get_StaticCount;
109109
}
110110

@@ -120,7 +120,7 @@ static Delegate cb_set_StaticCount_I;
120120
static Delegate Getset_StaticCount_IHandler ()
121121
{
122122
if (cb_set_StaticCount_I == null)
123-
cb_set_StaticCount_I = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, int>) n_set_StaticCount_I);
123+
cb_set_StaticCount_I = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPI_V) n_set_StaticCount_I);
124124
return cb_set_StaticCount_I;
125125
}
126126

@@ -153,7 +153,7 @@ static Delegate cb_get_AbstractCount;
153153
static Delegate Getget_AbstractCountHandler ()
154154
{
155155
if (cb_get_AbstractCount == null)
156-
cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, int>) n_get_AbstractCount);
156+
cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_I) n_get_AbstractCount);
157157
return cb_get_AbstractCount;
158158
}
159159

@@ -169,7 +169,7 @@ static Delegate cb_set_AbstractCount_I;
169169
static Delegate Getset_AbstractCount_IHandler ()
170170
{
171171
if (cb_set_AbstractCount_I == null)
172-
cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, int>) n_set_AbstractCount_I);
172+
cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPI_V) n_set_AbstractCount_I);
173173
return cb_set_AbstractCount_I;
174174
}
175175

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/Common/WriteInterfacePropertyInvokersWithSkips.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ static Delegate cb_get_Key;
33
static Delegate Getget_KeyHandler ()
44
{
55
if (cb_get_Key == null)
6-
cb_get_Key = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, IntPtr>) n_get_Key);
6+
cb_get_Key = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_L) n_get_Key);
77
return cb_get_Key;
88
}
99

@@ -19,7 +19,7 @@ static Delegate cb_set_Key_Ljava_lang_String_;
1919
static Delegate Getset_Key_Ljava_lang_String_Handler ()
2020
{
2121
if (cb_set_Key_Ljava_lang_String_ == null)
22-
cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, IntPtr>) n_set_Key_Ljava_lang_String_);
22+
cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPL_V) n_set_Key_Ljava_lang_String_);
2323
return cb_set_Key_Ljava_lang_String_;
2424
}
2525

@@ -55,7 +55,7 @@ static Delegate cb_get_StaticCount;
5555
static Delegate Getget_StaticCountHandler ()
5656
{
5757
if (cb_get_StaticCount == null)
58-
cb_get_StaticCount = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, int>) n_get_StaticCount);
58+
cb_get_StaticCount = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_I) n_get_StaticCount);
5959
return cb_get_StaticCount;
6060
}
6161

@@ -71,7 +71,7 @@ static Delegate cb_set_StaticCount_I;
7171
static Delegate Getset_StaticCount_IHandler ()
7272
{
7373
if (cb_set_StaticCount_I == null)
74-
cb_set_StaticCount_I = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, int>) n_set_StaticCount_I);
74+
cb_set_StaticCount_I = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPI_V) n_set_StaticCount_I);
7575
return cb_set_StaticCount_I;
7676
}
7777

@@ -104,7 +104,7 @@ static Delegate cb_get_AbstractCount;
104104
static Delegate Getget_AbstractCountHandler ()
105105
{
106106
if (cb_get_AbstractCount == null)
107-
cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, int>) n_get_AbstractCount);
107+
cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_I) n_get_AbstractCount);
108108
return cb_get_AbstractCount;
109109
}
110110

@@ -120,7 +120,7 @@ static Delegate cb_set_AbstractCount_I;
120120
static Delegate Getset_AbstractCount_IHandler ()
121121
{
122122
if (cb_set_AbstractCount_I == null)
123-
cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, int>) n_set_AbstractCount_I);
123+
cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPI_V) n_set_AbstractCount_I);
124124
return cb_set_AbstractCount_I;
125125
}
126126

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/Common/WritePropertyAbstractDeclaration.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ static Delegate cb_get_MyProperty;
33
static Delegate Getget_MyPropertyHandler ()
44
{
55
if (cb_get_MyProperty == null)
6-
cb_get_MyProperty = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, int>) n_get_MyProperty);
6+
cb_get_MyProperty = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_I) n_get_MyProperty);
77
return cb_get_MyProperty;
88
}
99

@@ -19,7 +19,7 @@ static Delegate cb_set_MyProperty_I;
1919
static Delegate Getset_MyProperty_IHandler ()
2020
{
2121
if (cb_set_MyProperty_I == null)
22-
cb_set_MyProperty_I = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, int>) n_set_MyProperty_I);
22+
cb_set_MyProperty_I = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPI_V) n_set_MyProperty_I);
2323
return cb_set_MyProperty_I;
2424
}
2525

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/Common/WritePropertyCallbacks.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ static Delegate cb_get_MyProperty;
33
static Delegate Getget_MyPropertyHandler ()
44
{
55
if (cb_get_MyProperty == null)
6-
cb_get_MyProperty = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, int>) n_get_MyProperty);
6+
cb_get_MyProperty = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_I) n_get_MyProperty);
77
return cb_get_MyProperty;
88
}
99

@@ -19,7 +19,7 @@ static Delegate cb_set_MyProperty_I;
1919
static Delegate Getset_MyProperty_IHandler ()
2020
{
2121
if (cb_set_MyProperty_I == null)
22-
cb_set_MyProperty_I = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, int>) n_set_MyProperty_I);
22+
cb_set_MyProperty_I = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPI_V) n_set_MyProperty_I);
2323
return cb_set_MyProperty_I;
2424
}
2525

0 commit comments

Comments
 (0)