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

Add Context checks to factory caching and simplify factory caching between factories and statics. #1367

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
933501a
Add Context checks to factory caching and simplify factory caching be…
jlaanstra Sep 13, 2023
2757db1
Revert.
jlaanstra Sep 13, 2023
07ba6dd
Fix revert.
jlaanstra Sep 13, 2023
d6960c0
Also handle composable.
jlaanstra Sep 14, 2023
f5fbf5f
Updates to not rely on vftbl.
jlaanstra Sep 14, 2023
8550207
Fix test that creates UI objects on MTA which previously incorrectly …
jlaanstra Sep 14, 2023
f34a1cb
Remove unused class.
jlaanstra Sep 15, 2023
f45db4f
Enable use of IID optimization.
jlaanstra Sep 15, 2023
aa8d44e
Make inner readonly.
jlaanstra Sep 15, 2023
85e8adb
Simplify Guids.
jlaanstra Sep 15, 2023
6fb2030
Test with generated guids.
jlaanstra Sep 16, 2023
4ff6df6
Merge.
jlaanstra Sep 29, 2023
0913405
Add missing sealed.
jlaanstra Oct 2, 2023
1d8eba1
Always internal.
jlaanstra Oct 2, 2023
48ab2e0
Generate caches for factories and statics.
jlaanstra Oct 14, 2023
3fcc06e
Remove second method.
jlaanstra Oct 20, 2023
76eea1d
Fix factory methods with raw return types.
jlaanstra Oct 21, 2023
ca94c50
Moce functionality to BaseFactory.
jlaanstra Oct 21, 2023
775416f
Fix context check.
jlaanstra Oct 28, 2023
c7c1654
Fix.
jlaanstra Oct 28, 2023
4091559
Small optimizations.
jlaanstra Oct 28, 2023
110385f
Fix.
jlaanstra Oct 30, 2023
c314706
Try some things.
jlaanstra Oct 31, 2023
d8de07d
Fix.
jlaanstra Oct 31, 2023
be96669
Revert "Try some things."
jlaanstra Nov 1, 2023
8d89daf
Fix.
jlaanstra Nov 1, 2023
e109c22
Fix.
jlaanstra Nov 1, 2023
2042d2e
Fix.
jlaanstra Nov 2, 2023
e45320f
Change activationfactory logic.
jlaanstra Nov 2, 2023
104f491
More optimizations.
jlaanstra Nov 3, 2023
73d5e29
Fix.
jlaanstra Nov 3, 2023
f0659d4
Remove Interlocked.
jlaanstra Nov 3, 2023
f5fcef7
Fix nullref.
jlaanstra Nov 3, 2023
a1d2cb4
Simplify factory code inside projections.
jlaanstra Nov 3, 2023
d2d96fc
Reduce duplicate namespace.
jlaanstra Nov 3, 2023
57a91cf
Simplify.
jlaanstra Nov 3, 2023
01178c2
Revert "Remove Interlocked."
jlaanstra Nov 3, 2023
269390f
Revert "Fix."
jlaanstra Nov 3, 2023
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
1 change: 1 addition & 0 deletions nuget/Microsoft.Windows.CsWinRT.targets
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ $(CsWinRTInternalProjection)

<ItemGroup Condition="'$(CsWinRTComponent)' != 'true' and Exists('$(CsWinRTResponseFile)')">
<UpToDateCheckInput Include="@(CsWinRTInputs)" Set="WinMDs" />
<UpToDateCheckInput Include="$(CsWinRTExe)" Set="WinMDs" />
<UpToDateCheckBuilt Include="$(CsWinRTResponseFile)" Set="WinMDs" />
</ItemGroup>

Expand Down
9 changes: 2 additions & 7 deletions src/Tests/UnitTest/TestComponentCSharp_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2438,8 +2438,6 @@ public void AcquireObject()
// Object gets proxied to the apartment.
Assert.Equal(2, proxyObject.Commands.Count);
agileReference.Dispose();

proxyObject2 = agileReference2.Get();
}

public void CheckValue()
Expand All @@ -2448,9 +2446,6 @@ public void CheckValue()
Assert.Equal(ApartmentState.MTA, Thread.CurrentThread.GetApartmentState());
proxyObject = agileReference.Get();
Assert.Equal(2, proxyObject.Commands.Count);

nonAgileObject2 = new Windows.UI.Popups.PopupMenu();
agileReference2 = nonAgileObject2.AsAgile();

