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 issue where dispose ABI wasn't being called in non blittable structs #1095

Merged
merged 2 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/WinRT.Runtime/Marshalers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ unsafe void CopyEnum(object value, IntPtr dest)
FromManaged = MarshalNonBlittable<T>.FromManaged;
CopyManaged = MarshalNonBlittable<T>.CopyManaged;
DisposeMarshaler = MarshalNonBlittable<T>.DisposeMarshaler;
DisposeAbi = (object box) => { };
DisposeAbi = MarshalNonBlittable<T>.DisposeAbi;
CreateMarshalerArray = (T[] array) => MarshalNonBlittable<T>.CreateMarshalerArray(array);
GetAbiArray = (object box) => MarshalNonBlittable<T>.GetAbiArray(box);
FromAbiArray = (object box) => MarshalNonBlittable<T>.FromAbiArray(box);
Expand Down
2 changes: 1 addition & 1 deletion src/WinRT.Runtime/Projections/Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static unsafe void CopyManaged(global::System.Type arg, IntPtr dest) =>
*(Type*)dest.ToPointer() = FromManaged(arg);

public static void DisposeMarshaler(Marshaler m) { m.Dispose(); }
public static void DisposeAbi(Type abi) { }
public static void DisposeAbi(Type abi) { MarshalString.DisposeAbi(abi.Name); }

public static string GetGuidSignature()
{
Expand Down
29 changes: 20 additions & 9 deletions src/cswinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7026,7 +7026,7 @@ var m = new Marshaler();)",
if (have_disposers)
{
w.write(R"(
Func<bool> dispose = () => { m.Dispose(); return false; };
bool success = false;
try
{)");
}
Expand All @@ -7041,6 +7041,7 @@ try
m.__abi = new %()
{
%};
%
return m;)",
abi_type,
[&](writer& w)
Expand Down Expand Up @@ -7074,15 +7075,18 @@ return m;)",
m.marshaler_type,
m.param_name);
}
});
},
have_disposers ? "success = true;" : "");
if (have_disposers)
{
w.write(R"(
}
catch (Exception) when (dispose())
finally
{
// Will never execute
return default;
if (!success)
{
m.Dispose();
}
}
)");
}
Expand Down Expand Up @@ -7198,14 +7202,21 @@ public static void DisposeMarshaler(Marshaler m) %
have_disposers ? "=> m.Dispose();" : "{}");

w.write(R"(
public static void DisposeAbi(% abi){ /*todo*/ }
public static void DisposeAbi(% abi)
{
%}
}

)",
abi_type);
abi_type,
bind_each([](writer& w, abi_marshaler const& m)
{
if (m.is_value_type) return;
w.write("%.DisposeAbi(abi.%);\n",
m.marshaler_type,
m.param_name);
}, marshalers));
}


void write_factory_class_inheritance(writer& w, TypeDef const& type)
{
auto delimiter{ ", " };
Expand Down