Skip to content

Commit

Permalink
Fix RCW caching. Fixes #143
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoritzinsky committed Apr 16, 2020
1 parent f214b58 commit debb39c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion WinRT.Runtime/ComWrappersSupport.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal static unsafe InspectableInfo GetInspectableInfo(IntPtr pThis)

public static IObjectReference CreateCCWForObject(object obj)
{
IntPtr ccw = ComWrappers.GetOrCreateComInterfaceForObject(obj, CreateComInterfaceFlags.CallerDefinedIUnknown | CreateComInterfaceFlags.TrackerSupport);
IntPtr ccw = ComWrappers.GetOrCreateComInterfaceForObject(obj, CreateComInterfaceFlags.TrackerSupport);
return ObjectReference<IUnknownVftbl>.Attach(ref ccw);
}

Expand Down
26 changes: 14 additions & 12 deletions cswinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ _inner = ObjectReference<IInspectable.Vftbl>.Attach(ref ptr);
var defaultInterface = new %(_inner);
_defaultLazy = new Lazy<%>(() => defaultInterface);
ComWrappersSupport.RegisterObjectForInterface(this, _inner.ThisPtr);
ComWrappersSupport.RegisterObjectForInterface(this, ThisPtr);
}
)",
class_type.TypeName(),
Expand Down Expand Up @@ -1959,15 +1959,8 @@ event % %;)",
}
break;
case category::class_type:
if(get_mapped_type(type.TypeNamespace(), type.TypeName()))
{
m.marshaler_type = w.write_temp("%", bind<write_type_name>(type, true, true));
m.local_type = m.is_out() ? "IntPtr" : "IObjectReference";
}
else
{
m.local_type = "IntPtr";
}
m.marshaler_type = w.write_temp("%", bind<write_type_name>(semantics, true, true));
m.local_type = m.is_out() ? "IntPtr" : "IObjectReference";
break;
case category::delegate_type:
m.marshaler_type = get_abi_type();
Expand Down Expand Up @@ -4037,16 +4030,19 @@ return global::System.Runtime.InteropServices.CustomQueryInterfaceResult.NotHand
auto projected_type_name = write_type_name_temp(w, type);
auto default_interface_abi_name = get_default_interface_name(w, type, true);

w.write(R"([global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public struct %
w.write(R"(internal struct %
{
public static IObjectReference CreateMarshaler(% obj) => MarshalInspectable.CreateMarshaler(obj).As<%.Vftbl>();
public static IntPtr GetAbi(IObjectReference value) => MarshalInterfaceHelper<object>.GetAbi(value);
public static % FromAbi(IntPtr thisPtr) => (%)MarshalInspectable.FromAbi(thisPtr);
public static IntPtr FromManaged(% obj) => obj is null ? IntPtr.Zero : CreateMarshaler(obj).GetRef();
public static unsafe MarshalInterfaceHelper<%>.MarshalerArray CreateMarshalerArray(%[] array) => MarshalInterfaceHelper<%>.CreateMarshalerArray(array, (o) => CreateMarshaler(o));
public static (int length, IntPtr data) GetAbiArray(object box) => MarshalInterfaceHelper<%>.GetAbiArray(box);
public static unsafe %[] FromAbiArray(object box) => MarshalInterfaceHelper<%>.FromAbiArray(box, FromAbi);
public static (int length, IntPtr data) FromManagedArray(%[] array) => MarshalInterfaceHelper<%>.FromManagedArray(array, (o) => FromManaged(o));
public static void DisposeMarshaler(IObjectReference value) => MarshalInspectable.DisposeMarshaler(value);
public static void DisposeAbi(IntPtr abi) => MarshalInspectable.DisposeAbi(abi);
public static unsafe void DisposeAbiArray(object box) => MarshalInspectable.DisposeAbiArray(box);
}
)",
abi_type_name,
Expand All @@ -4056,6 +4052,12 @@ public static void DisposeAbi(IntPtr abi) => MarshalInspectable.DisposeAbi(abi);
projected_type_name,
projected_type_name,
projected_type_name,
projected_type_name,
projected_type_name,
projected_type_name,
projected_type_name,
projected_type_name,
projected_type_name,
projected_type_name);
}

Expand Down

0 comments on commit debb39c

Please sign in to comment.