valueAcquired.Set();
}
Expand All @@ -2462,8 +2457,8 @@ public void CallProxyObject()
Assert.ThrowsAny<System.Exception>(() => proxyObject.Commands);
}

private Windows.UI.Popups.PopupMenu nonAgileObject, nonAgileObject2;
private Windows.UI.Popups.PopupMenu proxyObject, proxyObject2;
private Windows.UI.Popups.PopupMenu nonAgileObject;
private Windows.UI.Popups.PopupMenu proxyObject;
private AgileReference<Windows.UI.Popups.PopupMenu> agileReference, agileReference2;
private readonly AutoResetEvent objectAcquired = new AutoResetEvent(false);
private readonly AutoResetEvent valueAcquired = new AutoResetEvent(false);
Expand Down
12 changes: 1 addition & 11 deletions src/WinRT.Runtime/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@

namespace WinRT
{
static class Context
static partial class Context
{
[DllImport("api-ms-win-core-com-l1-1-0.dll")]
private static extern unsafe int CoGetContextToken(IntPtr* contextToken);

[DllImport("api-ms-win-core-com-l1-1-0.dll")]
private static extern int CoGetObjectContext(ref Guid riid, out IntPtr ppv);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same note as in the other PR, could you make this use a blittable signature while at it?


Expand All @@ -24,13 +21,6 @@ public static IntPtr GetContextCallback()
return contextCallbackPtr;
}

public unsafe static IntPtr GetContextToken()
{
IntPtr contextToken;
Marshal.ThrowExceptionForHR(CoGetContextToken(&contextToken));
return contextToken;
}

// Calls the given callback in the right context.
// On any exception, calls onFail callback if any set.
// If not set, exception is handled due to today we don't
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public ActivationFactory() : base("Microsoft.UI.Xaml.Data", "Microsoft.UI.Xaml.D
}

internal static ABI.Microsoft.UI.Xaml.Data.WinRTDataErrorsChangedEventArgsRuntimeClassFactory Instance =
new ActivationFactory()._As<ABI.Microsoft.UI.Xaml.Data.WinRTDataErrorsChangedEventArgsRuntimeClassFactory.Vftbl>();
new ActivationFactory().As<ABI.Microsoft.UI.Xaml.Data.WinRTDataErrorsChangedEventArgsRuntimeClassFactory.Vftbl>();
}

public static IObjectReference CreateMarshaler(global::System.ComponentModel.DataErrorsChangedEventArgs value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public ActivationFactory() : base("Microsoft.UI.Xaml.Interop", "Microsoft.UI.Xam
}

internal static WinRTNotifyCollectionChangedEventArgsRuntimeClassFactory Instance =
new ActivationFactory()._As<WinRTNotifyCollectionChangedEventArgsRuntimeClassFactory.Vftbl>();
new ActivationFactory().As<WinRTNotifyCollectionChangedEventArgsRuntimeClassFactory.Vftbl>();
}

public static IObjectReference CreateMarshaler(global::System.Collections.Specialized.NotifyCollectionChangedEventArgs value)
Expand Down
2 changes: 1 addition & 1 deletion src/WinRT.Runtime/Projections/PropertyChangedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public ActivationFactory() : base("Microsoft.UI.Xaml.Data", "Microsoft.UI.Xaml.D
}

internal static ABI.Microsoft.UI.Xaml.Data.WinRTPropertyChangedEventArgsRuntimeClassFactory Instance =
new ActivationFactory()._As<ABI.Microsoft.UI.Xaml.Data.WinRTPropertyChangedEventArgsRuntimeClassFactory.Vftbl>();
new ActivationFactory().As<ABI.Microsoft.UI.Xaml.Data.WinRTPropertyChangedEventArgsRuntimeClassFactory.Vftbl>();
}

public static IObjectReference CreateMarshaler(global::System.ComponentModel.PropertyChangedEventArgs value)
Expand Down
2 changes: 1 addition & 1 deletion src/WinRT.Runtime/Projections/Uri.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public ActivationFactory() : base("Windows.Foundation", "Windows.Foundation.Uri"
}

internal static WinRTUriRuntimeClassFactory Instance =
new ActivationFactory()._As<WinRTUriRuntimeClassFactory.Vftbl>();
new ActivationFactory().As<WinRTUriRuntimeClassFactory.Vftbl>();
}

public static IObjectReference CreateMarshaler(global::System.Uri value)
Expand Down
Loading