Skip to content

Commit

Permalink
Fix issue where dispose ABI wasn't being called. (#1095)
Browse files Browse the repository at this point in the history
  • Loading branch information
manodasanW authored Feb 3, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent b01c69d commit 5e2c1df
Showing 3 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/WinRT.Runtime/Marshalers.cs
Original file line number Diff line number Diff line change
@@ -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);
2 changes: 1 addition & 1 deletion src/WinRT.Runtime/Projections/Type.cs
Original file line number Diff line number Diff line change
@@ -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()
{
29 changes: 20 additions & 9 deletions src/cswinrt/code_writers.h
Original file line number Diff line number Diff line change
@@ -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
{)");
}
@@ -7041,6 +7041,7 @@ try
m.__abi = new %()
{
%};
%
return m;)",
abi_type,
[&](writer& w)
@@ -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();
}
}
)");
}
@@ -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{ ", " };

0 comments on commit 5e2c1df

Please sign in to comment.