Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[marshal methods] Properly support arrays of arrays #7707

Merged
merged 2 commits into from
Jan 20, 2023

Conversation

grendello
Copy link
Contributor

Fixes: #7693

Java code similar to:

package com.xamarin.android;

public interface DataListener {
  void onDataReceived (
    java.lang.String fromNode,
    java.lang.String fromChannel,
    java.lang.String payloadType,
    byte[][] payload);
}

Generates Java JNI signature:

(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[[B)V

which then would throw our marshal methods native assembly generator off, because it didn't expect that there might be consecutive [ characters for parameters which are arrays of arrays (of any rank):

System.InvalidOperationException: Unsupported JNI array type '[' at index 56 of signature '(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[[B)V'
error XAGPM7009:    at Xamarin.Android.Tasks.MarshalMethodsNativeAssemblyGenerator.<ParseJniSignature>g__JniTypeToManaged|55_0(Char jniType, <>c__DisplayClass55_0&)
error XAGPM7009:    at Xamarin.Android.Tasks.MarshalMethodsNativeAssemblyGenerator.ParseJniSignature(String signature, MethodDefinition implementedMethod)
error XAGPM7009:    at Xamarin.Android.Tasks.MarshalMethodsNativeAssemblyGenerator.ProcessAndAddMethod(List`1 allMethods, MarshalMethodEntry entry, Boolean useFullNativeSignature, Dictionary`2 seenClasses, Dictionary`2 overloadedNativeSymbolNames)
error XAGPM7009:    at Xamarin.Android.Tasks.MarshalMethodsNativeAssemblyGenerator.Init()
error XAGPM7009:    at Xamarin.Android.Tasks.GeneratePackageManagerJava.AddEnvironment()
error XAGPM7009:    at Xamarin.Android.Tasks.GeneratePackageManagerJava.RunTask()
error XAGPM7009:    at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/builder/azdo/_work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17

Fix this by skipping over the "extra" [ characters. This generates code which uses a simple pointer to array, instead of a pointer to pointer etc. We can take this shortcut because we don't dereference the parameter in our generated code in any way, instead passing it as-is to the managed code.

Fixes: dotnet#7693

Java code similar to:

    package com.xamarin.android;

    public interface DataListener {
      void onDataReceived (
        java.lang.String fromNode,
        java.lang.String fromChannel,
        java.lang.String payloadType,
        byte[][] payload);
    }

Generates Java JNI signature:

    (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[[B)V

which then would throw our marshal methods native assembly generator
off, because it didn't expect that there might be consecutive `[`
characters for parameters which are arrays of arrays (of any rank):

    System.InvalidOperationException: Unsupported JNI array type '[' at index 56 of signature '(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[[B)V'
    error XAGPM7009:    at Xamarin.Android.Tasks.MarshalMethodsNativeAssemblyGenerator.<ParseJniSignature>g__JniTypeToManaged|55_0(Char jniType, <>c__DisplayClass55_0&)
    error XAGPM7009:    at Xamarin.Android.Tasks.MarshalMethodsNativeAssemblyGenerator.ParseJniSignature(String signature, MethodDefinition implementedMethod)
    error XAGPM7009:    at Xamarin.Android.Tasks.MarshalMethodsNativeAssemblyGenerator.ProcessAndAddMethod(List`1 allMethods, MarshalMethodEntry entry, Boolean useFullNativeSignature, Dictionary`2 seenClasses, Dictionary`2 overloadedNativeSymbolNames)
    error XAGPM7009:    at Xamarin.Android.Tasks.MarshalMethodsNativeAssemblyGenerator.Init()
    error XAGPM7009:    at Xamarin.Android.Tasks.GeneratePackageManagerJava.AddEnvironment()
    error XAGPM7009:    at Xamarin.Android.Tasks.GeneratePackageManagerJava.RunTask()
    error XAGPM7009:    at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/builder/azdo/_work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17

Fix this by skipping over the "extra" `[` characters.  This generates
code which uses a simple pointer to array, instead of a pointer to
pointer etc.  We can take this shortcut because we don't dereference the
parameter in our generated code in any way, instead passing it as-is to
the managed code.
* main:
  [ci] Pass token when building Designer tests (dotnet#7715)
  [Mono.Android] Android.Telecom.InCallService.SetAudioRoute() + enum (dotnet#7711)
  [Mono.Android] Fix some incorrect enums. (dotnet#7670)
  [Xamarin.Android.Build.Tasks] _Microsoft.Android.Resource.Designer namespace (dotnet#7681)
  LEGO: Merge pull request 7713
  [Xamarin.Android.Build.Tasks] lazily populate Resource lookup (dotnet#7686)
@jonpryor jonpryor merged commit baa5a73 into dotnet:main Jan 20, 2023
@grendello grendello deleted the mm-array-of-arrays branch January 20, 2023 08:05
grendello added a commit to grendello/xamarin-android that referenced this pull request Jan 26, 2023
* main: (32 commits)
  [monodroid] Replace `exit()` with `abort()` in native code (dotnet#7734)
  Bump to xamarin/Java.Interop/main@8a1ae57 (dotnet#7738)
  [build] bump `$(AndroidNet7Version)` (dotnet#7737)
  Bump to xamarin/Java.Interop/main@1366d99 (dotnet#7718)
  [Xamarin.Android.Build.Tasks] fix AndroidGenerateResourceDesigner (dotnet#7721)
  Bump to xamarin/monodroid@50faac94 (dotnet#7725)
  Revert "[Xamarin.Android.Build.Tasks] fix cases of missing `@(Reference)` (dotnet#7642)" (dotnet#7726)
  [marshal methods] Properly support arrays of arrays (dotnet#7707)
  Bump to dotnet/installer@9962c6a 8.0.100-alpha.1.23063.11 (dotnet#7677)
  [Actions] Add action to bump the hash used for the unified pipeline (dotnet#7712)
  Bump to xamarin/xamarin-android-tools/main@099fd95 (dotnet#7709)
  [ci] Move build stages into yaml templates (dotnet#7553)
  [Xamarin.Android.Build.Tasks] fix NRE in `<GenerateResourceCaseMap/>` (dotnet#7716)
  [ci] Pass token when building Designer tests (dotnet#7715)
  [Mono.Android] Android.Telecom.InCallService.SetAudioRoute() + enum (dotnet#7711)
  [Mono.Android] Fix some incorrect enums. (dotnet#7670)
  [Xamarin.Android.Build.Tasks] _Microsoft.Android.Resource.Designer namespace (dotnet#7681)
  LEGO: Merge pull request 7713
  [Xamarin.Android.Build.Tasks] lazily populate Resource lookup (dotnet#7686)
  [Xamarin.Android.Build.Tasks] skip XA1034 logic in some cases (dotnet#7680)
  ...
grendello added a commit to grendello/xamarin-android that referenced this pull request Jan 30, 2023
* main:
  [marshal methods] Properly support arrays of arrays (dotnet#7707)
  Bump to dotnet/installer@9962c6a 8.0.100-alpha.1.23063.11 (dotnet#7677)
  [Actions] Add action to bump the hash used for the unified pipeline (dotnet#7712)
  Bump to xamarin/xamarin-android-tools/main@099fd95 (dotnet#7709)
  [ci] Move build stages into yaml templates (dotnet#7553)
  [Xamarin.Android.Build.Tasks] fix NRE in `<GenerateResourceCaseMap/>` (dotnet#7716)
  [ci] Pass token when building Designer tests (dotnet#7715)
@github-actions github-actions bot locked and limited conversation to collaborators Jan 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Marshal method feature does not support arrays of arrays
2 participants