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 source generator for exception types and fix is operator #1682

Merged
merged 11 commits into from
Aug 1, 2024
15 changes: 15 additions & 0 deletions src/Authoring/WinRT.SourceGenerator/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,10 @@ public static string GetAbiType(ITypeSymbol type, TypeMapper mapper)
{
return "IntPtr";
}
else if (typeStr == "System.Exception")
{
return "ABI.System.Exception";
}

if (type.IsValueType)
{
Expand Down Expand Up @@ -659,6 +663,17 @@ public static string GetMarshalerClass(string type, string abiType, TypeKind kin
return "global::ABI.System.Type";
}
}
else if (type == "System.Exception" || type == "Exception")
{
if (isArray)
{
return "MarshalNonBlittable<global::System.Exception>";
}
else
{
return "global::ABI.System.Exception";
}
}
else if (type == "System.Object" || type == "object")
{
return "MarshalInspectable<object>";
Expand Down
26 changes: 26 additions & 0 deletions src/Tests/FunctionalTests/Collections/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,32 @@
networkNames.AddRange(names);
}

if (names is IList<double> networkNamesList)
{
return 101;
}

var exceptionList = new List<Exception>();
instance.BindableIterableProperty = exceptionList;
if (exceptionList != instance.BindableIterableProperty)
{
return 101;
}

var uriList = new List<Uri>();
instance.BindableIterableProperty = uriList;
if (uriList != instance.BindableIterableProperty)
{
return 101;
}

var dateTimeOffsetList = new List<System.DateTimeOffset>();
instance.BindableIterableProperty = dateTimeOffsetList;
if (dateTimeOffsetList != instance.BindableIterableProperty)
{
return 101;
}

return 100;

static bool SequencesEqual<T>(IEnumerable<T> x, params IEnumerable<T>[] list) => list.All((y) => x.SequenceEqual(y));
Expand Down
15 changes: 15 additions & 0 deletions src/Tests/TestComponentCSharp/Class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,21 @@ namespace winrt::TestComponentCSharp::implementation
std::copy(_ints.begin(), _ints.end(), ints.begin());
}

com_array<winrt::hresult> Class::GetAndSetHResults(array_view<winrt::hresult const> hresults)
{
return com_array<winrt::hresult>(hresults.begin(), hresults.end());
}

com_array<winrt::Windows::Foundation::Uri> Class::GetAndSetUris(array_view<winrt::Windows::Foundation::Uri const> uris)
{
return com_array<winrt::Windows::Foundation::Uri>(uris.begin(), uris.end());
}

com_array<winrt::Windows::Foundation::DateTime> Class::GetAndSetDateTimes(array_view<winrt::Windows::Foundation::DateTime const> datetime)
{
return com_array<winrt::Windows::Foundation::DateTime>(datetime.begin(), datetime.end());
}

