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

[DllImportGenerator] Remove unnecessary DLLIMPORTGENERATOR_ENABLED ifdefs #61345

Merged
merged 1 commit into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Libraries.Advapi32, SetLastError = true)]
internal static unsafe partial bool AdjustTokenPrivileges(
#else
[DllImport(Libraries.Advapi32, SetLastError = true)]
internal static extern unsafe bool AdjustTokenPrivileges(
#endif
SafeTokenHandle TokenHandle,
bool DisableAllPrivileges,
TOKEN_PRIVILEGE* NewState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Interop.Libraries.Advapi32, SetLastError = true)]
internal static partial bool CheckTokenMembership(
#else
[DllImport(Interop.Libraries.Advapi32, SetLastError = true)]
internal static extern bool CheckTokenMembership(
#endif
SafeAccessTokenHandle TokenHandle,
byte[] SidToCheck,
ref bool IsMember);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "ConvertStringSidToSidW", CharSet = CharSet.Unicode, SetLastError = true)]
[GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "ConvertStringSidToSidW", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
Copy link
Member

Choose a reason for hiding this comment

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

Was the addition of ExactSpelling here just an opportunistic addition? Should we be using it in other places we're not currently

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, this was just opportunistic - I just noticed that already had the W suffix while doing this.

internal static partial int ConvertStringSidToSid(
#else
[DllImport(Interop.Libraries.Advapi32, EntryPoint = "ConvertStringSidToSidW", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern int ConvertStringSidToSid(
#endif
string stringSid,
out IntPtr ByteArray);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "CreateWellKnownSid", CharSet = CharSet.Unicode, SetLastError = true)]
[GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "CreateWellKnownSid", SetLastError = true)]
internal static partial int CreateWellKnownSid(
#else
[DllImport(Interop.Libraries.Advapi32, EntryPoint = "CreateWellKnownSid", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern int CreateWellKnownSid(
#endif
int sidType,
byte[]? domainSid,
byte[] resultSid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Interop.Libraries.Advapi32, SetLastError = true)]
internal static partial bool DuplicateTokenEx(
#else
[DllImport(Interop.Libraries.Advapi32, SetLastError = true)]
internal static extern bool DuplicateTokenEx(
#endif
SafeAccessTokenHandle hExistingToken,
uint dwDesiredAccess,
IntPtr lpTokenAttributes, // LPSECURITY_ATTRIBUTES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Interop.Libraries.Advapi32, SetLastError = true)]
internal static partial bool DuplicateTokenEx(
#else
[DllImport(Interop.Libraries.Advapi32, SetLastError = true)]
internal static extern bool DuplicateTokenEx(
#endif
SafeTokenHandle ExistingTokenHandle,
TokenAccessLevels DesiredAccess,
IntPtr TokenAttributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "GetSecurityInfo", ExactSpelling = true)]
internal static unsafe partial uint GetSecurityInfoByHandle(
#else
[DllImport(Interop.Libraries.Advapi32, EntryPoint = "GetSecurityInfo", ExactSpelling = true)]
internal static unsafe extern /*DWORD*/ uint GetSecurityInfoByHandle(
#endif
SafeHandle handle,
/*DWORD*/ uint objectType,
/*DWORD*/ uint securityInformation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "GetNamedSecurityInfoW", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
internal static partial uint GetSecurityInfoByName(
#else
[DllImport(Interop.Libraries.Advapi32, EntryPoint = "GetNamedSecurityInfoW", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
internal static extern /*DWORD*/ uint GetSecurityInfoByName(
#endif
string name,
/*DWORD*/ uint objectType,
/*DWORD*/ uint securityInformation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "GetWindowsAccountDomainSid", CharSet = CharSet.Unicode, SetLastError = true)]
[GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "GetWindowsAccountDomainSid", SetLastError = true)]
internal static partial int GetWindowsAccountDomainSid(
#else
[DllImport(Interop.Libraries.Advapi32, EntryPoint = "GetWindowsAccountDomainSid", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern int GetWindowsAccountDomainSid(
Copy link
Member

Choose a reason for hiding this comment

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

Do we have an analyzer that warns when specifying a CharSet and it's a nop? I assume that's how you spotted these? But if that's the case, why wasn't it previously firing for this #if case? Or is it just a suggestion right now that doesn't trigger warn-as-error build failures?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't. I just did a quick scan through the changes I had and manually updated a few things.

#endif
byte[] sid,
byte[] resultSid,
ref uint resultSidLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Interop.Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
[GeneratedDllImport(Interop.Libraries.Advapi32, SetLastError = true)]
internal static partial bool ImpersonateLoggedOnUser(SafeAccessTokenHandle userToken);
#else
[DllImport(Interop.Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern bool ImpersonateLoggedOnUser(SafeAccessTokenHandle userToken);
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "EqualDomainSid", CharSet = CharSet.Unicode, SetLastError = true)]
[GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "EqualDomainSid", SetLastError = true)]
internal static partial int IsEqualDomainSid(
#else
[DllImport(Interop.Libraries.Advapi32, EntryPoint = "EqualDomainSid", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern int IsEqualDomainSid(
#endif
byte[] sid1,
byte[] sid2,
out bool result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "IsWellKnownSid", CharSet = CharSet.Unicode, SetLastError = true)]
[GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "IsWellKnownSid", SetLastError = true)]
internal static partial int IsWellKnownSid(
#else
[DllImport(Interop.Libraries.Advapi32, EntryPoint = "IsWellKnownSid", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern int IsWellKnownSid(
#endif
byte[] sid,
int type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Interop.Libraries.Advapi32, SetLastError = true)]
internal static partial int LsaClose(IntPtr handle);
#else
[DllImport(Interop.Libraries.Advapi32, SetLastError = true)]
internal static extern int LsaClose(IntPtr handle);
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Interop.Libraries.Advapi32, SetLastError = true)]
internal static partial int LsaFreeMemory(IntPtr handle);
#else
[DllImport(Interop.Libraries.Advapi32, SetLastError = true)]
internal static extern int LsaFreeMemory(IntPtr handle);
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "LsaLookupSids", CharSet = CharSet.Unicode, SetLastError = true)]
[GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "LsaLookupSids", SetLastError = true)]
internal static partial uint LsaLookupSids(
#else
[DllImport(Interop.Libraries.Advapi32, EntryPoint = "LsaLookupSids", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern uint LsaLookupSids(
#endif
SafeLsaPolicyHandle handle,
int count,
IntPtr[] sids,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "LsaOpenPolicy", CharSet = CharSet.Unicode, SetLastError = true)]
[GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "LsaOpenPolicy", SetLastError = true)]
private static partial uint LsaOpenPolicy(
#else
[DllImport(Interop.Libraries.Advapi32, EntryPoint = "LsaOpenPolicy", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern uint LsaOpenPolicy(
#endif
ref UNICODE_STRING SystemName,
ref OBJECT_ATTRIBUTES ObjectAttributes,
int AccessMask,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
[GeneratedDllImport(Libraries.Advapi32, SetLastError = true)]
internal static partial bool OpenProcessToken(
#else
[DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern bool OpenProcessToken(
#endif
IntPtr ProcessToken,
TokenAccessLevels DesiredAccess,
out SafeTokenHandle TokenHandle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Interop.Libraries.Advapi32, SetLastError = true)]
private static partial bool OpenThreadToken(
#else
[DllImport(Interop.Libraries.Advapi32, SetLastError = true)]
private static extern bool OpenThreadToken(
#endif
IntPtr ThreadHandle,
TokenAccessLevels dwDesiredAccess,
bool bOpenAsSelf,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Interop.Libraries.Advapi32, SetLastError = true)]
internal static partial bool OpenThreadToken(
#else
[DllImport(Interop.Libraries.Advapi32, SetLastError = true)]
internal static extern bool OpenThreadToken(
#endif
IntPtr ThreadHandle,
TokenAccessLevels dwDesiredAccess,
bool bOpenAsSelf,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Interop.Libraries.Advapi32, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
[GeneratedDllImport(Interop.Libraries.Advapi32, ExactSpelling = true, SetLastError = true)]
internal static partial bool RevertToSelf();
#else
[DllImport(Interop.Libraries.Advapi32, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
internal static extern bool RevertToSelf();
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Libraries.Advapi32, SetLastError = true)]
internal static partial bool SetThreadToken(
#else
[DllImport(Libraries.Advapi32, SetLastError = true)]
internal static extern bool SetThreadToken(
#endif
IntPtr ThreadHandle,
SafeTokenHandle? hToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@ internal static partial class Kernel32
/// <summary>
/// WARNING: This method does not implicitly handle long paths. Use CopyFileEx.
/// </summary>
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Libraries.Kernel32, EntryPoint = "CopyFileExW", CharSet = CharSet.Unicode, SetLastError = true)]
[GeneratedDllImport(Libraries.Kernel32, EntryPoint = "CopyFileExW", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
private static partial bool CopyFileExPrivate(
#else
[DllImport(Libraries.Kernel32, EntryPoint = "CopyFileExW", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern bool CopyFileExPrivate(
#endif
string src,
string dst,
IntPtr progressRoutine,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@ internal static partial class Kernel32
/// <summary>
/// WARNING: This method does not implicitly handle long paths. Use CreateDirectory.
/// </summary>
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Libraries.Kernel32, EntryPoint = "CreateDirectoryW", CharSet = CharSet.Unicode, SetLastError = true)]
[GeneratedDllImport(Libraries.Kernel32, EntryPoint = "CreateDirectoryW", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
private static partial bool CreateDirectoryPrivate(
#else
[DllImport(Libraries.Kernel32, EntryPoint = "CreateDirectoryW", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern bool CreateDirectoryPrivate(
#endif
string path,
ref SECURITY_ATTRIBUTES lpSecurityAttributes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@ internal static partial class Kernel32
/// <summary>
/// WARNING: This method does not implicitly handle long paths. Use CreateFile.
/// </summary>
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Libraries.Kernel32, EntryPoint = "CreateFileW", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
private static unsafe partial IntPtr CreateFilePrivate_IntPtr(
#else
[DllImport(Libraries.Kernel32, EntryPoint = "CreateFileW", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
private static unsafe extern IntPtr CreateFilePrivate_IntPtr(
#endif
string lpFileName,
int dwDesiredAccess,
FileShare dwShareMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@ internal static partial class Kernel32
/// <summary>
/// WARNING: This method does not implicitly handle long paths. Use DeleteFile.
/// </summary>
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Libraries.Kernel32, EntryPoint = "DeleteFileW", CharSet = CharSet.Unicode, SetLastError = true)]
[GeneratedDllImport(Libraries.Kernel32, EntryPoint = "DeleteFileW", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
private static partial bool DeleteFilePrivate(string path);
#else
[DllImport(Libraries.Kernel32, EntryPoint = "DeleteFileW", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern bool DeleteFilePrivate(string path);
#endif

internal static bool DeleteFile(string path)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@ internal static partial class Kernel32
/// <summary>
/// WARNING: This method does not implicitly handle long paths. Use DeleteVolumeMountPoint.
/// </summary>
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Libraries.Kernel32, EntryPoint = "DeleteVolumeMountPointW", CharSet = CharSet.Unicode, SetLastError = true)]
[GeneratedDllImport(Libraries.Kernel32, EntryPoint = "DeleteVolumeMountPointW", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
internal static partial bool DeleteVolumeMountPointPrivate(string mountPoint);
#else
[DllImport(Libraries.Kernel32, EntryPoint = "DeleteVolumeMountPointW", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern bool DeleteVolumeMountPointPrivate(string mountPoint);
#endif

internal static bool DeleteVolumeMountPoint(string mountPoint)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ internal static partial class Interop
{
internal static partial class Kernel32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Libraries.Kernel32, SetLastError = true)]
internal static partial bool DuplicateHandle(
#else
[DllImport(Libraries.Kernel32, SetLastError = true)]
internal static extern bool DuplicateHandle(
#endif
IntPtr hSourceProcessHandle,
IntPtr hSourceHandle,
IntPtr hTargetProcessHandle,
Expand Down
Loading