Skip to content

Commit 16382c2

Browse files
Fix trimmable export rebase fallout
Use the Java.Interop activation constructor style when creating interface invokers, and align export UCO wrapper tests with the catch/finally shape emitted by export dispatch. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e2a45df commit 16382c2

3 files changed

Lines changed: 19 additions & 19 deletions

File tree

src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/ExportMethodDispatchEmitter.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,4 +613,3 @@ void AddUnmanagedCallersOnlyAttribute (MethodDefinitionHandle handle)
613613
}
614614

615615
}
616-

src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/TypeMapAssemblyEmitter.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -654,25 +654,26 @@ void EmitCreateInstance (JavaPeerProxyData proxy)
654654
return;
655655
}
656656

657-
// JavaInterop-style activation ctors (ref JniObjectReference, JniObjectReferenceOptions)
658-
// require parameter conversion from (IntPtr, JniHandleOwnership).
659-
if (proxy.ActivationCtor?.Style == ActivationCtorStyle.JavaInterop) {
660-
if (proxy.InvokerType != null) {
661-
EmitCreateInstanceViaJavaInteropNewobj (_pe.ResolveTypeRef (proxy.InvokerType));
657+
if (proxy.InvokerType != null) {
658+
var invokerTypeRef = _pe.ResolveTypeRef (proxy.InvokerType);
659+
if (proxy.InvokerActivationCtorStyle == ActivationCtorStyle.JavaInterop) {
660+
EmitCreateInstanceViaJavaInteropNewobj (invokerTypeRef);
662661
} else {
663-
var targetRef = _pe.ResolveTypeRef (proxy.TargetType);
664-
var jiCtor = proxy.ActivationCtor ?? throw new InvalidOperationException ("ActivationCtor should not be null");
665-
if (jiCtor.IsOnLeafType) {
666-
EmitCreateInstanceViaJavaInteropNewobj (targetRef);
667-
} else {
668-
EmitCreateInstanceInheritedJavaInteropCtor (targetRef, jiCtor);
669-
}
662+
EmitCreateInstanceViaNewobj (invokerTypeRef);
670663
}
671664
return;
672665
}
673666

674-
if (proxy.InvokerType != null) {
675-
EmitCreateInstanceViaNewobj (_pe.ResolveTypeRef (proxy.InvokerType));
667+
// JavaInterop-style activation ctors (ref JniObjectReference, JniObjectReferenceOptions)
668+
// require parameter conversion from (IntPtr, JniHandleOwnership).
669+
if (proxy.ActivationCtor?.Style == ActivationCtorStyle.JavaInterop) {
670+
var targetRef = _pe.ResolveTypeRef (proxy.TargetType);
671+
var jiCtor = proxy.ActivationCtor ?? throw new InvalidOperationException ("ActivationCtor should not be null");
672+
if (jiCtor.IsOnLeafType) {
673+
EmitCreateInstanceViaJavaInteropNewobj (targetRef);
674+
} else {
675+
EmitCreateInstanceInheritedJavaInteropCtor (targetRef, jiCtor);
676+
}
676677
return;
677678
}
678679

tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/TypeMapAssemblyGeneratorTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -793,9 +793,9 @@ public void Generate_UcoMethod_BooleanParam_WrapperUsesByte_CallbackUsesSByte ()
793793
}
794794

795795
[Fact]
796-
public void Generate_UcoMethod_HasCatchRegionWithoutFinally ()
796+
public void Generate_ExportUcoMethod_HasCatchAndFinallyRegions ()
797797
{
798-
var peer = FindFixtureByJavaName ("my/app/TouchHandler");
798+
var peer = FindFixtureByJavaName ("my/app/ExportExample");
799799
using var stream = GenerateAssembly (new [] { peer }, "UcoLegacyWrapperShape");
800800
using var pe = new PEReader (stream);
801801
var reader = pe.GetMetadataReader ();
@@ -804,13 +804,13 @@ public void Generate_UcoMethod_HasCatchRegionWithoutFinally ()
804804
.First (h => {
805805
var method = reader.GetMethodDefinition (h);
806806
var name = reader.GetString (method.Name);
807-
return name.Contains ("onTouch") && name.Contains ("_uco_");
807+
return name.Contains ("myExportedMethod") && name.Contains ("_uco_");
808808
});
809809
var ucoMethod = reader.GetMethodDefinition (ucoMethodHandle);
810810
var body = pe.GetMethodBody (ucoMethod.RelativeVirtualAddress);
811811
Assert.NotNull (body);
812812
Assert.Contains (body.ExceptionRegions, r => r.Kind == ExceptionRegionKind.Catch);
813-
Assert.DoesNotContain (body.ExceptionRegions, r => r.Kind == ExceptionRegionKind.Finally);
813+
Assert.Contains (body.ExceptionRegions, r => r.Kind == ExceptionRegionKind.Finally);
814814
}
815815

816816
[Fact]

0 commit comments

Comments
 (0)