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

Update SPCL to use GeneratedDllImport where possible. #61640

Merged
merged 3 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 10 additions & 10 deletions src/libraries/Common/src/Interop/Interop.Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ internal static partial class Interop
{
internal static partial class Globalization
{
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetCalendars")]
internal static extern int GetCalendars(string localeName, CalendarId[] calendars, int calendarsCapacity);
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetCalendars", CharSet = CharSet.Unicode)]
internal static partial int GetCalendars(string localeName, CalendarId[] calendars, int calendarsCapacity);

[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetCalendarInfo")]
internal static extern unsafe ResultCode GetCalendarInfo(string localeName, CalendarId calendarId, CalendarDataType calendarDataType, char* result, int resultCapacity);
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetCalendarInfo", CharSet = CharSet.Unicode)]
internal static unsafe partial ResultCode GetCalendarInfo(string localeName, CalendarId calendarId, CalendarDataType calendarDataType, char* result, int resultCapacity);

[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EnumCalendarInfo")]
internal static extern unsafe bool EnumCalendarInfo(delegate* unmanaged<char*, IntPtr, void> callback, string localeName, CalendarId calendarId, CalendarDataType calendarDataType, IntPtr context);
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_EnumCalendarInfo", CharSet = CharSet.Unicode)]
internal static unsafe partial bool EnumCalendarInfo(delegate* unmanaged<char*, IntPtr, void> callback, string localeName, CalendarId calendarId, CalendarDataType calendarDataType, IntPtr context);

[DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLatestJapaneseEra")]
internal static extern int GetLatestJapaneseEra();
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLatestJapaneseEra")]
internal static partial int GetLatestJapaneseEra();

[DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetJapaneseEraStartDate")]
internal static extern bool GetJapaneseEraStartDate(int era, out int startYear, out int startMonth, out int startDay);
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetJapaneseEraStartDate")]
internal static partial bool GetJapaneseEraStartDate(int era, out int startYear, out int startMonth, out int startDay);
}
}
16 changes: 8 additions & 8 deletions src/libraries/Common/src/Interop/Interop.Casing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ internal static partial class Interop
{
internal static partial class Globalization
{
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ChangeCase")]
internal static extern unsafe void ChangeCase(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper);
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_ChangeCase", CharSet = CharSet.Unicode)]
internal static unsafe partial void ChangeCase(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper);

[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ChangeCaseInvariant")]
internal static extern unsafe void ChangeCaseInvariant(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper);
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_ChangeCaseInvariant", CharSet = CharSet.Unicode)]
internal static unsafe partial void ChangeCaseInvariant(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper);

[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ChangeCaseTurkish")]
internal static extern unsafe void ChangeCaseTurkish(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper);
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_ChangeCaseTurkish", CharSet = CharSet.Unicode)]
internal static unsafe partial void ChangeCaseTurkish(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper);

[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_InitOrdinalCasingPage")]
internal static extern unsafe void InitOrdinalCasingPage(int pageNumber, char* pTarget);
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_InitOrdinalCasingPage", CharSet = CharSet.Unicode)]
internal static unsafe partial void InitOrdinalCasingPage(int pageNumber, char* pTarget);
}
}
44 changes: 22 additions & 22 deletions src/libraries/Common/src/Interop/Interop.Collation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,41 @@ internal static partial class Interop
{
internal static partial class Globalization
{
[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Ansi, EntryPoint = "GlobalizationNative_GetSortHandle")]
internal static extern unsafe ResultCode GetSortHandle(string localeName, out IntPtr sortHandle);
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetSortHandle", CharSet = CharSet.Ansi)]
internal static unsafe partial ResultCode GetSortHandle(string localeName, out IntPtr sortHandle);

[DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_CloseSortHandle")]
internal static extern void CloseSortHandle(IntPtr handle);
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_CloseSortHandle")]
internal static partial void CloseSortHandle(IntPtr handle);

[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_CompareString")]
internal static extern unsafe int CompareString(IntPtr sortHandle, char* lpStr1, int cwStr1Len, char* lpStr2, int cwStr2Len, CompareOptions options);
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_CompareString", CharSet = CharSet.Unicode)]
internal static unsafe partial int CompareString(IntPtr sortHandle, char* lpStr1, int cwStr1Len, char* lpStr2, int cwStr2Len, CompareOptions options);

[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IndexOf")]
internal static extern unsafe int IndexOf(IntPtr sortHandle, char* target, int cwTargetLength, char* pSource, int cwSourceLength, CompareOptions options, int* matchLengthPtr);
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_IndexOf", CharSet = CharSet.Unicode)]
internal static unsafe partial int IndexOf(IntPtr sortHandle, char* target, int cwTargetLength, char* pSource, int cwSourceLength, CompareOptions options, int* matchLengthPtr);

[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_LastIndexOf")]
internal static extern unsafe int LastIndexOf(IntPtr sortHandle, char* target, int cwTargetLength, char* pSource, int cwSourceLength, CompareOptions options, int* matchLengthPtr);
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_LastIndexOf", CharSet = CharSet.Unicode)]
internal static unsafe partial int LastIndexOf(IntPtr sortHandle, char* target, int cwTargetLength, char* pSource, int cwSourceLength, CompareOptions options, int* matchLengthPtr);

[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_StartsWith")]
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_StartsWith", CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern unsafe bool StartsWith(IntPtr sortHandle, char* target, int cwTargetLength, char* source, int cwSourceLength, CompareOptions options, int* matchedLength);
internal static unsafe partial bool StartsWith(IntPtr sortHandle, char* target, int cwTargetLength, char* source, int cwSourceLength, CompareOptions options, int* matchedLength);

[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EndsWith")]
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_EndsWith", CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern unsafe bool EndsWith(IntPtr sortHandle, char* target, int cwTargetLength, char* source, int cwSourceLength, CompareOptions options, int* matchedLength);
internal static unsafe partial bool EndsWith(IntPtr sortHandle, char* target, int cwTargetLength, char* source, int cwSourceLength, CompareOptions options, int* matchedLength);

[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_StartsWith")]
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_StartsWith", CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool StartsWith(IntPtr sortHandle, string target, int cwTargetLength, string source, int cwSourceLength, CompareOptions options);
internal static partial bool StartsWith(IntPtr sortHandle, string target, int cwTargetLength, string source, int cwSourceLength, CompareOptions options);

[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EndsWith")]
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_EndsWith", CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool EndsWith(IntPtr sortHandle, string target, int cwTargetLength, string source, int cwSourceLength, CompareOptions options);
internal static partial bool EndsWith(IntPtr sortHandle, string target, int cwTargetLength, string source, int cwSourceLength, CompareOptions options);

[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetSortKey")]
internal static extern unsafe int GetSortKey(IntPtr sortHandle, char* str, int strLength, byte* sortKey, int sortKeyLength, CompareOptions options);
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetSortKey", CharSet = CharSet.Unicode)]
internal static unsafe partial int GetSortKey(IntPtr sortHandle, char* str, int strLength, byte* sortKey, int sortKeyLength, CompareOptions options);

[DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetSortVersion")]
internal static extern int GetSortVersion(IntPtr sortHandle);
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetSortVersion")]
internal static partial int GetSortVersion(IntPtr sortHandle);
}
}
14 changes: 9 additions & 5 deletions src/libraries/Common/src/Interop/Interop.HostPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

internal static partial class Interop
{
internal static class HostPolicy
internal static partial class HostPolicy
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Auto)]
internal delegate void corehost_resolve_component_dependencies_result_fn(string assemblyPaths,
Expand All @@ -15,11 +15,15 @@ internal delegate void corehost_resolve_component_dependencies_result_fn(string
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Auto)]
internal delegate void corehost_error_writer_fn(string message);

[DllImport(Libraries.HostPolicy, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)]
internal static extern int corehost_resolve_component_dependencies(string componentMainAssemblyPath,
#pragma warning disable CS3016 // Arrays as attribute arguments is not CLS-compliant
[GeneratedDllImport(Libraries.HostPolicy, CharSet = CharSet.Auto)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
internal static partial int corehost_resolve_component_dependencies(string componentMainAssemblyPath,
corehost_resolve_component_dependencies_result_fn result);

[DllImport(Libraries.HostPolicy, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)]
internal static extern IntPtr corehost_set_error_writer(IntPtr errorWriter);
[GeneratedDllImport(Libraries.HostPolicy, CharSet = CharSet.Auto)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
internal static partial IntPtr corehost_set_error_writer(IntPtr errorWriter);
#pragma warning restore CS3016 // Arrays as attribute arguments is not CLS-compliant
}
}
12 changes: 6 additions & 6 deletions src/libraries/Common/src/Interop/Interop.ICU.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ internal static partial class Interop
{
internal static partial class Globalization
{
[DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_LoadICU")]
internal static extern int LoadICU();
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_LoadICU")]
internal static partial int LoadICU();

internal static void InitICUFunctions(IntPtr icuuc, IntPtr icuin, ReadOnlySpan<char> version, ReadOnlySpan<char> suffix)
{
Expand All @@ -20,10 +20,10 @@ internal static void InitICUFunctions(IntPtr icuuc, IntPtr icuin, ReadOnlySpan<c
InitICUFunctions(icuuc, icuin, version.ToString(), suffix.Length > 0 ? suffix.ToString() : null);
}

[DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_InitICUFunctions")]
internal static extern void InitICUFunctions(IntPtr icuuc, IntPtr icuin, string version, string? suffix);
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_InitICUFunctions", CharSet = CharSet.Ansi)]
internal static partial void InitICUFunctions(IntPtr icuuc, IntPtr icuin, string version, string? suffix);

[DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetICUVersion")]
internal static extern int GetICUVersion();
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetICUVersion")]
internal static partial int GetICUVersion();
}
}
8 changes: 4 additions & 4 deletions src/libraries/Common/src/Interop/Interop.Idna.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ internal static partial class Globalization
internal const int AllowUnassigned = 0x1;
internal const int UseStd3AsciiRules = 0x2;

[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ToAscii")]
internal static extern unsafe int ToAscii(uint flags, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity);
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_ToAscii", CharSet = CharSet.Unicode)]
internal static unsafe partial int ToAscii(uint flags, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity);

[DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ToUnicode")]
internal static extern unsafe int ToUnicode(uint flags, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity);
[GeneratedDllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_ToUnicode", CharSet = CharSet.Unicode)]
internal static unsafe partial int ToUnicode(uint flags, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity);
}
}
Loading