From dc38a21a614fba3d89c3212f483f5ff09e6aa710 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 1 May 2024 22:47:32 -0700 Subject: [PATCH] Remove 'Marshal.StructureToPtr' calls --- src/WinRT.Runtime/IInspectable.cs | 2 +- src/WinRT.Runtime/Projections/EventHandler.cs | 2 +- .../Projections/ICommand.net5.cs | 2 +- .../ICustomPropertyProvider.net5.cs | 2 +- .../INotifyCollectionChanged.net5.cs | 2 +- .../INotifyPropertyChanged.net5.cs | 2 +- .../Projections/IPropertyValue.net5.cs | 2 +- src/WinRT.Runtime/Projections/IStringable.cs | 2 +- .../NotifyCollectionChangedEventHandler.cs | 2 +- src/WinRT.Runtime/Projections/Nullable.cs | 40 +++++++++---------- .../PropertyChangedEventHandler.cs | 2 +- 11 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/WinRT.Runtime/IInspectable.cs b/src/WinRT.Runtime/IInspectable.cs index 2603bdedc..5905a791e 100644 --- a/src/WinRT.Runtime/IInspectable.cs +++ b/src/WinRT.Runtime/IInspectable.cs @@ -72,7 +72,7 @@ static Vftbl() #endif }; AbiToProjectionVftablePtr = Marshal.AllocHGlobal(sizeof(Vftbl)); - Marshal.StructureToPtr(AbiToProjectionVftable, AbiToProjectionVftablePtr, false); + *(Vftbl*)AbiToProjectionVftablePtr = AbiToProjectionVftable; } #if NET diff --git a/src/WinRT.Runtime/Projections/EventHandler.cs b/src/WinRT.Runtime/Projections/EventHandler.cs index 9c47a9f29..dbaa1ba3c 100644 --- a/src/WinRT.Runtime/Projections/EventHandler.cs +++ b/src/WinRT.Runtime/Projections/EventHandler.cs @@ -321,7 +321,7 @@ static unsafe EventHandler() #endif }; var nativeVftbl = ComWrappersSupport.AllocateVtableMemory(typeof(EventHandler), sizeof(global::WinRT.Interop.IDelegateVftbl)); - Marshal.StructureToPtr(AbiToProjectionVftable, nativeVftbl, false); + *(global::WinRT.Interop.IDelegateVftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = nativeVftbl; } diff --git a/src/WinRT.Runtime/Projections/ICommand.net5.cs b/src/WinRT.Runtime/Projections/ICommand.net5.cs index c984d6588..140e96cd1 100644 --- a/src/WinRT.Runtime/Projections/ICommand.net5.cs +++ b/src/WinRT.Runtime/Projections/ICommand.net5.cs @@ -110,7 +110,7 @@ static unsafe Vftbl() }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 4); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } diff --git a/src/WinRT.Runtime/Projections/ICustomPropertyProvider.net5.cs b/src/WinRT.Runtime/Projections/ICustomPropertyProvider.net5.cs index 3cd29f8b7..c84da8318 100644 --- a/src/WinRT.Runtime/Projections/ICustomPropertyProvider.net5.cs +++ b/src/WinRT.Runtime/Projections/ICustomPropertyProvider.net5.cs @@ -283,7 +283,7 @@ static unsafe ManagedCustomPropertyProviderVftbl() }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(ManagedCustomPropertyProviderVftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 4); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(ManagedCustomPropertyProviderVftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } diff --git a/src/WinRT.Runtime/Projections/INotifyCollectionChanged.net5.cs b/src/WinRT.Runtime/Projections/INotifyCollectionChanged.net5.cs index 2f6bf6ebe..f75aa91f4 100644 --- a/src/WinRT.Runtime/Projections/INotifyCollectionChanged.net5.cs +++ b/src/WinRT.Runtime/Projections/INotifyCollectionChanged.net5.cs @@ -71,7 +71,7 @@ static unsafe Vftbl() }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 2); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } diff --git a/src/WinRT.Runtime/Projections/INotifyPropertyChanged.net5.cs b/src/WinRT.Runtime/Projections/INotifyPropertyChanged.net5.cs index 229a84bc6..ebe8cabee 100644 --- a/src/WinRT.Runtime/Projections/INotifyPropertyChanged.net5.cs +++ b/src/WinRT.Runtime/Projections/INotifyPropertyChanged.net5.cs @@ -70,7 +70,7 @@ static unsafe Vftbl() }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 2); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } private volatile static global::System.Runtime.CompilerServices.ConditionalWeakTable> _PropertyChanged_TokenTablesLazy = null; diff --git a/src/WinRT.Runtime/Projections/IPropertyValue.net5.cs b/src/WinRT.Runtime/Projections/IPropertyValue.net5.cs index 3d735c1e7..594d35cce 100644 --- a/src/WinRT.Runtime/Projections/IPropertyValue.net5.cs +++ b/src/WinRT.Runtime/Projections/IPropertyValue.net5.cs @@ -159,7 +159,7 @@ static unsafe ManagedIPropertyValueImpl() }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(ManagedIPropertyValueImpl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 39); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(IPropertyValue.Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } diff --git a/src/WinRT.Runtime/Projections/IStringable.cs b/src/WinRT.Runtime/Projections/IStringable.cs index 3d7848d67..0fe19f833 100644 --- a/src/WinRT.Runtime/Projections/IStringable.cs +++ b/src/WinRT.Runtime/Projections/IStringable.cs @@ -37,7 +37,7 @@ static unsafe ManagedIStringableVftbl() #endif }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(ManagedIStringableVftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 1); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(ManagedIStringableVftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } diff --git a/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventHandler.cs b/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventHandler.cs index c2984aa4a..4bc6fdbcc 100644 --- a/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventHandler.cs +++ b/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventHandler.cs @@ -39,7 +39,7 @@ static unsafe NotifyCollectionChangedEventHandler() #endif }; var nativeVftbl = ComWrappersSupport.AllocateVtableMemory(typeof(NotifyCollectionChangedEventHandler), sizeof(global::WinRT.Interop.IDelegateVftbl)); - Marshal.StructureToPtr(AbiToProjectionVftable, nativeVftbl, false); + *(global::WinRT.Interop.IDelegateVftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = nativeVftbl; } diff --git a/src/WinRT.Runtime/Projections/Nullable.cs b/src/WinRT.Runtime/Projections/Nullable.cs index b4b0d6f99..000a214f0 100644 --- a/src/WinRT.Runtime/Projections/Nullable.cs +++ b/src/WinRT.Runtime/Projections/Nullable.cs @@ -30,7 +30,7 @@ static unsafe BoxedValueIReferenceImpl() get_Value_0 = GetValueDelegateForAbi(out IntPtr nativePtr) }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(BoxedValueIReferenceImpl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 1); - Marshal.StructureToPtr(AbiToProjectionVftable.IInspectableVftbl, (IntPtr)nativeVftbl, false); + *(global::WinRT.IInspectable.Vftbl*)nativeVftbl = AbiToProjectionVftable.IInspectableVftbl; nativeVftbl[6] = nativePtr; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; @@ -529,7 +529,7 @@ static Vftbl() #endif }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 1); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } @@ -590,7 +590,7 @@ static Vftbl() #endif }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 1); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } @@ -668,7 +668,7 @@ static Vftbl() #endif }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 1); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } @@ -729,7 +729,7 @@ static Vftbl() #endif }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 1); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } @@ -790,7 +790,7 @@ static Vftbl() #endif }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 1); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } @@ -851,7 +851,7 @@ static Vftbl() #endif }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 1); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } @@ -912,7 +912,7 @@ static Vftbl() #endif }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 1); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } @@ -973,7 +973,7 @@ static Vftbl() #endif }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 1); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } @@ -1034,7 +1034,7 @@ static Vftbl() #endif }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 1); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } @@ -1095,7 +1095,7 @@ static Vftbl() #endif }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 1); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } @@ -1156,7 +1156,7 @@ static Vftbl() #endif }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 1); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } @@ -1217,7 +1217,7 @@ static Vftbl() #endif }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 1); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } @@ -1278,7 +1278,7 @@ static Vftbl() #endif }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 1); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } @@ -1339,7 +1339,7 @@ static Vftbl() #endif }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 1); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } @@ -1400,7 +1400,7 @@ static Vftbl() #endif }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 1); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } @@ -1478,7 +1478,7 @@ static Vftbl() #endif }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 1); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } @@ -1556,7 +1556,7 @@ static Vftbl() #endif }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 1); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } @@ -1617,7 +1617,7 @@ static Vftbl() #endif }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 1); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } @@ -1695,7 +1695,7 @@ static Vftbl() #endif }; var nativeVftbl = (IntPtr*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(global::WinRT.IInspectable.Vftbl) + sizeof(IntPtr) * 1); - Marshal.StructureToPtr(AbiToProjectionVftable, (IntPtr)nativeVftbl, false); + *(Vftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = (IntPtr)nativeVftbl; } diff --git a/src/WinRT.Runtime/Projections/PropertyChangedEventHandler.cs b/src/WinRT.Runtime/Projections/PropertyChangedEventHandler.cs index 864ca1eec..2dcaacc75 100644 --- a/src/WinRT.Runtime/Projections/PropertyChangedEventHandler.cs +++ b/src/WinRT.Runtime/Projections/PropertyChangedEventHandler.cs @@ -38,7 +38,7 @@ static unsafe PropertyChangedEventHandler() #endif }; var nativeVftbl = ComWrappersSupport.AllocateVtableMemory(typeof(PropertyChangedEventHandler), sizeof(global::WinRT.Interop.IDelegateVftbl)); - Marshal.StructureToPtr(AbiToProjectionVftable, nativeVftbl, false); + *(IDelegateVftbl*)nativeVftbl = AbiToProjectionVftable; AbiToProjectionVftablePtr = nativeVftbl; }