IVectorView<int32_t> Class::GetIntVector()
{
return winrt::single_threaded_vector_view(std::vector{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
Expand Down
4 changes: 4 additions & 0 deletions src/Tests/TestComponentCSharp/Class.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ namespace winrt::TestComponentCSharp::implementation
com_array<int32_t> GetInts();
void FillInts(array_view<int32_t> ints);

com_array<winrt::hresult> GetAndSetHResults(array_view<winrt::hresult const> hresults);
com_array<winrt::Windows::Foundation::Uri> GetAndSetUris(array_view<winrt::Windows::Foundation::Uri const> uris);
com_array<winrt::Windows::Foundation::DateTime> GetAndSetDateTimes(array_view<winrt::Windows::Foundation::DateTime const> datetime);

Windows::Foundation::IAsyncOperation<int32_t> GetIntAsync();
Windows::Foundation::IAsyncOperationWithProgress<hstring, int32_t> GetStringAsync();

Expand Down
4 changes: 4 additions & 0 deletions src/Tests/TestComponentCSharp/TestComponentCSharp.idl
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ namespace TestComponentCSharp
Int32[] GetInts();
void FillInts(ref Int32[] ints);

Windows.Foundation.HResult[] GetAndSetHResults(Windows.Foundation.HResult[] hresults);
Windows.Foundation.Uri[] GetAndSetUris(Windows.Foundation.Uri[] uris);
Windows.Foundation.DateTime[] GetAndSetDateTimes(Windows.Foundation.DateTime[] datetime);

// Generics
Windows.Foundation.IAsyncOperation<Int32> GetIntAsync();
Windows.Foundation.IAsyncOperationWithProgress<String, Int32> GetStringAsync();
Expand Down
16 changes: 15 additions & 1 deletion src/WinRT.Runtime/IWinRTObject.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,21 @@ internal sealed bool IsInterfaceImplementedFallback(RuntimeTypeHandle interfaceT
return false;
}

Type helperType = type.FindHelperType();
Type helperType;
try
{
helperType = type.FindHelperType();
}
catch (Exception)
manodasanW marked this conversation as resolved.
Show resolved Hide resolved
{
if (throwIfNotImplemented)
manodasanW marked this conversation as resolved.
Show resolved Hide resolved
{
throw;
}

return false;
}

if (helperType is null || !helperType.IsInterface)
{
return false;
Expand Down
6 changes: 4 additions & 2 deletions src/WinRT.Runtime/Marshalers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,8 @@ static MarshalGeneric()
DisposeMarshaler = ABI.System.NonBlittableMarshallingStubs.NoOpFunc;
DisposeAbi = ABI.System.NonBlittableMarshallingStubs.NoOpFunc;
}
else if (typeof(T).IsValueType)
else if (typeof(T).IsValueType ||
manodasanW marked this conversation as resolved.
Show resolved Hide resolved
typeof(T) == typeof(Exception))
manodasanW marked this conversation as resolved.
Show resolved Hide resolved
{
// Value types can have custom marshaller types and use value types in places where we can't construct
// delegates in the same efficient way as with reference types. Use the fallback path in this case
Expand Down Expand Up @@ -2026,7 +2027,8 @@ static Marshaler()
DisposeMarshalerArray = new Action<object>(ABI.System.Type.DisposeMarshalerArray);
DisposeAbiArray = new Action<object>(ABI.System.Type.DisposeAbiArray);
}
else if (typeof(T).IsValueType)
else if (typeof(T).IsValueType ||
typeof(T) == typeof(Exception))
{
if (typeof(T) == typeof(bool))
{
Expand Down
3 changes: 2 additions & 1 deletion src/WinRT.Runtime/MatchingRefApiCompatBaseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,5 @@ TypesMustExist : Type 'WinRT.WinRTAssemblyExportsTypeAttribute' does not exist i
TypesMustExist : Type 'Microsoft.UI.Xaml.Data.BindableCustomProperty' does not exist in the reference but it does exist in the implementation.
TypesMustExist : Type 'WinRT.BindableCustomPropertyAttribute' does not exist in the reference but it does exist in the implementation.
TypesMustExist : Type 'Microsoft.UI.Xaml.Data.IBindableCustomPropertyImplementation' does not exist in the reference but it does exist in the implementation.
Total Issues: 272
MembersMustExist : Member 'public void ABI.System.Uri.DisposeAbiArray(System.Object)' does not exist in the reference but it does exist in the implementation.
Total Issues: 273
1 change: 1 addition & 0 deletions src/WinRT.Runtime/Projections/Uri.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public static IntPtr FromManaged(global::System.Uri value)
public static void DisposeMarshalerArray(MarshalInterfaceHelper<global::System.Uri>.MarshalerArray array) => MarshalInterfaceHelper<global::System.Uri>.DisposeMarshalerArray(array);
public static void DisposeMarshaler(IObjectReference m) { m?.Dispose(); }
public static void DisposeAbi(IntPtr abi) { MarshalInspectable<object>.DisposeAbi(abi); }
public static void DisposeAbiArray(object box) => MarshalInterfaceHelper<global::System.Uri>.DisposeAbiArray(box);

public static string GetGuidSignature()
{
Expand Down