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

Type.FromManaged returning an HSTRING reference, rather than allocating an HSTRING, causing crashes #551

Merged
merged 2 commits into from
Nov 3, 2020
Merged
Changes from 1 commit
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
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),
manodasanW marked this conversation as resolved.
Show resolved Hide resolved
Kind = abi.Kind
};
}

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