Skip to content

Commit ca6f420

Browse files
Remove ExactSpelling from GeneratedDllImport (dotnet#65343)
* Update conversion code fix to offer multiple fixes for appending each previously probed entry-point suffix when ExactSpelling is false. * Remove ExactSpelling property and move properties that were relying on ExactSpelling = false to use explicit entrypoint names. * Emit ExactSpelling = true for all of our emitted target DllImports. * Fix a few entry points * Add a comment around CharSet.Auto * Update compatibility doc. * Update docs/design/libraries/DllImportGenerator/Compatibility.md Co-authored-by: Elinor Fung <elfung@microsoft.com> Co-authored-by: Elinor Fung <elfung@microsoft.com>
1 parent ee0b460 commit ca6f420

File tree

290 files changed

+710
-436
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

290 files changed

+710
-436
lines changed

docs/design/libraries/DllImportGenerator/Compatibility.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ The built-in system treats `CharSet.None` as `CharSet.Ansi`. The P/Invoke source
2020

2121
[`CallingConvention`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.dllimportattribute.callingconvention) will not be supported for `GeneratedDllImportAttribute`. Users will be required to use the new `UnmanagedCallConvAttribute` attribute instead. This attribute provides support for extensible calling conventions and provides parity with the `UnmanagedCallersOnlyAttribute` attribute and C# function pointer syntax. We will enable our conversion code-fix to automatically convert explicit and known calling convention usage to use the `UnmanagedCallConvAttribute`.
2222

23+
[`ExactSpelling`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.dllimportattribute.exactspelling) will not be supported for `GeneratedDllImportAttribute`. If `ExactSpelling` is used on an existing `DllImport`, the offered code-fix will provide users with additional options for using `A` or `W` suffixed variants depending on the provided `CharSet` so they can explicitly choose which spelling is correct for their scenario.
24+
2325
### Required references
2426

2527
The following framework references are required:

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ public static partial class RuntimeImports
2626
{
2727
private const string RuntimeLibrary = "*";
2828

29-
[GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
29+
[GeneratedDllImport(RuntimeLibrary)]
3030
[SuppressGCTransition]
3131
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
3232
internal static partial ulong RhpGetTickCount64();
3333

34-
[GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
34+
[GeneratedDllImport(RuntimeLibrary)]
3535
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
3636
internal static partial IntPtr RhpGetCurrentThread();
3737

@@ -69,7 +69,7 @@ internal static void RhReRegisterForFinalize(object obj)
6969
private static extern bool _RhReRegisterForFinalize(object obj);
7070

7171
// Wait for all pending finalizers. This must be a p/invoke to avoid starving the GC.
72-
[GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
72+
[GeneratedDllImport(RuntimeLibrary)]
7373
private static partial void RhWaitForPendingFinalizers(int allowReentrantWait);
7474

7575
// Temporary workaround to unblock shareable assembly bring-up - without shared interop,
@@ -82,7 +82,7 @@ internal static void RhWaitForPendingFinalizers(bool allowReentrantWait)
8282
RhWaitForPendingFinalizers(allowReentrantWait ? 1 : 0);
8383
}
8484

85-
[GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
85+
[GeneratedDllImport(RuntimeLibrary)]
8686
internal static partial void RhInitializeFinalizerThread();
8787

8888
// Get maximum GC generation number.
@@ -187,18 +187,18 @@ internal static void RhWaitForPendingFinalizers(bool allowReentrantWait)
187187
[RuntimeImport(RuntimeLibrary, "RhGetTotalAllocatedBytes")]
188188
internal static extern long RhGetTotalAllocatedBytes();
189189

190-
[GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
190+
[GeneratedDllImport(RuntimeLibrary)]
191191
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
192192
internal static partial long RhGetTotalAllocatedBytesPrecise();
193193

194194
[MethodImpl(MethodImplOptions.InternalCall)]
195195
[RuntimeImport(RuntimeLibrary, "RhGetMemoryInfo")]
196196
internal static extern void RhGetMemoryInfo(ref byte info, GCKind kind);
197197

198-
[GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
198+
[GeneratedDllImport(RuntimeLibrary)]
199199
internal static unsafe partial void RhAllocateNewArray(IntPtr pArrayEEType, uint numElements, uint flags, void* pResult);
200200

201-
[GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
201+
[GeneratedDllImport(RuntimeLibrary)]
202202
internal static unsafe partial void RhAllocateNewObject(IntPtr pEEType, uint flags, void* pResult);
203203

204204
[MethodImpl(MethodImplOptions.InternalCall)]
@@ -368,25 +368,25 @@ internal static unsafe void RhUnbox(object? obj, ref byte data, EETypePtr pUnbox
368368
internal static extern object RhMemberwiseClone(object obj);
369369

370370
// Busy spin for the given number of iterations.
371-
[GeneratedDllImport(RuntimeLibrary, EntryPoint = "RhSpinWait", ExactSpelling = true)]
371+
[GeneratedDllImport(RuntimeLibrary, EntryPoint = "RhSpinWait")]
372372
[SuppressGCTransition]
373373
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
374374
internal static partial void RhSpinWait(int iterations);
375375

376376
// Yield the cpu to another thread ready to process, if one is available.
377-
[GeneratedDllImport(RuntimeLibrary, EntryPoint = "RhYield", ExactSpelling = true)]
377+
[GeneratedDllImport(RuntimeLibrary, EntryPoint = "RhYield")]
378378
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
379379
private static partial int _RhYield();
380380
internal static bool RhYield() { return (_RhYield() != 0); }
381381

382-
[GeneratedDllImport(RuntimeLibrary, EntryPoint = "RhFlushProcessWriteBuffers", ExactSpelling = true)]
382+
[GeneratedDllImport(RuntimeLibrary, EntryPoint = "RhFlushProcessWriteBuffers")]
383383
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
384384
internal static partial void RhFlushProcessWriteBuffers();
385385

386386
#if !TARGET_UNIX
387387
// Wait for any object to be signalled, in a way that's compatible with the CLR's behavior in an STA.
388388
// ExactSpelling = 'true' to force MCG to resolve it to default
389-
[GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
389+
[GeneratedDllImport(RuntimeLibrary)]
390390
private static unsafe partial int RhCompatibleReentrantWaitAny(int alertable, int timeout, int count, IntPtr* handles);
391391

392392
// Temporary workaround to unblock shareable assembly bring-up - without shared interop,
@@ -617,7 +617,7 @@ internal static IntPtr RhGetModuleSection(TypeManagerHandle module, ReadyToRunSe
617617
internal static extern void RhCallDescrWorker(IntPtr callDescr);
618618

619619
// For Managed to Native calls
620-
[GeneratedDllImport(RuntimeLibrary, EntryPoint = "RhCallDescrWorker", ExactSpelling = true)]
620+
[GeneratedDllImport(RuntimeLibrary, EntryPoint = "RhCallDescrWorker")]
621621
internal static partial void RhCallDescrWorkerNative(IntPtr callDescr);
622622

623623
// Moves memory from smem to dmem. Size must be a positive value.
@@ -935,14 +935,14 @@ internal struct ConservativelyReportedRegionDesc
935935
[RuntimeImport(RuntimeLibrary, "modff")]
936936
internal static extern unsafe float modff(float x, float* intptr);
937937

938-
[GeneratedDllImport(RuntimeImports.RuntimeLibrary, ExactSpelling = true)]
938+
[GeneratedDllImport(RuntimeImports.RuntimeLibrary)]
939939
internal static unsafe partial void* memmove(byte* dmem, byte* smem, nuint size);
940940

941-
[GeneratedDllImport(RuntimeImports.RuntimeLibrary, ExactSpelling = true)]
941+
[GeneratedDllImport(RuntimeImports.RuntimeLibrary)]
942942
internal static unsafe partial void* memset(byte* mem, int value, nuint size);
943943

944944
#if TARGET_X86 || TARGET_AMD64
945-
[GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
945+
[GeneratedDllImport(RuntimeLibrary)]
946946
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
947947
internal static unsafe partial void RhCpuIdEx(int* cpuInfo, int functionId, int subFunctionId);
948948
#endif

src/coreclr/nativeaot/Test.CoreLib/src/System/Runtime/RuntimeImports.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ internal static unsafe object RhNewObject(EETypePtr pEEType)
8585
internal static unsafe Array RhNewArray(EETypePtr pEEType, int length)
8686
=> RhNewArray(pEEType.ToPointer(), length);
8787

88-
[GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
88+
[GeneratedDllImport(RuntimeLibrary)]
8989
internal static unsafe partial void RhAllocateNewObject(IntPtr pEEType, uint flags, void* pResult);
9090

9191
[MethodImpl(MethodImplOptions.InternalCall)]

src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetTimestamp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ internal static partial class Interop
77
{
88
internal static partial class Sys
99
{
10-
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetTimestamp", ExactSpelling = true)]
10+
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetTimestamp")]
1111
[SuppressGCTransition]
1212
internal static partial ulong GetTimestamp();
1313
}

src/libraries/Common/src/Interop/Windows/Activeds/Interop.ADsOpenObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal static partial class Interop
88
{
99
internal static partial class Activeds
1010
{
11-
[GeneratedDllImport(Interop.Libraries.Activeds, CharSet = CharSet.Unicode, ExactSpelling = true)]
11+
[GeneratedDllImport(Interop.Libraries.Activeds, CharSet = CharSet.Unicode)]
1212
internal static partial int ADsOpenObject(string path, string? userName, string? password, int flags, ref Guid iid, out IntPtr ppObject);
1313
}
1414
}

src/libraries/Common/src/Interop/Windows/Advapi32/Interop.ChangeServiceConfig2.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal static partial class Interop
99
{
1010
internal static partial class Advapi32
1111
{
12-
[GeneratedDllImport(Libraries.Advapi32, EntryPoint = "ChangeServiceConfig2W", ExactSpelling = true, SetLastError = true)]
12+
[GeneratedDllImport(Libraries.Advapi32, EntryPoint = "ChangeServiceConfig2W", SetLastError = true)]
1313
public static partial bool ChangeServiceConfig2(SafeServiceHandle serviceHandle, uint infoLevel, ref SERVICE_DESCRIPTION serviceDesc);
1414

1515
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time

src/libraries/Common/src/Interop/Windows/Advapi32/Interop.ClearEventLog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal static partial class Interop
88
{
99
internal static partial class Advapi32
1010
{
11-
[GeneratedDllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
11+
[GeneratedDllImport(Libraries.Advapi32, EntryPoint = "ClearEventLogW", CharSet = CharSet.Unicode, SetLastError = true)]
1212
public static partial bool ClearEventLog(SafeEventLogReadHandle hEventLog, string lpBackupFileName);
1313
}
1414
}

src/libraries/Common/src/Interop/Windows/Advapi32/Interop.ConvertSdToStringSd.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal static partial class Interop
99
internal static partial class Advapi32
1010
{
1111
[GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "ConvertSecurityDescriptorToStringSecurityDescriptorW",
12-
CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
12+
CharSet = CharSet.Unicode, SetLastError = true)]
1313
internal static partial bool ConvertSdToStringSd(
1414
byte[] securityDescriptor,
1515
/* DWORD */ uint requestedRevision,

src/libraries/Common/src/Interop/Windows/Advapi32/Interop.ConvertSidToStringSid.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal static partial class Interop
88
{
99
internal static partial class Advapi32
1010
{
11-
[GeneratedDllImport(Libraries.Advapi32, EntryPoint = "ConvertSidToStringSidW", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
11+
[GeneratedDllImport(Libraries.Advapi32, EntryPoint = "ConvertSidToStringSidW", CharSet = CharSet.Unicode, SetLastError = true)]
1212
internal static partial BOOL ConvertSidToStringSid(IntPtr sid, out string stringSid);
1313
}
1414
}

src/libraries/Common/src/Interop/Windows/Advapi32/Interop.ConvertStringSdToSd.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal static partial class Interop
99
internal static partial class Advapi32
1010
{
1111
[GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "ConvertStringSecurityDescriptorToSecurityDescriptorW",
12-
CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
12+
CharSet = CharSet.Unicode, SetLastError = true)]
1313
internal static partial bool ConvertStringSdToSd(
1414
string stringSd,
1515
/* DWORD */ uint stringSdRevision,

0 commit comments

Comments
 (0)