Skip to content

Commit

Permalink
fix issue with FromManaged returning an HSTRING reference, rather tha…
Browse files Browse the repository at this point in the history
…n allocating an HSTRING, causing crashes (#551)
  • Loading branch information
Scottj1s authored Nov 3, 2020
1 parent 25e2ed4 commit 8d6b661
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions WinRT.Runtime/Projections/Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ internal void Dispose()
}
}

public static Marshaler CreateMarshaler(global::System.Type value)
{
private static (String Name, TypeKind Kind) ToAbi(global::System.Type value)
{
TypeKind kind = TypeKind.Custom;

if (value is object)
Expand All @@ -47,12 +47,18 @@ public static Marshaler CreateMarshaler(global::System.Type value)
{
kind = TypeKind.Metadata;
}
}
}

return (kind == TypeKind.Custom ? value.AssemblyQualifiedName : TypeNameSupport.GetNameForType(value, TypeNameGenerationFlags.None), kind);
}

public static Marshaler CreateMarshaler(global::System.Type value)
{
var abi = ToAbi(value);
return new Marshaler
{
Name = MarshalString.CreateMarshaler(kind == TypeKind.Custom ? value.AssemblyQualifiedName : TypeNameSupport.GetNameForType(value, TypeNameGenerationFlags.None)),
Kind = kind
Name = MarshalString.CreateMarshaler(abi.Name),
Kind = abi.Kind
};
}

Expand Down Expand Up @@ -85,8 +91,13 @@ public static unsafe void CopyAbi(Marshaler arg, IntPtr dest) =>
*(Type*)dest.ToPointer() = GetAbi(arg);

public static Type FromManaged(global::System.Type value)
{
return GetAbi(CreateMarshaler(value));
{
var abi = ToAbi(value);
return new Type
{
Name = MarshalString.FromManaged(abi.Name),
Kind = abi.Kind
};
}

public static unsafe void CopyManaged(global::System.Type arg, IntPtr dest) =>
Expand Down

0 comments on commit 8d6b661

Please sign in to comment.