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

Fix passing IStringable array by ref scenarios #357

Merged
merged 1 commit into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions UnitTest/TestComponent_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,20 @@ public void Array_Nested()
Assert.True(AllEqual(a, b, c, d));
}

[Fact]
public void Array_Stringable()
{
IStringable[] a = new IStringable[] {
Windows.Data.Json.JsonValue.CreateNumberValue(3),
Windows.Data.Json.JsonValue.CreateNumberValue(4),
Windows.Data.Json.JsonValue.CreateNumberValue(5.0)
};
IStringable[] b = new IStringable[a.Length];
IStringable[] c;
IStringable[] d = Tests.Array16(a, b, out c);
Assert.True(AllEqual(a, b, c, d));
}

private T[] Array_Call<T>(T[] a, T[] b, out T[] c)
{
Assert.True(a.Length == b.Length);
Expand Down Expand Up @@ -519,6 +533,12 @@ public void Array_Nested_Call()
Tests.Array15Call(Array_Call);
}

[Fact]
public void Array_Stringable_Call()
{
Tests.Array16Call(Array_Call);
}

[Fact]
public void Collections_IEnumerable()
{
Expand Down
16 changes: 16 additions & 0 deletions WinRT.Runtime/Marshalers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,20 @@ public static unsafe T[] FromAbiArray(object box, Func<IntPtr, T> fromAbi)
return array;
}

public static unsafe void CopyAbiArray(T[] array, object box, Func<IntPtr, T> fromAbi)
{
if (box is null)
{
return;
}
var abi = ((int length, IntPtr data))box;
var data = (IntPtr*)abi.data.ToPointer();
for (int i = 0; i < abi.length; i++)
{
array[i] = fromAbi(data[i]);
}
}

public static unsafe (int length, IntPtr data) FromManagedArray(T[] array, Func<T, IntPtr> fromManaged)
{
if (array is null)
Expand Down Expand Up @@ -867,6 +881,8 @@ public static unsafe void CopyManaged(T value, IntPtr dest)

public static unsafe T[] FromAbiArray(object box) => MarshalInterfaceHelper<T>.FromAbiArray(box, FromAbi);

public static unsafe void CopyAbiArray(T[] array, object box) => MarshalInterfaceHelper<T>.CopyAbiArray(array, box, FromAbi);

public static unsafe (int length, IntPtr data) FromManagedArray(T[] array) => MarshalInterfaceHelper<T>.FromManagedArray(array, (o) => FromManaged(o));

public static unsafe void CopyManagedArray(T[] array, IntPtr data) => MarshalInterfaceHelper<T>.CopyManagedArray(array, data, (o, dest) => CopyManaged(o, dest));
Expand Down
2 changes: 1 addition & 1 deletion WinRT.Runtime/Projections/Uri.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static IObjectReference CreateMarshaler(global::System.Uri value)
return null;
}

using var uri = ObjectReference<ABI.Windows.Foundation.IUriRuntimeClassVftbl>.FromAbi(ptr);
using var uri = ObjectReference<IUnknownVftbl>.FromAbi(ptr).As<ABI.Windows.Foundation.IUriRuntimeClassVftbl>();
IntPtr rawUri = IntPtr.Zero;
try
{
Expand Down
2 changes: 1 addition & 1 deletion get_testwinrt.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ git checkout -f master
if ErrorLevel 1 popd & exit /b !ErrorLevel!
git fetch -f
if ErrorLevel 1 popd & exit /b !ErrorLevel!
git reset -q --hard 6d72afbcb51ab3981c6cd620d24954020f4d2bbc
git reset -q --hard e058f2fc16e4812a16b5453da7ef4d65b3cf0bfe
if ErrorLevel 1 popd & exit /b !ErrorLevel!
echo Restoring Nuget
..\.nuget\nuget.exe restore
Expand Down