From 3681a849166d6d09105356b6047f5fc0fd07035c Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Fri, 19 Jan 2024 16:06:03 +0100 Subject: [PATCH 01/30] Create separate lib System.HybridGlobalization.Native --- .../common/evaluate-default-paths.yml | 2 + src/coreclr/vm/pinvokeoverride.cpp | 6 + .../Microsoft.DotNet.ILCompiler.pkgproj | 1 + .../Directory.Build.props | 5 + .../Globalization/GlobalizationMode.Unix.cs | 6 +- .../System/Globalization/GlobalizationMode.cs | 5 +- src/mono/mono/metadata/native-library.c | 54 +- src/mono/mono/mini/CMakeLists.txt | 142 +-- .../corehost/apphost/static/CMakeLists.txt | 1 + src/native/libs/CMakeLists.txt | 4 + .../CMakeLists.txt | 44 +- .../System.Globalization.Native/entrypoints.c | 25 +- .../pal_icushim_internal.h | 39 +- .../System.Globalization.Native/pal_locale.m | 800 ----------------- .../CMakeLists.txt | 203 +++++ .../config.h.in | 5 + .../configure.cmake | 36 + .../entrypoints.c | 92 ++ .../pal_calendarData.h | 119 +++ .../pal_calendarData.m | 0 .../pal_casing.h | 40 + .../pal_casing.m | 0 .../pal_collation.h | 110 +++ .../pal_collation.m | 0 .../pal_common.c | 21 + .../pal_errors.h | 17 + .../pal_errors_internal.h | 30 + .../pal_icushim.c | 575 ++++++++++++ .../pal_icushim.h | 16 + .../pal_icushim_internal.h | 386 ++++++++ .../pal_icushim_internal_android.h | 542 +++++++++++ .../pal_icushim_static.c | 253 ++++++ .../pal_idna.c | 99 +++ .../pal_idna.h | 20 + .../pal_locale.h | 404 +++++++++ .../pal_locale.m | 839 ++++++++++++++++++ .../pal_localeNumberData.h | 54 ++ .../pal_localeStringData.h | 54 ++ .../pal_locale_internal.h | 63 ++ .../pal_normalization.h | 39 + .../pal_normalization.m | 1 - .../pal_placeholders.c | 276 ++++++ .../pal_timeZoneInfo.h | 29 + .../pal_timeZoneInfo.m | 0 src/native/libs/build-native.proj | 4 +- src/tasks/AppleAppBuilder/Templates/runtime.m | 4 + 46 files changed, 4464 insertions(+), 1001 deletions(-) create mode 100644 src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt create mode 100644 src/native/libs/System.HybridGlobalization.Native/config.h.in create mode 100644 src/native/libs/System.HybridGlobalization.Native/configure.cmake create mode 100644 src/native/libs/System.HybridGlobalization.Native/entrypoints.c create mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_calendarData.h rename src/native/libs/{System.Globalization.Native => System.HybridGlobalization.Native}/pal_calendarData.m (100%) create mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_casing.h rename src/native/libs/{System.Globalization.Native => System.HybridGlobalization.Native}/pal_casing.m (100%) create mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_collation.h rename src/native/libs/{System.Globalization.Native => System.HybridGlobalization.Native}/pal_collation.m (100%) create mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_common.c create mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_errors.h create mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_errors_internal.h create mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_icushim.c create mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_icushim.h create mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_icushim_internal.h create mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_icushim_internal_android.h create mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_icushim_static.c create mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_idna.c create mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_idna.h create mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_locale.h create mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_locale.m create mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_localeNumberData.h create mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_localeStringData.h create mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_locale_internal.h create mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_normalization.h rename src/native/libs/{System.Globalization.Native => System.HybridGlobalization.Native}/pal_normalization.m (99%) create mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_placeholders.c create mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_timeZoneInfo.h rename src/native/libs/{System.Globalization.Native => System.HybridGlobalization.Native}/pal_timeZoneInfo.m (100%) diff --git a/eng/pipelines/common/evaluate-default-paths.yml b/eng/pipelines/common/evaluate-default-paths.yml index 42c7e53735b0b..9de3c93f71ee3 100644 --- a/eng/pipelines/common/evaluate-default-paths.yml +++ b/eng/pipelines/common/evaluate-default-paths.yml @@ -86,6 +86,7 @@ jobs: - src/libraries/System.Private.CoreLib/* - src/native/libs/Common/* - src/native/libs/System.Globalization.Native/* + - src/native/libs/System.HybridGlobalization.Native/* - src/native/libs/System.IO.Compression.Native/* exclude: - eng/Version.Details.xml @@ -109,6 +110,7 @@ jobs: - src/libraries/System.Private.CoreLib/* - src/native/libs/Common/* - src/native/libs/System.Globalization.Native/* + - src/native/libs/System.HybridGlobalization.Native/* - src/native/libs/System.IO.Compression.Native/* exclude: - ${{ parameters._const_paths._wasm_specific_only }} diff --git a/src/coreclr/vm/pinvokeoverride.cpp b/src/coreclr/vm/pinvokeoverride.cpp index d8f1d0972a399..1b65b5b8d7c9f 100644 --- a/src/coreclr/vm/pinvokeoverride.cpp +++ b/src/coreclr/vm/pinvokeoverride.cpp @@ -22,6 +22,7 @@ namespace #define GLOBALIZATION_DLL_NAME "System.Globalization.Native" #else #define GLOBALIZATION_DLL_NAME "libSystem.Globalization.Native" +#define HYBRID_GLOBALIZATION_DLL_NAME "libSystem.HybridGlobalization.Native" #endif // here we handle PInvokes whose implementation is always statically linked (even in .so/.dll case) @@ -31,6 +32,11 @@ static const void* DefaultResolveDllImport(const char* libraryName, const char* { return GlobalizationResolveDllImport(entrypointName); } + // Add hybrid globalization here + if (strcmp(libraryName, HYBRID_GLOBALIZATION_DLL_NAME) == 0) + { + return HybridGlobalizationResolveDllImport(entrypointName); + } return nullptr; } diff --git a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj index 3995419fc9098..5612e5b3f3cc1 100644 --- a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj +++ b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj @@ -18,6 +18,7 @@ + diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props index 9865d487c7101..a8ec5b2382cdd 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props @@ -35,6 +35,8 @@ <_pastShimFiles Include="System.Globalization.Native.dylib" /> <_pastShimFiles Include="System.Globalization.Native.so" /> + <_pastShimFiles Include="System.HybridGlobalization.Native.dylib" /> + <_pastShimFiles Include="System.HybridGlobalization.Native.so" /> <_pastShimFiles Include="System.IO.Compression.Native.a" /> <_pastShimFiles Include="System.IO.Compression.Native.dylib" /> <_pastShimFiles Include="System.IO.Compression.Native.so" /> @@ -80,6 +82,9 @@ + + + diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Unix.cs index df937e56e34fe..33982d73e8137 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Unix.cs @@ -12,9 +12,12 @@ private static partial class Settings /// the GlobalizationMode.Invariant check. Globalization P/Invokes, e.g. in CompareInfo.GetSortKey, /// rely on ICU already being loaded before they are called. /// -#if !TARGET_MACCATALYST && !TARGET_IOS && !TARGET_TVOS static Settings() { +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS + if (GlobalizationMode.Hybrid) + return; +#endif // Use GlobalizationMode.Invariant to allow ICU initialization to be trimmed when Invariant=true // and PredefinedCulturesOnly is unspecified. if (!GlobalizationMode.Invariant) @@ -33,7 +36,6 @@ static Settings() } } } -#endif private static string GetIcuLoadFailureMessage() { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs index 314bb33692dc7..639aea29c8a77 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs @@ -13,9 +13,8 @@ internal static partial class GlobalizationMode private static partial class Settings { internal static bool Invariant { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.Invariant", "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT"); -#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS - internal static bool Hybrid { get; } = true; -#elif TARGET_BROWSER + +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS || TARGET_BROWSER internal static bool Hybrid { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.Hybrid", "DOTNET_SYSTEM_GLOBALIZATION_HYBRID"); #endif internal static bool PredefinedCulturesOnly { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.PredefinedCulturesOnly", "DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY", GlobalizationMode.Invariant); diff --git a/src/mono/mono/metadata/native-library.c b/src/mono/mono/metadata/native-library.c index 6692736251330..4d02d2a2fe05f 100644 --- a/src/mono/mono/metadata/native-library.c +++ b/src/mono/mono/metadata/native-library.c @@ -47,9 +47,9 @@ static GHashTable *native_library_module_map; */ static GHashTable *native_library_module_blocklist; -#ifndef NO_GLOBALIZATION_SHIM -extern const void *GlobalizationResolveDllImport (const char *name); -#endif +// #ifndef NO_GLOBALIZATION_SHIM +// extern const void *GlobalizationResolveDllImport (const char *name); +// #endif static GHashTable *global_module_map; // should only be accessed with the global loader data lock @@ -786,25 +786,25 @@ get_dllimportsearchpath_flags (MonoCustomAttrInfo *cinfo) return flags; } -#ifndef NO_GLOBALIZATION_SHIM -#ifdef HOST_WIN32 -#define GLOBALIZATION_DLL_NAME "System.Globalization.Native" -#else -#define GLOBALIZATION_DLL_NAME "libSystem.Globalization.Native" -#endif - -static gpointer -default_resolve_dllimport (const char *dll, const char *func) -{ - if (strcmp (dll, GLOBALIZATION_DLL_NAME) == 0) { - const void *method_impl = GlobalizationResolveDllImport (func); - if (method_impl) - return (gpointer)method_impl; - } - - return NULL; -} -#endif // NO_GLOBALIZATION_SHIM +// #ifndef NO_GLOBALIZATION_SHIM +// #ifdef HOST_WIN32 +// #define GLOBALIZATION_DLL_NAME "System.Globalization.Native" +// #else +// #define GLOBALIZATION_DLL_NAME "libSystem.Globalization.Native" +// #endif + +// static gpointer +// default_resolve_dllimport (const char *dll, const char *func) +// { +// if (strcmp (dll, GLOBALIZATION_DLL_NAME) == 0) { +// const void *method_impl = GlobalizationResolveDllImport (func); +// if (method_impl) +// return (gpointer)method_impl; +// } + +// return NULL; +// } +// #endif // NO_GLOBALIZATION_SHIM gpointer lookup_pinvoke_call_impl (MonoMethod *method, MonoLookupPInvokeStatus *status_out) @@ -881,11 +881,11 @@ lookup_pinvoke_call_impl (MonoMethod *method, MonoLookupPInvokeStatus *status_ou } #endif -#ifndef NO_GLOBALIZATION_SHIM - addr = default_resolve_dllimport (new_scope, new_import); - if (addr) - goto exit; -#endif +// #ifndef NO_GLOBALIZATION_SHIM +// addr = default_resolve_dllimport (new_scope, new_import); +// if (addr) +// goto exit; +// #endif if (pinvoke_override) { addr = pinvoke_override (new_scope, new_import); diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index 3628dd3a19de2..68a6a0c7eaa4e 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -45,77 +45,77 @@ if(HOST_WIN32) add_link_options(/OPT:NOICF) endif() -# ICU -if(HAVE_SYS_ICU) - if(STATIC_ICU) - set(pal_icushim_sources_base - pal_icushim_static.c) - add_definitions(-DSTATIC_ICU=1) - else() - set(pal_icushim_sources_base - pal_icushim.c) - endif() - - set(icu_shim_sources_base - pal_idna.c - pal_common.c - entrypoints.c - ${pal_icushim_sources_base}) - -if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) - set(icu_shim_sources_base - ${icu_shim_sources_base} - pal_calendarData.c - pal_casing.c - pal_collation.c - pal_locale.c - pal_localeNumberData.c - pal_localeStringData.c - pal_normalization.c - pal_timeZoneInfo.c - ) -endif() - -if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) - set(icu_shim_sources_base - ${icu_shim_sources_base} - pal_placeholders.c - ) -endif() - - addprefix(icu_shim_sources "${ICU_SHIM_PATH}" "${icu_shim_sources_base}") - - if (TARGET_DARWIN) - set(icu_shim_darwin_sources_base - pal_locale.m - pal_collation.m - pal_casing.m - pal_calendarData.m - pal_normalization.m - pal_timeZoneInfo.m) - - addprefix(icu_shim_darwin_sources "${ICU_SHIM_PATH}" "${icu_shim_darwin_sources_base}") - set(icu_shim_sources ${icu_shim_sources} ${icu_shim_darwin_sources}) - endif() - - set_source_files_properties(${icu_shim_sources} PROPERTIES COMPILE_DEFINITIONS OSX_ICU_LIBRARY_PATH="${OSX_ICU_LIBRARY_PATH}") - set_source_files_properties(${icu_shim_sources} PROPERTIES COMPILE_FLAGS "-I\"${ICU_INCLUDEDIR}\" -I\"${CLR_SRC_NATIVE_DIR}/libs/System.Globalization.Native/\" -I\"${CLR_SRC_NATIVE_DIR}/libs/Common/\" ${ICU_FLAGS}") - if(TARGET_DARWIN) - set_property(SOURCE ${icu_shim_darwin_sources} APPEND_STRING PROPERTY COMPILE_FLAGS " -fobjc-arc ${CLR_CMAKE_COMMON_OBJC_FLAGS}") - endif() - if(TARGET_WIN32) - set_source_files_properties(${icu_shim_sources} PROPERTIES LANGUAGE CXX) - endif() - if(ICU_LIBDIR) - set(ICU_LDFLAGS "-L${ICU_LIBDIR}") - endif() - if(CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) - set(ICU_LDFLAGS "-licucore") - endif() - - add_library(icu_shim_objects OBJECT "${icu_shim_sources}") - set(HAVE_ICU_SHIM 1) -endif() +# # ICU +# if(HAVE_SYS_ICU) +# if(STATIC_ICU) +# set(pal_icushim_sources_base +# pal_icushim_static.c) +# add_definitions(-DSTATIC_ICU=1) +# else() +# set(pal_icushim_sources_base +# pal_icushim.c) +# endif() + +# set(icu_shim_sources_base +# pal_idna.c +# pal_common.c +# entrypoints.c +# ${pal_icushim_sources_base}) + +# if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) +# set(icu_shim_sources_base +# ${icu_shim_sources_base} +# pal_calendarData.c +# pal_casing.c +# pal_collation.c +# pal_locale.c +# pal_localeNumberData.c +# pal_localeStringData.c +# pal_normalization.c +# pal_timeZoneInfo.c +# ) +# endif() + +# if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) +# set(icu_shim_sources_base +# ${icu_shim_sources_base} +# pal_placeholders.c +# ) +# endif() + +# addprefix(icu_shim_sources "${ICU_SHIM_PATH}" "${icu_shim_sources_base}") + +# if (TARGET_DARWIN) +# set(icu_shim_darwin_sources_base +# pal_locale.m +# pal_collation.m +# pal_casing.m +# pal_calendarData.m +# pal_normalization.m +# pal_timeZoneInfo.m) + +# addprefix(icu_shim_darwin_sources "${ICU_SHIM_PATH}" "${icu_shim_darwin_sources_base}") +# set(icu_shim_sources ${icu_shim_sources} ${icu_shim_darwin_sources}) +# endif() + +# set_source_files_properties(${icu_shim_sources} PROPERTIES COMPILE_DEFINITIONS OSX_ICU_LIBRARY_PATH="${OSX_ICU_LIBRARY_PATH}") +# set_source_files_properties(${icu_shim_sources} PROPERTIES COMPILE_FLAGS "-I\"${ICU_INCLUDEDIR}\" -I\"${CLR_SRC_NATIVE_DIR}/libs/System.Globalization.Native/\" -I\"${CLR_SRC_NATIVE_DIR}/libs/Common/\" ${ICU_FLAGS}") +# if(TARGET_DARWIN) +# set_property(SOURCE ${icu_shim_darwin_sources} APPEND_STRING PROPERTY COMPILE_FLAGS " -fobjc-arc ${CLR_CMAKE_COMMON_OBJC_FLAGS}") +# endif() +# if(TARGET_WIN32) +# set_source_files_properties(${icu_shim_sources} PROPERTIES LANGUAGE CXX) +# endif() +# if(ICU_LIBDIR) +# set(ICU_LDFLAGS "-L${ICU_LIBDIR}") +# endif() +# if(CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) +# set(ICU_LDFLAGS "-licucore") +# endif() + +# add_library(icu_shim_objects OBJECT "${icu_shim_sources}") +# set(HAVE_ICU_SHIM 1) +# endif() # # MINI diff --git a/src/native/corehost/apphost/static/CMakeLists.txt b/src/native/corehost/apphost/static/CMakeLists.txt index 7a14c7c92ed66..68231734bdc70 100644 --- a/src/native/corehost/apphost/static/CMakeLists.txt +++ b/src/native/corehost/apphost/static/CMakeLists.txt @@ -143,6 +143,7 @@ else() coreclr_static System.Globalization.Native-Static + System.HybridGlobalization.Native-Static System.IO.Compression.Native-Static System.Net.Security.Native-Static System.Native-Static diff --git a/src/native/libs/CMakeLists.txt b/src/native/libs/CMakeLists.txt index 79b92e33da29e..893b2d89ef3b1 100644 --- a/src/native/libs/CMakeLists.txt +++ b/src/native/libs/CMakeLists.txt @@ -101,6 +101,9 @@ else () # we only need to build System.Globalization.Native when building static libs. if (STATIC_LIBS_ONLY) add_subdirectory(System.Globalization.Native) + if (CLR_CMAKE_TARGET_APPLE) + add_subdirectory(System.HybridGlobalization.Native) + endif () endif () endif () @@ -157,5 +160,6 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) if (CLR_CMAKE_TARGET_APPLE) add_subdirectory(System.Security.Cryptography.Native.Apple) + add_subdirectory(System.HybridGlobalization.Native) endif () endif () diff --git a/src/native/libs/System.Globalization.Native/CMakeLists.txt b/src/native/libs/System.Globalization.Native/CMakeLists.txt index 1959fec40a7cf..daaeb9d333549 100644 --- a/src/native/libs/System.Globalization.Native/CMakeLists.txt +++ b/src/native/libs/System.Globalization.Native/CMakeLists.txt @@ -22,7 +22,7 @@ if(CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_WASI) add_compile_options(-Wno-unknown-warning-option) # The mobile configurations in particular bring their own ICU, so skip - if (NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT DEFINED CMAKE_ICU_DIR) + if (NOT CLR_CMAKE_TARGET_ANDROID AND NOT DEFINED CMAKE_ICU_DIR) if (CLR_CMAKE_TARGET_OSX) execute_process(COMMAND brew --prefix OUTPUT_VARIABLE brew_prefix OUTPUT_STRIP_TRAILING_WHITESPACE) set(ICU_HOMEBREW_INC_PATH "${brew_prefix}/opt/icu4c/include") @@ -58,40 +58,23 @@ endif() include(configure.cmake) set(NATIVEGLOBALIZATION_SOURCES + pal_calendarData.c + pal_casing.c + pal_collation.c pal_idna.c pal_common.c -) -if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) - set(NATIVEGLOBALIZATION_SOURCES - ${NATIVEGLOBALIZATION_SOURCES} - pal_calendarData.c - pal_casing.c - pal_collation.c - pal_locale.c - pal_localeNumberData.c - pal_localeStringData.c - pal_normalization.c + pal_locale.c + pal_localeNumberData.c + pal_localeStringData.c + pal_normalization.c ) -endif() -if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) - add_definitions(-DAPPLE_HYBRID_GLOBALIZATION) - set(NATIVEGLOBALIZATION_SOURCES - ${NATIVEGLOBALIZATION_SOURCES} - pal_placeholders.c - ) -endif() - -if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND DEFINED CMAKE_ICU_DIR) +if (DEFINED CMAKE_ICU_DIR) include_directories(${CMAKE_ICU_DIR}/include) link_libraries(${CMAKE_ICU_DIR}/lib/libicuuc.a ${CMAKE_ICU_DIR}/lib/libicui18n.a ${CMAKE_ICU_DIR}/lib/libicudata.a) link_libraries(stdc++) endif() -if ((CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) AND NOT DEFINED CMAKE_ICU_DIR) - link_libraries(icucore) -endif() - if (CMAKE_USE_PTHREADS) add_compile_options(-pthread) add_linker_flag(-pthread) @@ -116,18 +99,13 @@ endif() if (CLR_CMAKE_TARGET_APPLE) set(NATIVEGLOBALIZATION_SOURCES_OBJC - pal_locale.m - pal_collation.m - pal_casing.m - pal_calendarData.m - pal_normalization.m - pal_timeZoneInfo.m) + pal_locale.m) set_source_files_properties(${NATIVEGLOBALIZATION_SOURCES_OBJC} PROPERTIES COMPILE_FLAGS "-fobjc-arc ${CLR_CMAKE_COMMON_OBJC_FLAGS}") set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} ${NATIVEGLOBALIZATION_SOURCES_OBJC}) endif() # time zone names are filtered out of icu data for the browser and associated functionality is disabled -if (NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) +if (NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_timeZoneInfo.c) endif() diff --git a/src/native/libs/System.Globalization.Native/entrypoints.c b/src/native/libs/System.Globalization.Native/entrypoints.c index f2db315ec5452..e6009cfafbb74 100644 --- a/src/native/libs/System.Globalization.Native/entrypoints.c +++ b/src/native/libs/System.Globalization.Native/entrypoints.c @@ -55,30 +55,7 @@ static const Entry s_globalizationNative[] = DllImportEntry(GlobalizationNative_NormalizeString) DllImportEntry(GlobalizationNative_StartsWith) DllImportEntry(GlobalizationNative_WindowsIdToIanaId) -#if defined(APPLE_HYBRID_GLOBALIZATION) - DllImportEntry(GlobalizationNative_ChangeCaseInvariantNative) - DllImportEntry(GlobalizationNative_ChangeCaseNative) - DllImportEntry(GlobalizationNative_CompareStringNative) - DllImportEntry(GlobalizationNative_GetDefaultLocaleNameNative) - DllImportEntry(GlobalizationNative_EndsWithNative) - DllImportEntry(GlobalizationNative_GetCalendarInfoNative) - DllImportEntry(GlobalizationNative_GetCalendarsNative) - DllImportEntry(GlobalizationNative_GetJapaneseEraStartDateNative) - DllImportEntry(GlobalizationNative_GetLatestJapaneseEraNative) - DllImportEntry(GlobalizationNative_GetLocaleInfoIntNative) - DllImportEntry(GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative) - DllImportEntry(GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative) - DllImportEntry(GlobalizationNative_GetLocaleInfoStringNative) - DllImportEntry(GlobalizationNative_GetLocaleNameNative) - DllImportEntry(GlobalizationNative_GetLocalesNative) - DllImportEntry(GlobalizationNative_GetLocaleTimeFormatNative) - DllImportEntry(GlobalizationNative_GetSortKeyNative) - DllImportEntry(GlobalizationNative_GetTimeZoneDisplayNameNative) - DllImportEntry(GlobalizationNative_IndexOfNative) - DllImportEntry(GlobalizationNative_IsNormalizedNative) - DllImportEntry(GlobalizationNative_NormalizeStringNative) - DllImportEntry(GlobalizationNative_StartsWithNative) -#endif + DllImportEntry(GlobalizationNative_ToAscii) DllImportEntry(GlobalizationNative_ToUnicode) DllImportEntry(GlobalizationNative_InitOrdinalCasingPage) diff --git a/src/native/libs/System.Globalization.Native/pal_icushim_internal.h b/src/native/libs/System.Globalization.Native/pal_icushim_internal.h index a7bad69cef319..e62ced1015f4e 100644 --- a/src/native/libs/System.Globalization.Native/pal_icushim_internal.h +++ b/src/native/libs/System.Globalization.Native/pal_icushim_internal.h @@ -21,11 +21,7 @@ // All ICU headers need to be included here so that all function prototypes are // available before the function pointers are declared below. -#if defined(APPLE_HYBRID_GLOBALIZATION) -#include -#include -#include -#else + #include #include #include @@ -46,7 +42,6 @@ #include #include -#endif #endif #elif defined(TARGET_WINDOWS) @@ -352,35 +347,3 @@ const char* GlobalizationNative_GetICUDataPathFallback(void); #endif #endif // !defined(STATIC_ICU) -#if defined(APPLE_HYBRID_GLOBALIZATION) -/** - * Append a code point to a string, overwriting 1 or 2 code units. - * The offset points to the current end of the string contents - * and is advanced (post-increment). - * "Safe" macro, checks for a valid code point. - * Converts code points outside of Basic Multilingual Plane into - * corresponding surrogate pairs if sufficient space in the string. - * High surrogate range: 0xD800 - 0xDBFF - * Low surrogate range: 0xDC00 - 0xDFFF - * If the code point is not valid or a trail surrogate does not fit, - * then isError is set to true. - * - * @param buffer const uint16_t * string buffer - * @param offset string offset, must be offset= (capacity)) /* insufficiently sized destination buffer */ { \ - (isError) = InsufficientBuffer; \ - } else if ((uint32_t)(codePoint) > 0x10ffff) /* invalid code point */ { \ - (isError) = InvalidCodePoint; \ - } else if ((uint32_t)(codePoint) <= 0xffff) { \ - (buffer)[(offset)++] = (uint16_t)(codePoint); \ - } else { \ - (buffer)[(offset)++] = (uint16_t)(((codePoint) >> 10) + 0xd7c0); \ - (buffer)[(offset)++] = (uint16_t)(((codePoint)&0x3ff) | 0xdc00); \ - } \ -} -#endif diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index 873b56950ee3c..e7b53b1790e55 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -8,7 +8,6 @@ #include "pal_localeNumberData.h" #import -#import #if !__has_feature(objc_arc) #error This file relies on ARC for memory management, but ARC is not enabled. @@ -36,805 +35,6 @@ return strdup([localeName UTF8String]); } -#if defined(APPLE_HYBRID_GLOBALIZATION) -const char* GlobalizationNative_GetLocaleNameNative(const char* localeName) -{ - @autoreleasepool - { - NSString *locName = [NSString stringWithFormat:@"%s", localeName]; - NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; - const char* value = [currentLocale.localeIdentifier UTF8String]; - return strdup(value); - } -} - -/** - * Useful constant for the maximum size of the whole locale ID - * (including the terminating NULL and all keywords). - */ -#define FULLNAME_CAPACITY 157 - -static void GetParent(const char* localeID, char* parent, int32_t parentCapacity) -{ - const char *lastUnderscore; - int32_t i; - - if (localeID == NULL) - localeID = [NSLocale systemLocale].localeIdentifier.UTF8String; - - lastUnderscore = strrchr(localeID, '-'); - if (lastUnderscore != NULL) - { - i = (int32_t)(lastUnderscore - localeID); - } - else - { - i = 0; - } - - if (i > 0) - { - // primary lang subtag und (undefined). - if (strncasecmp(localeID, "und-", 4) == 0) - { - localeID += 3; - i -= 3; - memmove(parent, localeID, MIN(i, parentCapacity)); - } - else if (parent != localeID) - { - memcpy(parent, localeID, MIN(i, parentCapacity)); - } - } - - // terminate chars - if (i >= 0 && i < parentCapacity) - parent[i] = 0; -} - -/** - * Lookup 'key' in the array 'list'. The array 'list' should contain - * a NULL entry, followed by more entries, and a second NULL entry. - * - * The 'list' param should be LANGUAGES, LANGUAGES_3, COUNTRIES, or - * COUNTRIES_3. - */ -static int16_t _findIndex(const char* const* list, const char* key) -{ - const char* const* anchor = list; - int32_t pass = 0; - - /* Make two passes through two NULL-terminated arrays at 'list' */ - while (pass++ < 2) { - while (*list) { - if (strcmp(key, *list) == 0) { - return (int16_t)(list - anchor); - } - list++; - } - ++list; /* skip final NULL *CWB*/ - } - return -1; -} - -static const char* getISO3CountryByCountryCode(const char* countryCode) -{ - int16_t offset = _findIndex(COUNTRIES, countryCode); - if (offset < 0) - return ""; - - return COUNTRIES_3[offset]; -} - -static const char* getISO3LanguageByLangCode(const char* langCode) -{ - int16_t offset = _findIndex(LANGUAGES, langCode); - if (offset < 0) - return ""; - return LANGUAGES_3[offset]; -} - -const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData, const char* currentUILocaleName) -{ - @autoreleasepool - { - NSString *value; - NSString *locName = [NSString stringWithFormat:@"%s", localeName]; - NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; - NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; - numberFormatter.locale = currentLocale; - NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; - [dateFormatter setLocale:currentLocale]; - NSLocale *gbLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"]; - - switch (localeStringData) - { - ///// localized name of locale, eg "German (Germany)" in UI language (corresponds to LOCALE_SLOCALIZEDDISPLAYNAME) - case LocaleString_LocalizedDisplayName: - { - NSString *currUILocaleName = [NSString stringWithFormat:@"%s", currentUILocaleName == NULL ? GlobalizationNative_GetDefaultLocaleNameNative() : currentUILocaleName]; - NSLocale *currentUILocale = [[NSLocale alloc] initWithLocaleIdentifier:currUILocaleName]; - value = [currentUILocale displayNameForKey:NSLocaleIdentifier value:currentLocale.localeIdentifier]; - break; - } - /// Display name (language + country usually) in English, eg "German (Germany)" (corresponds to LOCALE_SENGLISHDISPLAYNAME) - case LocaleString_EnglishDisplayName: - value = [gbLocale displayNameForKey:NSLocaleIdentifier value:currentLocale.localeIdentifier]; - break; - /// Display name in native locale language, eg "Deutsch (Deutschland) (corresponds to LOCALE_SNATIVEDISPLAYNAME) - case LocaleString_NativeDisplayName: - value = [currentLocale displayNameForKey:NSLocaleIdentifier value:currentLocale.localeIdentifier]; - break; - /// Language Display Name for a language, eg "German" in UI language (corresponds to LOCALE_SLOCALIZEDLANGUAGENAME) - case LocaleString_LocalizedLanguageName: - { - NSString *currUILocaleName = [NSString stringWithFormat:@"%s", currentUILocaleName == NULL ? GlobalizationNative_GetDefaultLocaleNameNative() : currentUILocaleName]; - NSLocale *currentUILocale = [[NSLocale alloc] initWithLocaleIdentifier:currUILocaleName]; - value = [currentUILocale localizedStringForLanguageCode:currentLocale.languageCode]; - break; - } - /// English name of language, eg "German" (corresponds to LOCALE_SENGLISHLANGUAGENAME) - case LocaleString_EnglishLanguageName: - value = [gbLocale localizedStringForLanguageCode:currentLocale.languageCode]; - break; - /// native name of language, eg "Deutsch" (corresponds to LOCALE_SNATIVELANGUAGENAME) - case LocaleString_NativeLanguageName: - value = [currentLocale localizedStringForLanguageCode:currentLocale.languageCode]; - break; - /// English name of country, eg "Germany" (corresponds to LOCALE_SENGLISHCOUNTRYNAME) - case LocaleString_EnglishCountryName: - value = [gbLocale localizedStringForCountryCode:currentLocale.countryCode]; - break; - /// native name of country, eg "Deutschland" (corresponds to LOCALE_SNATIVECOUNTRYNAME) - case LocaleString_NativeCountryName: - value = [currentLocale localizedStringForCountryCode:currentLocale.countryCode]; - break; - case LocaleString_ThousandSeparator: - value = currentLocale.groupingSeparator; - break; - case LocaleString_DecimalSeparator: - value = currentLocale.decimalSeparator; - // or value = [[currentLocale objectForKey:NSLocaleDecimalSeparator] UTF8String]; - break; - case LocaleString_Digits: - { - NSString *digitsString = @"0123456789"; - NSNumberFormatter *nf1 = [[NSNumberFormatter alloc] init]; - [nf1 setLocale:currentLocale]; - - NSNumber *newNum = [nf1 numberFromString:digitsString]; - value = [newNum stringValue]; - break; - } - case LocaleString_MonetarySymbol: - value = currentLocale.currencySymbol; - break; - case LocaleString_Iso4217MonetarySymbol: - // check if this is correct, check currencyISOCode - value = currentLocale.currencyCode; - break; - case LocaleString_CurrencyEnglishName: - value = [gbLocale localizedStringForCurrencyCode:currentLocale.currencyCode]; - break; - case LocaleString_CurrencyNativeName: - value = [currentLocale localizedStringForCurrencyCode:currentLocale.currencyCode]; - break; - case LocaleString_MonetaryDecimalSeparator: - value = numberFormatter.currencyDecimalSeparator; - break; - case LocaleString_MonetaryThousandSeparator: - value = numberFormatter.currencyGroupingSeparator; - break; - case LocaleString_AMDesignator: - value = dateFormatter.AMSymbol; - break; - case LocaleString_PMDesignator: - value = dateFormatter.PMSymbol; - break; - case LocaleString_PositiveSign: - value = numberFormatter.plusSign; - break; - case LocaleString_NegativeSign: - value = numberFormatter.minusSign; - break; - case LocaleString_Iso639LanguageTwoLetterName: - value = [currentLocale objectForKey:NSLocaleLanguageCode]; - break; - case LocaleString_Iso639LanguageThreeLetterName: - { - NSString *iso639_2 = [currentLocale objectForKey:NSLocaleLanguageCode]; - return iso639_2 == nil ? strdup("") : strdup(getISO3LanguageByLangCode([iso639_2 UTF8String])); - } - case LocaleString_Iso3166CountryName: - value = [currentLocale objectForKey:NSLocaleCountryCode]; - break; - case LocaleString_Iso3166CountryName2: - { - NSString* countryCode = [currentLocale objectForKey:NSLocaleCountryCode]; - return countryCode == nil ? strdup("") : strdup(getISO3CountryByCountryCode([countryCode UTF8String])); - } - case LocaleString_NaNSymbol: - value = numberFormatter.notANumberSymbol; - break; - case LocaleString_PositiveInfinitySymbol: - value = numberFormatter.positiveInfinitySymbol; - break; - case LocaleString_NegativeInfinitySymbol: - value = numberFormatter.negativeInfinitySymbol; - break; - case LocaleString_PercentSymbol: - value = numberFormatter.percentSymbol; - break; - case LocaleString_PerMilleSymbol: - value = numberFormatter.perMillSymbol; - break; - case LocaleString_ParentName: - { - char localeNameTemp[FULLNAME_CAPACITY]; - const char* lName = [currentLocale.localeIdentifier UTF8String]; - GetParent(lName, localeNameTemp, FULLNAME_CAPACITY); - return strdup(localeNameTemp); - } - default: - value = nil; - break; - } - - return value == nil ? strdup("") : strdup([value UTF8String]); - } -} - -// invariant character definitions -#define CHAR_CURRENCY ((char)0x00A4) // international currency -#define CHAR_SPACE ((char)0x0020) // space -#define CHAR_NBSPACE ((char)0x00A0) // no-break space -#define CHAR_DIGIT ((char)0x0023) // '#' -#define CHAR_MINUS ((char)0x002D) // '-' -#define CHAR_PERCENT ((char)0x0025) // '%' -#define CHAR_OPENPAREN ((char)0x0028) // '(' -#define CHAR_CLOSEPAREN ((char)0x0029) // ')' -#define CHAR_ZERO ((char)0x0030) // '0' - -/* -Function: -NormalizeNumericPattern - -Returns a numeric string pattern in a format that we can match against the -appropriate managed pattern. Examples: -For PositiveMonetaryNumberFormat "¤#,##0.00" becomes "Cn" -For NegativeNumberFormat "#,##0.00;(#,##0.00)" becomes "(n)" -*/ -static char* NormalizeNumericPattern(const char* srcPattern, int isNegative) -{ - int iStart = 0; - int iEnd = strlen(srcPattern); - - // ';' separates positive and negative subpatterns. - // When there is no explicit negative subpattern, - // an implicit negative subpattern is formed from the positive pattern with a prefixed '-'. - char * ptrNegativePattern = strrchr(srcPattern,';'); - if (ptrNegativePattern) - { - int32_t iNegativePatternStart = ptrNegativePattern - srcPattern; - if (isNegative) - { - iStart = iNegativePatternStart + 1; - } - else - { - iEnd = iNegativePatternStart - 1; - } - } - - int minusAdded = false; - - for (int i = iStart; i <= iEnd; i++) - { - switch (srcPattern[i]) - { - case CHAR_MINUS: - case CHAR_OPENPAREN: - case CHAR_CLOSEPAREN: - minusAdded = true; - break; - } - - if (minusAdded) - break; - } - - // international currency symbol (CHAR_CURRENCY) - // The positive pattern comes first, then an optional negative pattern - // separated by a semicolon - // A destPattern example: "(C n)" where C represents the currency symbol, and - // n is the number - char* destPattern; - int index = 0; - - // if there is no negative subpattern, prefix the minus sign - if (isNegative && !minusAdded) - { - int length = (iEnd - iStart) + 2; - destPattern = (char*)calloc((size_t)length, sizeof(char)); - if (!destPattern) - { - return NULL; - } - destPattern[index++] = '-'; - } - else - { - int length = (iEnd - iStart) + 1; - destPattern = (char*)calloc((size_t)length, sizeof(char)); - if (!destPattern) - { - return NULL; - } - } - - int digitAdded = false; - int currencyAdded = false; - int spaceAdded = false; - - for (int i = iStart; i <= iEnd; i++) - { - char ch = srcPattern[i]; - switch (ch) - { - case CHAR_DIGIT: - case CHAR_ZERO: - if (!digitAdded) - { - digitAdded = true; - destPattern[index++] = 'n'; - } - break; - - case CHAR_CURRENCY: - if (!currencyAdded) - { - currencyAdded = true; - destPattern[index++] = 'C'; - } - break; - - case CHAR_SPACE: - case CHAR_NBSPACE: - if (!spaceAdded) - { - spaceAdded = true; - destPattern[index++] = ' '; - } - break; - - case CHAR_MINUS: - case CHAR_OPENPAREN: - case CHAR_CLOSEPAREN: - case CHAR_PERCENT: - destPattern[index++] = ch; - break; - } - } - - const int MAX_DOTNET_NUMERIC_PATTERN_LENGTH = 6; // example: "(C n)" plus terminator - - if (destPattern[0] == '\0' || strlen (destPattern) >= MAX_DOTNET_NUMERIC_PATTERN_LENGTH) - { - free (destPattern); - return NULL; - } - - return destPattern; -} - -/* -Function: -GetNumericPattern - -Determines the pattern from the decimalFormat and returns the matching pattern's -index from patterns[]. -Returns index -1 if no pattern is found. -*/ -static int GetPatternIndex(char* normalizedPattern,const char* patterns[], int patternsCount) -{ - const int INVALID_FORMAT = -1; - - if (!normalizedPattern) - { - return INVALID_FORMAT; - } - - for (int i = 0; i < patternsCount; i++) - { - if (strcmp(normalizedPattern, patterns[i]) == 0) - { - free(normalizedPattern); - return i; - } - } - assert(false); // should have found a valid pattern - free(normalizedPattern); - return INVALID_FORMAT; -} - -static int32_t GetValueForNumberFormat(NSLocale *currentLocale, LocaleNumberData localeNumberData) -{ - NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; - numberFormatter.locale = currentLocale; - const char *pFormat; - int32_t value; - - switch(localeNumberData) - { - case LocaleNumber_PositiveMonetaryNumberFormat: - { - numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle; - static const char* Patterns[] = {"Cn", "nC", "C n", "n C"}; - pFormat = [[numberFormatter positiveFormat] UTF8String]; - char* normalizedPattern = NormalizeNumericPattern(pFormat, false); - value = GetPatternIndex(normalizedPattern, Patterns, sizeof(Patterns)/sizeof(Patterns[0])); - break; - } - case LocaleNumber_NegativeMonetaryNumberFormat: - { - numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle; - static const char* Patterns[] = {"(Cn)", "-Cn", "C-n", "Cn-", "(nC)", "-nC", "n-C", "nC-", "-n C", - "-C n", "n C-", "C n-", "C -n", "n- C", "(C n)", "(n C)", "C- n" }; - pFormat = [[numberFormatter negativeFormat] UTF8String]; - char* normalizedPattern = NormalizeNumericPattern(pFormat, true); - value = GetPatternIndex(normalizedPattern, Patterns, sizeof(Patterns)/sizeof(Patterns[0])); - break; - } - case LocaleNumber_NegativeNumberFormat: - { - numberFormatter.numberStyle = NSNumberFormatterDecimalStyle; - static const char* Patterns[] = {"(n)", "-n", "- n", "n-", "n -"}; - pFormat = [[numberFormatter negativeFormat] UTF8String]; - char* normalizedPattern = NormalizeNumericPattern(pFormat, true); - value = GetPatternIndex(normalizedPattern, Patterns, sizeof(Patterns)/sizeof(Patterns[0])); - break; - } - case LocaleNumber_NegativePercentFormat: - { - numberFormatter.numberStyle = NSNumberFormatterPercentStyle; - static const char* Patterns[] = {"-n %", "-n%", "-%n", "%-n", "%n-", "n-%", "n%-", "-% n", "n %-", "% n-", "% -n", "n- %"}; - pFormat = [[numberFormatter negativeFormat] UTF8String]; - char* normalizedPattern = NormalizeNumericPattern(pFormat, true); - value = GetPatternIndex(normalizedPattern, Patterns, sizeof(Patterns)/sizeof(Patterns[0])); - break; - } - case LocaleNumber_PositivePercentFormat: - { - numberFormatter.numberStyle = NSNumberFormatterPercentStyle; - static const char* Patterns[] = {"n %", "n%", "%n", "% n"}; - pFormat = [[numberFormatter positiveFormat] UTF8String]; - char* normalizedPattern = NormalizeNumericPattern(pFormat, false); - value = GetPatternIndex(normalizedPattern, Patterns, sizeof(Patterns)/sizeof(Patterns[0])); - break; - } - default: - return -1; - } - - return value; -} - -int32_t GlobalizationNative_GetLocaleInfoIntNative(const char* localeName, LocaleNumberData localeNumberData) -{ - @autoreleasepool - { -#ifndef NDEBUG - bool isSuccess = true; -#endif - int32_t value; - NSString *locName = [NSString stringWithFormat:@"%s", localeName]; - NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; - - switch (localeNumberData) - { - case LocaleNumber_MeasurementSystem: - { - const char *measurementSystem = [[currentLocale objectForKey:NSLocaleMeasurementSystem] UTF8String]; - NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; - const char *us_measurementSystem = [[usLocale objectForKey:NSLocaleMeasurementSystem] UTF8String]; - value = (measurementSystem == us_measurementSystem) ? 1 : 0; - break; - } - case LocaleNumber_FractionalDigitsCount: - { - NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; - numberFormatter.locale = currentLocale; - numberFormatter.numberStyle = NSNumberFormatterDecimalStyle; - value = (int32_t)numberFormatter.maximumFractionDigits; - break; - } - case LocaleNumber_MonetaryFractionalDigitsCount: - { - NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; - numberFormatter.locale = currentLocale; - numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle; - value = (int32_t)numberFormatter.maximumFractionDigits; - break; - } - case LocaleNumber_PositiveMonetaryNumberFormat: - case LocaleNumber_NegativeMonetaryNumberFormat: - case LocaleNumber_NegativeNumberFormat: - case LocaleNumber_NegativePercentFormat: - case LocaleNumber_PositivePercentFormat: - { - value = GetValueForNumberFormat(currentLocale, localeNumberData); -#ifndef NDEBUG - if (value < 0) - { - isSuccess = false; - } -#endif - break; - } - case LocaleNumber_FirstWeekOfYear: - { - NSCalendar *calendar = [currentLocale objectForKey:NSLocaleCalendar]; - int minDaysInWeek = (int32_t)[calendar minimumDaysInFirstWeek]; - if (minDaysInWeek == 1) - { - value = WeekRule_FirstDay; - } - else if (minDaysInWeek == 7) - { - value = WeekRule_FirstFullWeek; - } - else if (minDaysInWeek >= 4) - { - value = WeekRule_FirstFourDayWeek; - } - else - { - value = -1; -#ifndef NDEBUG - isSuccess = false; -#endif - } - break; - } - case LocaleNumber_ReadingLayout: - { - NSLocaleLanguageDirection langDir = [NSLocale characterDirectionForLanguage:[currentLocale objectForKey:NSLocaleLanguageCode]]; - // 0 - Left to right (such as en-US) - // 1 - Right to left (such as arabic locales) - value = NSLocaleLanguageDirectionRightToLeft == langDir ? 1 : 0; - break; - } - case LocaleNumber_FirstDayofWeek: - { - NSCalendar *calendar = [currentLocale objectForKey:NSLocaleCalendar]; - value = [calendar firstWeekday] - 1; // .NET is 0-based and in Apple is 1-based; - break; - } - default: - value = -1; -#ifndef NDEBUG - isSuccess = false; -#endif - break; - } - - assert(isSuccess); - - return value; - } -} - -/* -PAL Function: -GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative - -Returns primary grouping size for decimal and currency -*/ -int32_t GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative(const char* localeName, LocaleNumberData localeGroupingData) -{ - @autoreleasepool - { - NSString *locName = [NSString stringWithFormat:@"%s", localeName]; - NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; - NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; - numberFormatter.locale = currentLocale; - - switch (localeGroupingData) - { - case LocaleNumber_Digit: - numberFormatter.numberStyle = NSNumberFormatterDecimalStyle; - break; - case LocaleNumber_Monetary: - numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle; - break; - default: - assert(false); - break; - } - return [numberFormatter groupingSize]; - } -} - -/* -PAL Function: -GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative - -Returns secondary grouping size for decimal and currency -*/ -int32_t GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative(const char* localeName, LocaleNumberData localeGroupingData) -{ - @autoreleasepool - { - NSString *locName = [NSString stringWithFormat:@"%s", localeName]; - NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; - NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; - numberFormatter.locale = currentLocale; - - switch (localeGroupingData) - { - case LocaleNumber_Digit: - numberFormatter.numberStyle = NSNumberFormatterDecimalStyle; - break; - case LocaleNumber_Monetary: - numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle; - break; - default: - assert(false); - break; - } - - return [numberFormatter secondaryGroupingSize]; - } -} - -/* -PAL Function: -GlobalizationNative_GetLocaleTimeFormatNative - -Returns time format information (in native format, it needs to be converted to .NET's format). -*/ -const char* GlobalizationNative_GetLocaleTimeFormatNative(const char* localeName, int shortFormat) -{ - @autoreleasepool - { - NSString *locName = [NSString stringWithFormat:@"%s", localeName]; - NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; - NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; - [dateFormatter setLocale:currentLocale]; - - if (shortFormat != 0) - { - [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; - } - else - { - [dateFormatter setTimeStyle:NSDateFormatterMediumStyle]; - } - - return strdup([[dateFormatter dateFormat] UTF8String]); - } -} - -// GlobalizationNative_GetLocalesNative gets all locale names and store it in the value buffer -// in case of success, it returns the count of the characters stored in value buffer -// in case of failure, it returns negative number. -// if the input value buffer is null, it returns the length needed to store the -// locale names list. -// if the value is not null, it fills the value with locale names separated by the length -// of each name. -int32_t GlobalizationNative_GetLocalesNative(UChar* value, int32_t length) -{ - @autoreleasepool - { - NSArray* availableLocaleIdentifiers = [NSLocale availableLocaleIdentifiers]; - int32_t index = 0; - int32_t totalLength = 0; - int32_t availableLength = (int32_t)[availableLocaleIdentifiers count]; - - if (availableLength <= 0) - return -1; // failed - - for (NSInteger i = 0; i < availableLength; i++) - { - NSString *localeIdentifier = availableLocaleIdentifiers[i]; - int32_t localeNameLength = localeIdentifier.length; - totalLength += localeNameLength + 1; // add 1 for the name length - if (value != NULL) - { - if (totalLength > length) - return -3; - - value[index++] = (UChar) localeNameLength; - - for (int j = 0; j < localeNameLength; j++) - { - if ((UChar)[localeIdentifier characterAtIndex:j] == '_') - { - value[index++] = (UChar) '-'; - } - else - { - value[index++] = (UChar) [localeIdentifier characterAtIndex:j]; - } - } - } - } - return totalLength; - } -} - -const char* GlobalizationNative_GetICUDataPathRelativeToAppBundleRoot(const char* path) -{ - @autoreleasepool - { - NSString *bundlePath = [[NSBundle mainBundle] bundlePath]; - NSString *dataPath = [bundlePath stringByAppendingPathComponent: [NSString stringWithFormat:@"%s", path]]; - - return strdup([dataPath UTF8String]); - } -} - -const char* GlobalizationNative_GetICUDataPathFallback(void) -{ - @autoreleasepool - { - NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"icudt" ofType:@"dat"]; - return strdup([dataPath UTF8String]); - } -} - -const char* GlobalizationNative_GetDefaultLocaleNameNative(void) -{ - @autoreleasepool - { - if (NSLocale.preferredLanguages.count > 0) - { - return strdup([NSLocale.preferredLanguages[0] UTF8String]); - } - else - { - NSLocale *currentLocale = [NSLocale currentLocale]; - NSString *localeName = @""; - - if (!currentLocale) - { - return strdup([localeName UTF8String]); - } - - if ([currentLocale.languageCode length] > 0 && [currentLocale.countryCode length] > 0) - { - localeName = [NSString stringWithFormat:@"%@-%@", currentLocale.languageCode, currentLocale.countryCode]; - } - else - { - localeName = currentLocale.localeIdentifier; - } - - return strdup([localeName UTF8String]); - } - } -} - -// GlobalizationNative_IsPredefinedLocaleNative returns TRUE if localeName exists in availableLocaleIdentifiers. -// Otherwise it returns FALSE; - -int32_t GlobalizationNative_IsPredefinedLocaleNative(const char* localeName) -{ - @autoreleasepool - { - NSString *localeIdentifier = [NSString stringWithFormat:@"%s", localeName]; - NSString *localeIdentifierByRegionDesignator = [localeIdentifier stringByReplacingOccurrencesOfString:@"-" withString:@"_"]; - NSArray *availableLocales = [NSLocale availableLocaleIdentifiers]; - - if ([availableLocales containsObject:localeIdentifier] || [availableLocales containsObject:localeIdentifierByRegionDesignator]) - { - return true; - } - - return false; - } -} -#endif diff --git a/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt b/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt new file mode 100644 index 0000000000000..479f88b131e17 --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt @@ -0,0 +1,203 @@ +# Required for StaticICULinking +cmake_minimum_required(VERSION 3.10..3.20) + +project(System.HybridGlobalization.Native C) + +if(CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_WASI) + if (ANDROID_FORCE_ICU_DATA_DIR) + add_definitions(-DANDROID_FORCE_ICU_DATA_DIR) + endif() + + add_compile_options(-Wno-switch-enum) + add_compile_options(-Wno-covered-switch-default) + + # Workaround for warnings produced by ICU headers + add_compile_options(-Wno-reserved-id-macro) + add_compile_options(-Wno-documentation) + add_compile_options(-Wno-documentation-unknown-command) + add_compile_options(-Wno-reserved-identifier) + + # Workaround for https://unicode-org.atlassian.net/browse/ICU-20601 + add_compile_options(-Wno-extra-semi-stmt) + add_compile_options(-Wno-unknown-warning-option) + + # The mobile configurations in particular bring their own ICU, so skip + if (NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT DEFINED CMAKE_ICU_DIR) + if (CLR_CMAKE_TARGET_OSX) + execute_process(COMMAND brew --prefix OUTPUT_VARIABLE brew_prefix OUTPUT_STRIP_TRAILING_WHITESPACE) + set(ICU_HOMEBREW_INC_PATH "${brew_prefix}/opt/icu4c/include") + endif() + + find_path(UCURR_H "unicode/ucurr.h" PATHS ${ICU_HOMEBREW_INC_PATH}) + if(UCURR_H STREQUAL UCURR_H-NOTFOUND) + message(FATAL_ERROR "Cannot find ucurr.h, try installing libicu-dev (or the appropriate package for your platform)") + return() + endif() + + if(CLR_CMAKE_TARGET_OSX) + add_definitions(-DOSX_ICU_LIBRARY_PATH="/usr/lib/libicucore.dylib") + add_definitions(-DU_DISABLE_RENAMING) + else() + find_library(ICUUC icuuc) + if(ICUUC STREQUAL ICUUC-NOTFOUND) + message(FATAL_ERROR "Cannot find libicuuc, try installing libicu-dev (or the appropriate package for your platform)") + return() + endif() + + find_library(ICUI18N icui18n) + if(ICUI18N STREQUAL ICUI18N-NOTFOUND) + message(FATAL_ERROR "Cannot find libicui18n, try installing libicu-dev (or the appropriate package for your platform)") + return() + endif() + endif() + + include_directories(${UCURR_H}) + endif() +endif() + +include(configure.cmake) + +set(NATIVEGLOBALIZATION_SOURCES + pal_idna.c + pal_common.c +) +# if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) +# set(NATIVEGLOBALIZATION_SOURCES +# ${NATIVEGLOBALIZATION_SOURCES} +# pal_calendarData.c +# pal_casing.c +# pal_collation.c +# pal_locale.c +# pal_localeNumberData.c +# pal_localeStringData.c +# pal_normalization.c +# ) +# endif() + +if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) + add_definitions(-DAPPLE_HYBRID_GLOBALIZATION) + set(NATIVEGLOBALIZATION_SOURCES + ${NATIVEGLOBALIZATION_SOURCES} + pal_placeholders.c + ) +endif() + +if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND DEFINED CMAKE_ICU_DIR) + include_directories(${CMAKE_ICU_DIR}/include) + link_libraries(${CMAKE_ICU_DIR}/lib/libicuuc.a ${CMAKE_ICU_DIR}/lib/libicui18n.a ${CMAKE_ICU_DIR}/lib/libicudata.a) + link_libraries(stdc++) +endif() + +if ((CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) AND NOT DEFINED CMAKE_ICU_DIR) + link_libraries(icucore) +endif() + +if (CMAKE_USE_PTHREADS) + add_compile_options(-pthread) + add_linker_flag(-pthread) +endif() + +if (LOCAL_BUILD) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_icushim_static.c) + add_definitions(-DLOCAL_BUILD) + add_definitions(-DSTATIC_ICU) + add_definitions(-DPALEXPORT=EXTERN_C) + add_definitions(-DTARGET_UNIX) + # For minipal files + include_directories(../../) + include_directories(${CMAKE_CURRENT_BINARY_DIR}) +elseif (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) + add_definitions(-DSTATIC_ICU) + set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_icushim_static.c) +else() + set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_icushim.c) +endif() + +if (CLR_CMAKE_TARGET_APPLE) + set(NATIVEGLOBALIZATION_SOURCES_OBJC + pal_locale.m + pal_collation.m + pal_casing.m + pal_calendarData.m + pal_normalization.m + pal_timeZoneInfo.m) + set_source_files_properties(${NATIVEGLOBALIZATION_SOURCES_OBJC} PROPERTIES COMPILE_FLAGS "-fobjc-arc ${CLR_CMAKE_COMMON_OBJC_FLAGS}") + set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} ${NATIVEGLOBALIZATION_SOURCES_OBJC}) +endif() + +# time zone names are filtered out of icu data for the browser and associated functionality is disabled +if (NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) + set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_timeZoneInfo.c) +endif() + +if (MSVC) + set_source_files_properties(${NATIVEGLOBALIZATION_SOURCES} PROPERTIES LANGUAGE CXX) +endif() + +include_directories("../Common") + +if (GEN_SHARED_LIB) + if (CLR_CMAKE_TARGET_APPLE) + include(CMakeFindFrameworks) + find_library(FOUNDATION Foundation REQUIRED) + endif() + + add_library(System.HybridGlobalization.Native + SHARED + ${NATIVEGLOBALIZATION_SOURCES} + ${VERSION_FILE_PATH} + ) + + target_link_libraries(System.HybridGlobalization.Native + PRIVATE + ${CMAKE_DL_LIBS} + ${FOUNDATION} + ) + + install_with_stripped_symbols (System.HybridGlobalization.Native PROGRAMS .) +endif() + +add_library(System.HybridGlobalization.Native-Static + STATIC + ${NATIVEGLOBALIZATION_SOURCES} + entrypoints.c +) + +if(CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_WASI) + set_target_properties(System.HybridGlobalization.Native-Static PROPERTIES OUTPUT_NAME System.HybridGlobalization.Native CLEAN_DIRECT_OUTPUT 1) +endif() + +install (TARGETS System.HybridGlobalization.Native-Static DESTINATION ${STATIC_LIB_DESTINATION} COMPONENT libs) + +if(NOT CLR_CMAKE_TARGET_APPLE AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_LINUX_MUSL AND NOT CLR_CMAKE_TARGET_HAIKU) + if (GEN_SHARED_LIB) + add_custom_command(TARGET System.HybridGlobalization.Native POST_BUILD + COMMENT "Verifying System.HybridGlobalization.Native.so dependencies" + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../verify-so.sh + $ + "Verification failed. System.HybridGlobalization.Native.so has undefined dependencies. These are likely ICU APIs that need to be added to icushim.h." + VERBATIM + ) + endif() +endif() + +if(CLR_CMAKE_TARGET_WIN32) + if(STATIC_LIBS_ONLY) + add_library(System.HybridGlobalization.Native.Aot + STATIC + ${NATIVEGLOBALIZATION_SOURCES} + ) + set_target_properties(System.HybridGlobalization.Native.Aot PROPERTIES CLR_CONTROL_FLOW_GUARD OFF) + set_target_properties(System.HybridGlobalization.Native.Aot PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) + + add_library(System.HybridGlobalization.Native.Aot.GuardCF + STATIC + ${NATIVEGLOBALIZATION_SOURCES} + ) + set_target_properties(System.HybridGlobalization.Native.Aot.GuardCF PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) + + install_static_library(System.HybridGlobalization.Native.Aot aotsdk nativeaot) + install_static_library(System.HybridGlobalization.Native.Aot.GuardCF aotsdk nativeaot) + endif() +endif() \ No newline at end of file diff --git a/src/native/libs/System.HybridGlobalization.Native/config.h.in b/src/native/libs/System.HybridGlobalization.Native/config.h.in new file mode 100644 index 0000000000000..933a3d0c5c419 --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/config.h.in @@ -0,0 +1,5 @@ +#pragma once + +#cmakedefine01 HAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS +#cmakedefine01 HAVE_SET_MAX_VARIABLE +#cmakedefine01 HAVE_UCOL_CLONE \ No newline at end of file diff --git a/src/native/libs/System.HybridGlobalization.Native/configure.cmake b/src/native/libs/System.HybridGlobalization.Native/configure.cmake new file mode 100644 index 0000000000000..8163745c4c20a --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/configure.cmake @@ -0,0 +1,36 @@ +if(CLR_CMAKE_TARGET_ANDROID OR CLR_CMAKE_TARGET_APPLE OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) + set(HAVE_SET_MAX_VARIABLE 1) + set(HAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS 1) + set(HAVE_UCOL_CLONE 0) +else() + include(CheckCSourceCompiles) + include(CheckSymbolExists) + + if (CLR_CMAKE_TARGET_UNIX) + set(CMAKE_REQUIRED_INCLUDES ${UCURR_H} ${ICU_HOMEBREW_INC_PATH}) + + CHECK_C_SOURCE_COMPILES(" + #include + int main(void) { enum UDateFormatSymbolType e = UDAT_STANDALONE_SHORTER_WEEKDAYS; } + " HAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS) + + set(CMAKE_REQUIRED_LIBRARIES ${ICUUC} ${ICUI18N}) + + check_symbol_exists( + ucol_setMaxVariable + "unicode/ucol.h" + HAVE_SET_MAX_VARIABLE) + + check_symbol_exists( + ucol_clone + "unicode/ucol.h" + HAVE_UCOL_CLONE) + + unset(CMAKE_REQUIRED_LIBRARIES) + unset(CMAKE_REQUIRED_INCLUDES) + endif() +endif() + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/config.h) diff --git a/src/native/libs/System.HybridGlobalization.Native/entrypoints.c b/src/native/libs/System.HybridGlobalization.Native/entrypoints.c new file mode 100644 index 0000000000000..91bda0a13b551 --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/entrypoints.c @@ -0,0 +1,92 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include + +typedef uint16_t UChar; + +// Include System.HybridGlobalization.Native headers +#include "pal_calendarData.h" +#include "pal_casing.h" +#include "pal_collation.h" +#include "pal_locale.h" +#include "pal_localeNumberData.h" +#include "pal_localeStringData.h" +#include "pal_icushim.h" +#include "pal_idna.h" +#include "pal_normalization.h" +#include "pal_timeZoneInfo.h" + +static const Entry s_globalizationNative[] = +{ + DllImportEntry(GlobalizationNative_ChangeCase) + DllImportEntry(GlobalizationNative_ChangeCaseInvariant) + DllImportEntry(GlobalizationNative_ChangeCaseTurkish) + DllImportEntry(GlobalizationNative_CloseSortHandle) + DllImportEntry(GlobalizationNative_CompareString) + DllImportEntry(GlobalizationNative_EndsWith) + DllImportEntry(GlobalizationNative_EnumCalendarInfo) + DllImportEntry(GlobalizationNative_GetCalendarInfo) + DllImportEntry(GlobalizationNative_GetCalendars) + DllImportEntry(GlobalizationNative_GetDefaultLocaleName) + DllImportEntry(GlobalizationNative_GetICUVersion) + DllImportEntry(GlobalizationNative_GetJapaneseEraStartDate) + DllImportEntry(GlobalizationNative_GetLatestJapaneseEra) + DllImportEntry(GlobalizationNative_GetLocaleInfoGroupingSizes) + DllImportEntry(GlobalizationNative_GetLocaleInfoInt) + DllImportEntry(GlobalizationNative_GetLocaleInfoString) + DllImportEntry(GlobalizationNative_GetLocaleName) + DllImportEntry(GlobalizationNative_GetLocales) + DllImportEntry(GlobalizationNative_GetLocaleTimeFormat) + DllImportEntry(GlobalizationNative_GetSortHandle) + DllImportEntry(GlobalizationNative_GetSortKey) + DllImportEntry(GlobalizationNative_GetSortVersion) + DllImportEntry(GlobalizationNative_GetTimeZoneDisplayName) + DllImportEntry(GlobalizationNative_IanaIdToWindowsId) + DllImportEntry(GlobalizationNative_IndexOf) + DllImportEntry(GlobalizationNative_InitICUFunctions) + DllImportEntry(GlobalizationNative_IsNormalized) + DllImportEntry(GlobalizationNative_IsPredefinedLocale) + DllImportEntry(GlobalizationNative_LastIndexOf) + DllImportEntry(GlobalizationNative_LoadICU) +#if defined(STATIC_ICU) + DllImportEntry(GlobalizationNative_LoadICUData) +#endif + DllImportEntry(GlobalizationNative_NormalizeString) + DllImportEntry(GlobalizationNative_StartsWith) + DllImportEntry(GlobalizationNative_WindowsIdToIanaId) +#if defined(APPLE_HYBRID_GLOBALIZATION) + DllImportEntry(GlobalizationNative_ChangeCaseInvariantNative) + DllImportEntry(GlobalizationNative_ChangeCaseNative) + DllImportEntry(GlobalizationNative_CompareStringNative) + DllImportEntry(GlobalizationNative_GetDefaultLocaleNameNative) + DllImportEntry(GlobalizationNative_EndsWithNative) + DllImportEntry(GlobalizationNative_GetCalendarInfoNative) + DllImportEntry(GlobalizationNative_GetCalendarsNative) + DllImportEntry(GlobalizationNative_GetJapaneseEraStartDateNative) + DllImportEntry(GlobalizationNative_GetLatestJapaneseEraNative) + DllImportEntry(GlobalizationNative_GetLocaleInfoIntNative) + DllImportEntry(GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative) + DllImportEntry(GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative) + DllImportEntry(GlobalizationNative_GetLocaleInfoStringNative) + DllImportEntry(GlobalizationNative_GetLocaleNameNative) + DllImportEntry(GlobalizationNative_GetLocalesNative) + DllImportEntry(GlobalizationNative_GetLocaleTimeFormatNative) + DllImportEntry(GlobalizationNative_GetSortKeyNative) + DllImportEntry(GlobalizationNative_GetTimeZoneDisplayNameNative) + DllImportEntry(GlobalizationNative_IndexOfNative) + DllImportEntry(GlobalizationNative_IsNormalizedNative) + DllImportEntry(GlobalizationNative_NormalizeStringNative) + DllImportEntry(GlobalizationNative_StartsWithNative) +#endif + DllImportEntry(GlobalizationNative_ToAscii) + DllImportEntry(GlobalizationNative_ToUnicode) + DllImportEntry(GlobalizationNative_InitOrdinalCasingPage) +}; + +EXTERN_C const void* GlobalizationResolveDllImport(const char* name); + +EXTERN_C const void* GlobalizationResolveDllImport(const char* name) +{ + return minipal_resolve_dllimport(s_globalizationNative, ARRAY_SIZE(s_globalizationNative), name); +} \ No newline at end of file diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_calendarData.h b/src/native/libs/System.HybridGlobalization.Native/pal_calendarData.h new file mode 100644 index 0000000000000..31ce76d869395 --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/pal_calendarData.h @@ -0,0 +1,119 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#pragma once + +#include + +#include "pal_locale.h" +#include "pal_compiler.h" +#include "pal_errors.h" + +/* +* These values should be kept in sync with System.Globalization.CalendarId +*/ +enum +{ + UNINITIALIZED_VALUE = 0, + GREGORIAN = 1, // Gregorian (localized) calendar + GREGORIAN_US = 2, // Gregorian (U.S.) calendar + JAPAN = 3, // Japanese Emperor Era calendar + /* SSS_WARNINGS_OFF */ + TAIWAN = 4, // Taiwan Era calendar /* SSS_WARNINGS_ON */ + KOREA = 5, // Korean Tangun Era calendar + HIJRI = 6, // Hijri (Arabic Lunar) calendar + THAI = 7, // Thai calendar + HEBREW = 8, // Hebrew (Lunar) calendar + GREGORIAN_ME_FRENCH = 9, // Gregorian Middle East French calendar + GREGORIAN_ARABIC = 10, // Gregorian Arabic calendar + GREGORIAN_XLIT_ENGLISH = 11, // Gregorian Transliterated English calendar + GREGORIAN_XLIT_FRENCH = 12, + // Note that all calendars after this point are MANAGED ONLY for now. + JULIAN = 13, + JAPANESELUNISOLAR = 14, + CHINESELUNISOLAR = 15, + SAKA = 16, // reserved to match Office but not implemented in our code + LUNAR_ETO_CHN = 17, // reserved to match Office but not implemented in our code + LUNAR_ETO_KOR = 18, // reserved to match Office but not implemented in our code + LUNAR_ETO_ROKUYOU = 19, // reserved to match Office but not implemented in our code + KOREANLUNISOLAR = 20, + TAIWANLUNISOLAR = 21, + PERSIAN = 22, + UMALQURA = 23, + LAST_CALENDAR = 23 // Last calendar ID +}; +typedef uint16_t CalendarId; + +/* +* These values should be kept in sync with System.Globalization.CalendarDataType +*/ +typedef enum +{ + CalendarData_Uninitialized = 0, + CalendarData_NativeName = 1, + CalendarData_MonthDay = 2, + CalendarData_ShortDates = 3, + CalendarData_LongDates = 4, + CalendarData_YearMonths = 5, + CalendarData_DayNames = 6, + CalendarData_AbbrevDayNames = 7, + CalendarData_MonthNames = 8, + CalendarData_AbbrevMonthNames = 9, + CalendarData_SuperShortDayNames = 10, + CalendarData_MonthGenitiveNames = 11, + CalendarData_AbbrevMonthGenitiveNames = 12, + CalendarData_EraNames = 13, + CalendarData_AbbrevEraNames = 14, +} CalendarDataType; + +#define GREGORIAN_NAME "gregorian" +#define JAPANESE_NAME "japanese" +#define BUDDHIST_NAME "buddhist" +#define HEBREW_NAME "hebrew" +#define DANGI_NAME "dangi" +#define PERSIAN_NAME "persian" +#define ISLAMIC_NAME "islamic" +#define ISLAMIC_UMALQURA_NAME "islamic-umalqura" +#define ROC_NAME "roc" + +// the function pointer definition for the callback used in EnumCalendarInfo +typedef void (PAL_CALLBACK_CALLTYPE *EnumCalendarInfoCallback)(const UChar*, const void*); + +PALEXPORT int32_t GlobalizationNative_GetCalendars(const UChar* localeName, + CalendarId* calendars, + int32_t calendarsCapacity); + +PALEXPORT ResultCode GlobalizationNative_GetCalendarInfo(const UChar* localeName, + CalendarId calendarId, + CalendarDataType dataType, + UChar* result, + int32_t resultCapacity); + +PALEXPORT int32_t GlobalizationNative_EnumCalendarInfo(EnumCalendarInfoCallback callback, + const UChar* localeName, + CalendarId calendarId, + CalendarDataType dataType, + const void* context); + +PALEXPORT int32_t GlobalizationNative_GetLatestJapaneseEra(void); + +PALEXPORT int32_t GlobalizationNative_GetJapaneseEraStartDate(int32_t era, + int32_t* startYear, + int32_t* startMonth, + int32_t* startDay); +#if defined(APPLE_HYBRID_GLOBALIZATION) +PALEXPORT const char* GlobalizationNative_GetCalendarInfoNative(const char* localeName, + CalendarId calendarId, + CalendarDataType dataType); + +PALEXPORT int32_t GlobalizationNative_GetCalendarsNative(const char* localeName, + CalendarId* calendars, + int32_t calendarsCapacity); + +PALEXPORT int32_t GlobalizationNative_GetLatestJapaneseEraNative(void); + +PALEXPORT int32_t GlobalizationNative_GetJapaneseEraStartDateNative(int32_t era, + int32_t* startYear, + int32_t* startMonth, + int32_t* startDay); +#endif diff --git a/src/native/libs/System.Globalization.Native/pal_calendarData.m b/src/native/libs/System.HybridGlobalization.Native/pal_calendarData.m similarity index 100% rename from src/native/libs/System.Globalization.Native/pal_calendarData.m rename to src/native/libs/System.HybridGlobalization.Native/pal_calendarData.m diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_casing.h b/src/native/libs/System.HybridGlobalization.Native/pal_casing.h new file mode 100644 index 0000000000000..5371ba3bb0886 --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/pal_casing.h @@ -0,0 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "pal_locale.h" +#include "pal_compiler.h" + +PALEXPORT void GlobalizationNative_InitOrdinalCasingPage(int32_t pageNumber, UChar* pTarget); + +PALEXPORT void GlobalizationNative_ChangeCase(const UChar* lpSrc, + int32_t cwSrcLength, + UChar* lpDst, + int32_t cwDstLength, + int32_t bToUpper); + +PALEXPORT void GlobalizationNative_ChangeCaseInvariant(const UChar* lpSrc, + int32_t cwSrcLength, + UChar* lpDst, + int32_t cwDstLength, + int32_t bToUpper); + +PALEXPORT void GlobalizationNative_ChangeCaseTurkish(const UChar* lpSrc, + int32_t cwSrcLength, + UChar* lpDst, + int32_t cwDstLength, + int32_t bToUpper); +#if defined(APPLE_HYBRID_GLOBALIZATION) +PALEXPORT int32_t GlobalizationNative_ChangeCaseNative(const uint16_t* localeName, + int32_t lNameLength, + const uint16_t* lpSrc, + int32_t cwSrcLength, + uint16_t* lpDst, + int32_t cwDstLength, + int32_t bToUpper); + +PALEXPORT int32_t GlobalizationNative_ChangeCaseInvariantNative(const uint16_t* lpSrc, + int32_t cwSrcLength, + uint16_t* lpDst, + int32_t cwDstLength, + int32_t bToUpper); +#endif diff --git a/src/native/libs/System.Globalization.Native/pal_casing.m b/src/native/libs/System.HybridGlobalization.Native/pal_casing.m similarity index 100% rename from src/native/libs/System.Globalization.Native/pal_casing.m rename to src/native/libs/System.HybridGlobalization.Native/pal_casing.m diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_collation.h b/src/native/libs/System.HybridGlobalization.Native/pal_collation.h new file mode 100644 index 0000000000000..b2ef6e1ed3d24 --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/pal_collation.h @@ -0,0 +1,110 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#pragma once + +#include "pal_locale.h" +#include "pal_compiler.h" +#include "pal_errors.h" + +typedef struct SortHandle SortHandle; +typedef struct _Range { + int32_t location; + int32_t length; +} Range; + +PALEXPORT ResultCode GlobalizationNative_GetSortHandle(const char* lpLocaleName, SortHandle** ppSortHandle); + +PALEXPORT void GlobalizationNative_CloseSortHandle(SortHandle* pSortHandle); + +// If we fail to get the sort version we will fallback to -1 as the sort version. +PALEXPORT int32_t GlobalizationNative_GetSortVersion(SortHandle* pSortHandle); + +PALEXPORT int32_t GlobalizationNative_CompareString(SortHandle* pSortHandle, + const UChar* lpStr1, + int32_t cwStr1Length, + const UChar* lpStr2, + int32_t cwStr2Length, + int32_t options); + +PALEXPORT int32_t GlobalizationNative_IndexOf(SortHandle* pSortHandle, + const UChar* lpTarget, + int32_t cwTargetLength, + const UChar* lpSource, + int32_t cwSourceLength, + int32_t options, + int32_t* pMatchedLength); + +PALEXPORT int32_t GlobalizationNative_LastIndexOf(SortHandle* pSortHandle, + const UChar* lpTarget, + int32_t cwTargetLength, + const UChar* lpSource, + int32_t cwSourceLength, + int32_t options, + int32_t* pMatchedLength); + +PALEXPORT int32_t GlobalizationNative_StartsWith(SortHandle* pSortHandle, + const UChar* lpTarget, + int32_t cwTargetLength, + const UChar* lpSource, + int32_t cwSourceLength, + int32_t options, + int32_t* pMatchedLength); + +PALEXPORT int32_t GlobalizationNative_EndsWith(SortHandle* pSortHandle, + const UChar* lpTarget, + int32_t cwTargetLength, + const UChar* lpSource, + int32_t cwSourceLength, + int32_t options, + int32_t* pMatchedLength); + +PALEXPORT int32_t GlobalizationNative_GetSortKey(SortHandle* pSortHandle, + const UChar* lpStr, + int32_t cwStrLength, + uint8_t* sortKey, + int32_t cbSortKeyLength, + int32_t options); +#if defined(APPLE_HYBRID_GLOBALIZATION) +PALEXPORT int32_t GlobalizationNative_CompareStringNative(const uint16_t* localeName, + int32_t lNameLength, + const uint16_t* lpTarget, + int32_t cwTargetLength, + const uint16_t* lpSource, + int32_t cwSourceLength, + int32_t options); + +PALEXPORT Range GlobalizationNative_IndexOfNative(const uint16_t* localeName, + int32_t lNameLength, + const uint16_t* lpTarget, + int32_t cwTargetLength, + const uint16_t* lpSource, + int32_t cwSourceLength, + int32_t options, + int32_t fromBeginning); + +PALEXPORT int32_t GlobalizationNative_StartsWithNative(const uint16_t* localeName, + int32_t lNameLength, + const uint16_t* lpPrefix, + int32_t cwPrefixLength, + const uint16_t* lpSource, + int32_t cwSourceLength, + int32_t options); + +PALEXPORT int32_t GlobalizationNative_EndsWithNative(const uint16_t* localeName, + int32_t lNameLength, + const uint16_t* lpSuffix, + int32_t cwSuffixLength, + const uint16_t* lpSource, + int32_t cwSourceLength, + int32_t options); + +PALEXPORT int32_t GlobalizationNative_GetSortKeyNative(const uint16_t* localeName, + int32_t lNameLength, + const UChar* lpStr, + int32_t cwStrLength, + uint8_t* sortKey, + int32_t cbSortKeyLength, + int32_t options); + +#endif diff --git a/src/native/libs/System.Globalization.Native/pal_collation.m b/src/native/libs/System.HybridGlobalization.Native/pal_collation.m similarity index 100% rename from src/native/libs/System.Globalization.Native/pal_collation.m rename to src/native/libs/System.HybridGlobalization.Native/pal_collation.m diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_common.c b/src/native/libs/System.HybridGlobalization.Native/pal_common.c new file mode 100644 index 0000000000000..5904a1c3bdbe2 --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/pal_common.c @@ -0,0 +1,21 @@ +#include +#include "pal_icushim_internal.h" +#include "pal_casing.h" + +void GlobalizationNative_InitOrdinalCasingPage(int32_t pageNumber, UChar* pTarget) +{ + pageNumber <<= 8; + for (int i = 0; i < 256; i++) + { + // Unfortunately, to ensure one-to-one simple mapping we have to call u_toupper on every character. + // Using string casing ICU APIs cannot give such results even when using NULL locale to force root behavior. + pTarget[i] = (UChar) u_toupper((UChar32)(pageNumber + i)); + } + + if (pageNumber == 0x0100) + { + // Disable Turkish I behavior on Ordinal operations + pTarget[0x31] = (UChar)0x0131; // Turkish lowercase i + pTarget[0x7F] = (UChar)0x017F; // // 017F;LATIN SMALL LETTER LONG S + } +} diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_errors.h b/src/native/libs/System.HybridGlobalization.Native/pal_errors.h new file mode 100644 index 0000000000000..84fe004902ee4 --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/pal_errors.h @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#pragma once + +/* +* These values should be kept in sync with +* Interop.GlobalizationInterop.ResultCode +*/ +typedef enum +{ + Success = 0, + UnknownError = 1, + InsufficientBuffer = 2, + OutOfMemory = 3, + InvalidCodePoint = 4 +} ResultCode; diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_errors_internal.h b/src/native/libs/System.HybridGlobalization.Native/pal_errors_internal.h new file mode 100644 index 0000000000000..1680335834736 --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/pal_errors_internal.h @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#pragma once + +#include "pal_icushim_internal.h" +#include "pal_errors.h" + +/* +Converts a UErrorCode to a ResultCode. +*/ +static ResultCode GetResultCode(UErrorCode err) +{ + if (err == U_BUFFER_OVERFLOW_ERROR || err == U_STRING_NOT_TERMINATED_WARNING) + { + return InsufficientBuffer; + } + + if (err == U_MEMORY_ALLOCATION_ERROR) + { + return OutOfMemory; + } + + if (U_SUCCESS(err)) + { + return Success; + } + + return UnknownError; +} diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_icushim.c b/src/native/libs/System.HybridGlobalization.Native/pal_icushim.c new file mode 100644 index 0000000000000..11b4ea6b748b3 --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/pal_icushim.c @@ -0,0 +1,575 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +#include +#include +#include "pal_icushim_internal.h" + +#if defined(TARGET_UNIX) +#include +#elif defined(TARGET_WINDOWS) +#include +#include +#include +#endif +#include +#include +#include + +#include "pal_icushim.h" + +// Define pointers to all the used ICU functions +#define PER_FUNCTION_BLOCK(fn, lib, required) TYPEOF(fn)* fn##_ptr; +FOR_ALL_ICU_FUNCTIONS +#undef PER_FUNCTION_BLOCK + +// 35 for the actual suffix, 1 for _ and 1 for '\0' +#define SYMBOL_CUSTOM_SUFFIX_SIZE 37 +#define SYMBOL_NAME_SIZE (128 + SYMBOL_CUSTOM_SUFFIX_SIZE) +#define MaxICUVersionStringWithSuffixLength (MaxICUVersionStringLength + SYMBOL_CUSTOM_SUFFIX_SIZE) + +#if defined(TARGET_WINDOWS) || defined(TARGET_OSX) || defined(TARGET_ANDROID) + +#define MaxICUVersionStringLength 33 + +#else + +#define VERSION_PREFIX_NONE "" +#define VERSION_PREFIX_SUSE "suse" + +// .[suse]x.x.x, considering the max number of decimal digits for each component +#define MaxICUVersionStringLength (sizeof(VERSION_PREFIX_SUSE) + 33) + +#endif + +static void* libicuuc = NULL; +static void* libicui18n = NULL; +ucol_setVariableTop_func ucol_setVariableTop_ptr = NULL; +ucol_safeClone_func ucol_safeClone_ptr = NULL; + +#if defined (TARGET_UNIX) + +#define PER_FUNCTION_BLOCK(fn, lib, required) \ + c_static_assert_msg((sizeof(#fn) + MaxICUVersionStringWithSuffixLength + 1) <= sizeof(symbolName), "The symbolName is too small for symbol " #fn); \ + snprintf(symbolName, SYMBOL_NAME_SIZE, #fn "%s", symbolVersion); \ + fn##_ptr = (TYPEOF(fn)*)dlsym(lib, symbolName); \ + if (fn##_ptr == NULL && required) { fprintf(stderr, "Cannot get symbol %s from " #lib "\nError: %s\n", symbolName, dlerror()); abort(); } + +static int FindSymbolVersion(int majorVer, int minorVer, int subVer, char* symbolName, char* symbolVersion, size_t symbolVersionLen, char* suffix) +{ + // Find out the format of the version string added to each symbol + // First try just the unversioned symbol + if (dlsym(libicuuc, "u_strlen") == NULL) + { + // Now try just the _majorVer added + snprintf(symbolVersion, symbolVersionLen, "_%d%s", majorVer, suffix); + snprintf(symbolName, SYMBOL_NAME_SIZE, "u_strlen%s", symbolVersion); + if (dlsym(libicuuc, symbolName) == NULL) + { + if (minorVer == -1) + return false; + + // Now try the _majorVer_minorVer added + snprintf(symbolVersion, symbolVersionLen, "_%d_%d%s", majorVer, minorVer, suffix); + snprintf(symbolName, SYMBOL_NAME_SIZE, "u_strlen%s", symbolVersion); + if (dlsym(libicuuc, symbolName) == NULL) + { + if (subVer == -1) + return false; + + // Finally, try the _majorVer_minorVer_subVer added + snprintf(symbolVersion, symbolVersionLen, "_%d_%d_%d%s", majorVer, minorVer, subVer, suffix); + snprintf(symbolName, SYMBOL_NAME_SIZE, "u_strlen%s", symbolVersion); + if (dlsym(libicuuc, symbolName) == NULL) + { + return false; + } + } + } + } + + return true; +} + +#endif // TARGET_UNIX + +#if defined(TARGET_WINDOWS) + +#define sscanf sscanf_s + +#define PER_FUNCTION_BLOCK(fn, lib, required) \ + sprintf_s(symbolName, SYMBOL_NAME_SIZE, #fn "%s", symbolVersion); \ + fn##_ptr = (TYPEOF(fn)*)GetProcAddress((HMODULE)lib, symbolName); \ + if (fn##_ptr == NULL && required) { fprintf(stderr, "Cannot get symbol %s from " #lib "\nError: %u\n", symbolName, GetLastError()); abort(); } + +static int FindICULibs(void) +{ + libicuuc = LoadLibraryExW(L"icu.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); + if (libicuuc == NULL) + { + // On Windows Server 2019, the ICU library is installed as icuuc.dll and icuin.dll. Try to load these. + libicuuc = LoadLibraryExW(L"icuuc.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); + if (libicuuc != NULL) + { + libicui18n = LoadLibraryExW(L"icuin.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); + if (libicui18n != NULL) + { + return true; + } + } + + return false; + } + + // Windows has a single dll for icu. + libicui18n = libicuuc; + return true; +} + +static int FindSymbolVersion(int majorVer, int minorVer, int subVer, char* symbolName, char* symbolVersion, size_t symbolVersionLen, char* suffix) +{ + HMODULE lib = (HMODULE)libicuuc; + // Find out the format of the version string added to each symbol + // First try just the unversioned symbol + if (GetProcAddress(lib, "u_strlen") == NULL) + { + // Now try just the _majorVer added + sprintf_s(symbolVersion, symbolVersionLen,"_%d%s", majorVer, suffix); + sprintf_s(symbolName, SYMBOL_NAME_SIZE, "u_strlen%s", symbolVersion); + if (GetProcAddress(lib, symbolName) == NULL) + { + if (minorVer == -1) + return false; + + // Now try the _majorVer_minorVer added + sprintf_s(symbolVersion, symbolVersionLen, "_%d_%d%s", majorVer, minorVer, suffix); + sprintf_s(symbolName, SYMBOL_NAME_SIZE, "u_strlen%s", symbolVersion); + if (GetProcAddress(lib, symbolName) == NULL) + { + if (subVer == -1) + return false; + // Finally, try the _majorVer_minorVer_subVer added + sprintf_s(symbolVersion, symbolVersionLen, "_%d_%d_%d%s", majorVer, minorVer, subVer, suffix); + sprintf_s(symbolName, SYMBOL_NAME_SIZE, "u_strlen%s", symbolVersion); + if (GetProcAddress(lib, symbolName) == NULL) + { + return false; + } + } + } + } + + return true; +} + +#elif defined(TARGET_OSX) + +static int FindICULibs(void) +{ +#ifndef OSX_ICU_LIBRARY_PATH + c_static_assert_msg(false, "The ICU Library path is not defined"); +#endif // OSX_ICU_LIBRARY_PATH + + // Usually OSX_ICU_LIBRARY_PATH is "/usr/lib/libicucore.dylib" + libicuuc = dlopen(OSX_ICU_LIBRARY_PATH, RTLD_LAZY); + + if (libicuuc == NULL) + { + return false; + } + + // in OSX all ICU APIs exist in the same library libicucore.A.dylib + libicui18n = libicuuc; + + return true; +} + +#elif defined(TARGET_ANDROID) + +// support ICU versions from 50-255 +#define MinICUVersion 50 +#define MaxICUVersion 255 + +static int FindICULibs(char* symbolName, char* symbolVersion) +{ + libicui18n = dlopen("libicui18n.so", RTLD_LAZY); + + if (libicui18n == NULL) + { + return false; + } + + libicuuc = dlopen("libicuuc.so", RTLD_LAZY); + + if (libicuuc == NULL) + { + return false; + } + + char symbolSuffix[SYMBOL_CUSTOM_SUFFIX_SIZE]=""; + for (int i = MinICUVersion; i <= MaxICUVersion; i++) + { + if (FindSymbolVersion(i, -1, -1, symbolName, symbolVersion, MaxICUVersionStringLength, symbolSuffix)) + { + return true; + } + } + + fprintf(stderr, "Cannot determine ICU version."); + return false; +} + +#else // !TARGET_WINDOWS && !TARGET_OSX && !TARGET_ANDROID + +// Version ranges to search for each of the three version components +// The rationale for major version range is that we support versions higher or +// equal to the version we are built against and less or equal to that version +// plus 30 to give us enough headspace. The ICU seems to version about twice +// a year. +// On some platforms (mainly Alpine Linux) we want to make our minimum version +// an earlier version than what we build that we know we support. +#define MinICUVersion 50 +#define MaxICUVersion (U_ICU_VERSION_MAJOR_NUM + 30) +#define MinMinorICUVersion 1 +#define MaxMinorICUVersion 5 +#define MinSubICUVersion 1 +#define MaxSubICUVersion 5 + +#define VERSIONED_LIB_NAME_LEN 64 + +// Get filename of an ICU library with the requested version in the name +// There are three possible cases of the version components values: +// 1. Only majorVer is not equal to -1 => result is baseFileName.majorver +// 2. Only majorVer and minorVer are not equal to -1 => result is baseFileName.majorver.minorVer +// 3. All components are not equal to -1 => result is baseFileName.majorver.minorVer.subver +static void GetVersionedLibFileName(const char* baseFileName, int majorVer, int minorVer, int subVer, const char* versionPrefix, char* result) +{ + assert(majorVer != -1); + + int nameLen = snprintf(result, VERSIONED_LIB_NAME_LEN, "%s.%s%d", baseFileName, versionPrefix, majorVer); + + if (minorVer != -1) + { + assert(nameLen <= VERSIONED_LIB_NAME_LEN); + nameLen += snprintf(result + nameLen, (size_t)(VERSIONED_LIB_NAME_LEN - nameLen), ".%d", minorVer); + if (subVer != -1) + { + assert(nameLen <= VERSIONED_LIB_NAME_LEN); + snprintf(result + nameLen, (size_t)(VERSIONED_LIB_NAME_LEN - nameLen), ".%d", subVer); + } + } +} + +// Try to open the necessary ICU libraries +static int OpenICULibraries(int majorVer, int minorVer, int subVer, const char* versionPrefix, char* symbolName, char* symbolVersion) +{ + char libicuucName[VERSIONED_LIB_NAME_LEN]; + char libicui18nName[VERSIONED_LIB_NAME_LEN]; + + c_static_assert_msg(sizeof("libicuuc.so") + MaxICUVersionStringLength <= sizeof(libicuucName), "The libicuucName is too small"); + GetVersionedLibFileName("libicuuc.so", majorVer, minorVer, subVer, versionPrefix, libicuucName); + + c_static_assert_msg(sizeof("libicui18n.so") + MaxICUVersionStringLength <= sizeof(libicui18nName), "The libicui18nName is too small"); + GetVersionedLibFileName("libicui18n.so", majorVer, minorVer, subVer, versionPrefix, libicui18nName); + + libicuuc = dlopen(libicuucName, RTLD_LAZY); + if (libicuuc != NULL) + { + char symbolSuffix[SYMBOL_CUSTOM_SUFFIX_SIZE]=""; + if (FindSymbolVersion(majorVer, minorVer, subVer, symbolName, symbolVersion, MaxICUVersionStringLength, symbolSuffix)) + { + libicui18n = dlopen(libicui18nName, RTLD_LAZY); + } + if (libicui18n == NULL) + { + dlclose(libicuuc); + libicuuc = NULL; + } + } + + return libicuuc != NULL; +} + +// Select libraries using the version override specified by the CLR_ICU_VERSION_OVERRIDE +// environment variable. +// The format of the string in this variable is majorVer[.minorVer[.subVer]] (the brackets +// indicate optional parts). +static int FindLibUsingOverride(const char* versionPrefix, char* symbolName, char* symbolVersion) +{ + char* versionOverride = getenv("CLR_ICU_VERSION_OVERRIDE"); + if (versionOverride != NULL) + { + if (strcmp(versionOverride, "build") == 0) + { + if (OpenICULibraries(U_ICU_VERSION_MAJOR_NUM, -1, -1, versionPrefix, symbolName, symbolVersion)) + { + return true; + } + } + else + { + int first = -1; + int second = -1; + int third = -1; + + int matches = sscanf(versionOverride, "%d.%d.%d", &first, &second, &third); + if (matches > 0) + { + if (OpenICULibraries(first, second, third, versionPrefix, symbolName, symbolVersion)) + { + return true; + } + } + } + } + + return false; +} + +// Search for library files with names including the major version. +static int FindLibWithMajorVersion(const char* versionPrefix, char* symbolName, char* symbolVersion) +{ + // ICU packaging documentation (http://userguide.icu-project.org/packaging) + // describes applications link against the major (e.g. libicuuc.so.54). + + // Select the highest supported version of ICU present on the local machine + for (int i = MaxICUVersion; i >= MinICUVersion; i--) + { + if (OpenICULibraries(i, -1, -1, versionPrefix, symbolName, symbolVersion)) + { + return true; + } + } + + return false; +} + +// Select the highest supported version of ICU present on the local machine +// Search for library files with names including the major and minor version. +static int FindLibWithMajorMinorVersion(const char* versionPrefix, char* symbolName, char* symbolVersion) +{ + for (int i = MaxICUVersion; i >= MinICUVersion; i--) + { + for (int j = MaxMinorICUVersion; j >= MinMinorICUVersion; j--) + { + if (OpenICULibraries(i, j, -1, versionPrefix, symbolName, symbolVersion)) + { + return true; + } + } + } + + return false; +} + +// Select the highest supported version of ICU present on the local machine +// Search for library files with names including the major, minor and sub version. +static int FindLibWithMajorMinorSubVersion(const char* versionPrefix, char* symbolName, char* symbolVersion) +{ + for (int i = MaxICUVersion; i >= MinICUVersion; i--) + { + for (int j = MaxMinorICUVersion; j >= MinMinorICUVersion; j--) + { + for (int k = MaxSubICUVersion; k >= MinSubICUVersion; k--) + { + if (OpenICULibraries(i, j, k, versionPrefix, symbolName, symbolVersion)) + { + return true; + } + } + } + } + + return false; +} + + +static int FindICULibs(const char* versionPrefix, char* symbolName, char* symbolVersion) +{ + return FindLibUsingOverride(versionPrefix, symbolName, symbolVersion) || + FindLibWithMajorVersion(versionPrefix, symbolName, symbolVersion) || + FindLibWithMajorMinorVersion(versionPrefix, symbolName, symbolVersion) || + FindLibWithMajorMinorSubVersion(versionPrefix, symbolName, symbolVersion); +} + +#endif + +static void ValidateICUDataCanLoad(void) +{ + UVersionInfo version; + UErrorCode err = U_ZERO_ERROR; + ulocdata_getCLDRVersion(version, &err); + + if (U_FAILURE(err)) + { + fprintf(stderr, "Could not load ICU data. UErrorCode: %d\n", err); + abort(); + } +} + +static void InitializeUColClonePointers(char* symbolVersion) +{ + if (ucol_clone_ptr != NULL) + { + return; + } + +#if defined(TARGET_WINDOWS) + char symbolName[SYMBOL_NAME_SIZE]; + sprintf_s(symbolName, SYMBOL_NAME_SIZE, "ucol_safeClone%s", symbolVersion); + ucol_safeClone_ptr = (ucol_safeClone_func)GetProcAddress((HMODULE)libicui18n, symbolName); +#else + char symbolName[SYMBOL_NAME_SIZE]; + snprintf(symbolName, SYMBOL_NAME_SIZE, "ucol_safeClone%s", symbolVersion); + ucol_safeClone_ptr = (ucol_safeClone_func)dlsym(libicui18n, symbolName); +#endif // defined(TARGET_WINDOWS) + + if (ucol_safeClone_ptr == NULL) + { + fprintf(stderr, "Cannot get the symbols of ICU APIs ucol_safeClone or ucol_clone.\n"); + abort(); + } +} + +static void InitializeVariableMaxAndTopPointers(char* symbolVersion) +{ + if (ucol_setMaxVariable_ptr != NULL) + { + return; + } + +#if defined(TARGET_OSX) || defined(TARGET_ANDROID) + // OSX and Android always run against ICU version which has ucol_setMaxVariable. + // We shouldn't come here. + (void)symbolVersion; + assert(false); +#elif defined(TARGET_WINDOWS) + char symbolName[SYMBOL_NAME_SIZE]; + sprintf_s(symbolName, SYMBOL_NAME_SIZE, "ucol_setVariableTop%s", symbolVersion); + ucol_setVariableTop_ptr = (ucol_setVariableTop_func)GetProcAddress((HMODULE)libicui18n, symbolName); +#else + char symbolName[SYMBOL_NAME_SIZE]; + snprintf(symbolName, SYMBOL_NAME_SIZE, "ucol_setVariableTop%s", symbolVersion); + ucol_setVariableTop_ptr = (ucol_setVariableTop_func)dlsym(libicui18n, symbolName); +#endif // defined(TARGET_OSX) || defined(TARGET_ANDROID) + + if (ucol_setVariableTop_ptr == NULL) + { + fprintf(stderr, "Cannot get the symbols of ICU APIs ucol_setMaxVariable or ucol_setVariableTop.\n"); + abort(); + } +} + +// GlobalizationNative_LoadICU +// This method get called from the managed side during the globalization initialization. +// This method shouldn't get called at all if we are running in globalization invariant mode +// return 0 if failed to load ICU and 1 otherwise +int32_t GlobalizationNative_LoadICU(void) +{ + char symbolName[SYMBOL_NAME_SIZE]; + char symbolVersion[MaxICUVersionStringLength + 1]=""; + +#if defined(TARGET_WINDOWS) || defined(TARGET_OSX) + + if (!FindICULibs()) + { + return false; + } + +#elif defined(TARGET_ANDROID) + if (!FindICULibs(symbolName, symbolVersion)) + { + return false; + } +#else + if (!FindICULibs(VERSION_PREFIX_NONE, symbolName, symbolVersion)) + { + if (!FindICULibs(VERSION_PREFIX_SUSE, symbolName, symbolVersion)) + { + return false; + } + } +#endif // TARGET_WINDOWS || TARGET_OSX + +#if defined(ANDROID_FORCE_ICU_DATA_DIR) + setenv ("ICU_DATA", "/system/usr/icu/", 0); +#endif + FOR_ALL_ICU_FUNCTIONS + ValidateICUDataCanLoad(); + + InitializeVariableMaxAndTopPointers(symbolVersion); + InitializeUColClonePointers(symbolVersion); + + return true; +} + +void GlobalizationNative_InitICUFunctions(void* icuuc, void* icuin, const char* version, const char* suffix) +{ + assert(icuuc != NULL); + assert(icuin != NULL); + assert(version != NULL); + + libicuuc = icuuc; + libicui18n = icuin; + int major = -1; + int minor = -1; + int build = -1; + + char symbolName[SYMBOL_NAME_SIZE]; + char symbolVersion[MaxICUVersionStringWithSuffixLength + 1]=""; + char symbolSuffix[SYMBOL_CUSTOM_SUFFIX_SIZE]=""; + + if (strlen(version) > (size_t)MaxICUVersionStringLength) + { + fprintf(stderr, "The resolved version \"%s\" from System.Globalization.AppLocalIcu switch has to be < %zu chars long.\n", version, (size_t)MaxICUVersionStringLength); + abort(); + } + + sscanf(version, "%d.%d.%d", &major, &minor, &build); + + if (suffix != NULL) + { + size_t suffixAllowedSize = SYMBOL_CUSTOM_SUFFIX_SIZE - 2; // SYMBOL_CUSTOM_SUFFIX_SIZE considers `_` and `\0`. + if (strlen(suffix) > suffixAllowedSize) + { + fprintf(stderr, "The resolved suffix \"%s\" from System.Globalization.AppLocalIcu switch has to be < %zu chars long.\n", suffix, suffixAllowedSize); + abort(); + } + + assert(strlen(suffix) + 1 <= SYMBOL_CUSTOM_SUFFIX_SIZE); + +#if defined(TARGET_WINDOWS) + sprintf_s(symbolSuffix, SYMBOL_CUSTOM_SUFFIX_SIZE, "_%s", suffix); +#else + snprintf(symbolSuffix, SYMBOL_CUSTOM_SUFFIX_SIZE, "_%s", suffix); +#endif + } + + if(!FindSymbolVersion(major, minor, build, symbolName, symbolVersion, MaxICUVersionStringWithSuffixLength, symbolSuffix)) + { + fprintf(stderr, "Could not find symbol: %s from libicuuc\n", symbolName); + abort(); + } + + FOR_ALL_ICU_FUNCTIONS + ValidateICUDataCanLoad(); + + InitializeVariableMaxAndTopPointers(symbolVersion); + InitializeUColClonePointers(symbolVersion); +} + +#undef PER_FUNCTION_BLOCK + +// GlobalizationNative_GetICUVersion +// return the current loaded ICU version +int32_t GlobalizationNative_GetICUVersion(void) +{ + if (u_getVersion_ptr == NULL) + return 0; + + UVersionInfo versionInfo; + u_getVersion(versionInfo); + + return (versionInfo[0] << 24) + (versionInfo[1] << 16) + (versionInfo[2] << 8) + versionInfo[3]; +} diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_icushim.h b/src/native/libs/System.HybridGlobalization.Native/pal_icushim.h new file mode 100644 index 0000000000000..ec4dea95dc119 --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/pal_icushim.h @@ -0,0 +1,16 @@ + +#pragma once + +#include "pal_compiler.h" + +PALEXPORT int32_t GlobalizationNative_LoadICU(void); + +PALEXPORT void GlobalizationNative_InitICUFunctions(void* icuuc, void* icuin, const char* version, const char* suffix); + +PALEXPORT int32_t GlobalizationNative_GetICUVersion(void); + +#if defined(STATIC_ICU) + +PALEXPORT int32_t GlobalizationNative_LoadICUData(const char* path); + +#endif diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_icushim_internal.h b/src/native/libs/System.HybridGlobalization.Native/pal_icushim_internal.h new file mode 100644 index 0000000000000..bb19906effd92 --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/pal_icushim_internal.h @@ -0,0 +1,386 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +// Enable calling ICU functions through shims to enable support for +// multiple versions of ICU. + +#pragma once + +#if defined(TARGET_UNIX) || defined(TARGET_WASI) + +#include "config.h" + +#if defined(TARGET_ANDROID) +#include "pal_icushim_internal_android.h" +#else + +#if !defined(LOCAL_BUILD) +#define U_DISABLE_RENAMING 1 +#endif + +// All ICU headers need to be included here so that all function prototypes are +// available before the function pointers are declared below. +#if defined(APPLE_HYBRID_GLOBALIZATION) +#include +#include +#include +#else +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif +#endif + +#elif defined(TARGET_WINDOWS) + +#include "icu.h" + +#define HAVE_SET_MAX_VARIABLE 1 +#define UDAT_STANDALONE_SHORTER_WEEKDAYS 1 + +#endif + +#include "pal_compiler.h" + +#if !defined(STATIC_ICU) + +#if !defined(TARGET_ANDROID) +// (U_ICU_VERSION_MAJOR_NUM < 52) +// The following APIs are not supported in the ICU versions less than 52. We need to define them manually. +// We have to do runtime check before using the pointers to these APIs. That is why these are listed in the FOR_ALL_OPTIONAL_ICU_FUNCTIONS list. +U_CAPI void U_EXPORT2 ucol_setMaxVariable(UCollator* coll, UColReorderCode group, UErrorCode* pErrorCode); +U_CAPI int32_t U_EXPORT2 ucal_getTimeZoneIDForWindowsID(const UChar* winid, int32_t len, const char* region, UChar* id, int32_t idCapacity, UErrorCode* status); +U_CAPI int32_t U_EXPORT2 ucal_getWindowsTimeZoneID(const UChar* id, int32_t len, UChar* winid, int32_t winidCapacity, UErrorCode* status); + +// (U_ICU_VERSION_MAJOR_NUM < 71) +// The following API is not supported in the ICU versions less than 71. We need to define it manually. +// We have to do runtime check before using the pointers to this API. That is why these are listed in the FOR_ALL_OPTIONAL_ICU_FUNCTIONS list. +U_CAPI UCollator* U_EXPORT2 ucol_clone(const UCollator* coll, UErrorCode* status); + +// ucol_setVariableTop is a deprecated function on the newer ICU versions and ucol_setMaxVariable should be used instead. +// As we can run against ICU versions which do not support ucol_setMaxVariable, we will dynamically try to get the pointer +// to ucol_setVariableTop when we could not get a pointer to ucol_setMaxVariable. +typedef uint32_t (U_EXPORT2 *ucol_setVariableTop_func)(UCollator* coll, const UChar* varTop, int32_t len, UErrorCode* status); + +// ucol_safeClone is deprecated in ICU version 71. We have to handle it manually to avoid getting a build break when referencing it in the code. +typedef UCollator* (U_EXPORT2 *ucol_safeClone_func)(const UCollator* coll, void* stackBuffer, int32_t* pBufferSize, UErrorCode* status); + +#else // !defined(TARGET_ANDROID) + +typedef uint32_t (*ucol_setVariableTop_func)(UCollator* coll, const UChar* varTop, int32_t len, UErrorCode* status); +typedef UCollator* (*ucol_safeClone_func)(const UCollator* coll, void* stackBuffer, int32_t* pBufferSize, UErrorCode* status); + +#endif // !defined(TARGET_ANDROID) + +extern ucol_setVariableTop_func ucol_setVariableTop_ptr; +extern ucol_safeClone_func ucol_safeClone_ptr; + +// List of all functions from the ICU libraries that are used in the System.Globalization.Native.so +#define FOR_ALL_UNCONDITIONAL_ICU_FUNCTIONS \ + PER_FUNCTION_BLOCK(u_charsToUChars, libicuuc, true) \ + PER_FUNCTION_BLOCK(u_getVersion, libicuuc, true) \ + PER_FUNCTION_BLOCK(u_strcmp, libicuuc, true) \ + PER_FUNCTION_BLOCK(u_strcpy, libicuuc, true) \ + PER_FUNCTION_BLOCK(u_strlen, libicuuc, true) \ + PER_FUNCTION_BLOCK(u_strncpy, libicuuc, true) \ + PER_FUNCTION_BLOCK(u_tolower, libicuuc, true) \ + PER_FUNCTION_BLOCK(u_toupper, libicuuc, true) \ + PER_FUNCTION_BLOCK(u_uastrncpy, libicuuc, true) \ + PER_FUNCTION_BLOCK(ubrk_close, libicuuc, true) \ + PER_FUNCTION_BLOCK(ubrk_openRules, libicuuc, true) \ + PER_FUNCTION_BLOCK(ucal_add, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucal_close, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucal_get, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucal_getAttribute, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucal_getKeywordValuesForLocale, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucal_getLimit, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucal_getNow, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucal_getTimeZoneDisplayName, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucal_open, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucal_openTimeZoneIDEnumeration, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucal_set, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucal_setMillis, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucol_close, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucol_closeElements, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucol_getOffset, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucol_getRules, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucol_getSortKey, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucol_getStrength, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucol_getVersion, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucol_next, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucol_previous, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucol_open, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucol_openElements, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucol_openRules, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucol_setAttribute, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucol_strcoll, libicui18n, true) \ + PER_FUNCTION_BLOCK(udat_close, libicui18n, true) \ + PER_FUNCTION_BLOCK(udat_countSymbols, libicui18n, true) \ + PER_FUNCTION_BLOCK(udat_format, libicui18n, true) \ + PER_FUNCTION_BLOCK(udat_getSymbols, libicui18n, true) \ + PER_FUNCTION_BLOCK(udat_open, libicui18n, true) \ + PER_FUNCTION_BLOCK(udat_setCalendar, libicui18n, true) \ + PER_FUNCTION_BLOCK(udat_toPattern, libicui18n, true) \ + PER_FUNCTION_BLOCK(udatpg_close, libicui18n, true) \ + PER_FUNCTION_BLOCK(udatpg_getBestPattern, libicui18n, true) \ + PER_FUNCTION_BLOCK(udatpg_open, libicui18n, true) \ + PER_FUNCTION_BLOCK(uenum_close, libicuuc, true) \ + PER_FUNCTION_BLOCK(uenum_count, libicuuc, true) \ + PER_FUNCTION_BLOCK(uenum_next, libicuuc, true) \ + PER_FUNCTION_BLOCK(uidna_close, libicuuc, true) \ + PER_FUNCTION_BLOCK(uidna_nameToASCII, libicuuc, true) \ + PER_FUNCTION_BLOCK(uidna_nameToUnicode, libicuuc, true) \ + PER_FUNCTION_BLOCK(uidna_openUTS46, libicuuc, true) \ + PER_FUNCTION_BLOCK(uloc_canonicalize, libicuuc, true) \ + PER_FUNCTION_BLOCK(uloc_countAvailable, libicuuc, true) \ + PER_FUNCTION_BLOCK(uloc_getAvailable, libicuuc, true) \ + PER_FUNCTION_BLOCK(uloc_getBaseName, libicuuc, true) \ + PER_FUNCTION_BLOCK(uloc_getCharacterOrientation, libicuuc, true) \ + PER_FUNCTION_BLOCK(uloc_getCountry, libicuuc, true) \ + PER_FUNCTION_BLOCK(uloc_getDefault, libicuuc, true) \ + PER_FUNCTION_BLOCK(uloc_getDisplayCountry, libicuuc, true) \ + PER_FUNCTION_BLOCK(uloc_getDisplayLanguage, libicuuc, true) \ + PER_FUNCTION_BLOCK(uloc_getDisplayName, libicuuc, true) \ + PER_FUNCTION_BLOCK(uloc_getISO3Country, libicuuc, true) \ + PER_FUNCTION_BLOCK(uloc_getISO3Language, libicuuc, true) \ + PER_FUNCTION_BLOCK(uloc_getKeywordValue, libicuuc, true) \ + PER_FUNCTION_BLOCK(uloc_getLanguage, libicuuc, true) \ + PER_FUNCTION_BLOCK(uloc_getLCID, libicuuc, true) \ + PER_FUNCTION_BLOCK(uloc_getName, libicuuc, true) \ + PER_FUNCTION_BLOCK(uloc_getParent, libicuuc, true) \ + PER_FUNCTION_BLOCK(uloc_setKeywordValue, libicuuc, true) \ + PER_FUNCTION_BLOCK(ulocdata_getCLDRVersion, libicui18n, true) \ + PER_FUNCTION_BLOCK(ulocdata_getMeasurementSystem, libicui18n, true) \ + PER_FUNCTION_BLOCK(unorm2_getNFCInstance, libicuuc, true) \ + PER_FUNCTION_BLOCK(unorm2_getNFDInstance, libicuuc, true) \ + PER_FUNCTION_BLOCK(unorm2_getNFKCInstance, libicuuc, true) \ + PER_FUNCTION_BLOCK(unorm2_getNFKDInstance, libicuuc, true) \ + PER_FUNCTION_BLOCK(unorm2_isNormalized, libicuuc, true) \ + PER_FUNCTION_BLOCK(unorm2_normalize, libicuuc, true) \ + PER_FUNCTION_BLOCK(unum_close, libicui18n, true) \ + PER_FUNCTION_BLOCK(unum_getAttribute, libicui18n, true) \ + PER_FUNCTION_BLOCK(unum_getSymbol, libicui18n, true) \ + PER_FUNCTION_BLOCK(unum_open, libicui18n, true) \ + PER_FUNCTION_BLOCK(unum_toPattern, libicui18n, true) \ + PER_FUNCTION_BLOCK(ures_close, libicuuc, true) \ + PER_FUNCTION_BLOCK(ures_getByKey, libicuuc, true) \ + PER_FUNCTION_BLOCK(ures_getSize, libicuuc, true) \ + PER_FUNCTION_BLOCK(ures_getStringByIndex, libicuuc, true) \ + PER_FUNCTION_BLOCK(ures_open, libicuuc, true) \ + PER_FUNCTION_BLOCK(usearch_close, libicui18n, true) \ + PER_FUNCTION_BLOCK(usearch_first, libicui18n, true) \ + PER_FUNCTION_BLOCK(usearch_getBreakIterator, libicui18n, true) \ + PER_FUNCTION_BLOCK(usearch_getMatchedLength, libicui18n, true) \ + PER_FUNCTION_BLOCK(usearch_last, libicui18n, true) \ + PER_FUNCTION_BLOCK(usearch_openFromCollator, libicui18n, true) \ + PER_FUNCTION_BLOCK(usearch_setPattern, libicui18n, true) \ + PER_FUNCTION_BLOCK(usearch_setText, libicui18n, true) + +#if defined(TARGET_WINDOWS) +#define FOR_ALL_OS_CONDITIONAL_ICU_FUNCTIONS \ + PER_FUNCTION_BLOCK(ucurr_forLocale, libicuuc, true) \ + PER_FUNCTION_BLOCK(ucurr_getName, libicuuc, true) \ + PER_FUNCTION_BLOCK(uldn_close, libicuuc, true) \ + PER_FUNCTION_BLOCK(uldn_keyValueDisplayName, libicuuc, true) \ + PER_FUNCTION_BLOCK(uldn_open, libicuuc, true) +#else + // Unix ICU is dynamically resolved at runtime and these APIs in old versions + // of ICU were in libicui18n +#define FOR_ALL_OS_CONDITIONAL_ICU_FUNCTIONS \ + PER_FUNCTION_BLOCK(ucurr_forLocale, libicui18n, true) \ + PER_FUNCTION_BLOCK(ucurr_getName, libicui18n, true) \ + PER_FUNCTION_BLOCK(uldn_close, libicui18n, true) \ + PER_FUNCTION_BLOCK(uldn_keyValueDisplayName, libicui18n, true) \ + PER_FUNCTION_BLOCK(uldn_open, libicui18n, true) +#endif + +// The following are the list of the ICU APIs which are optional. If these APIs exist in the ICU version we load at runtime, then we'll use it. +// Otherwise, we'll just not provide the functionality to users which needed these APIs. +#define FOR_ALL_OPTIONAL_ICU_FUNCTIONS \ + PER_FUNCTION_BLOCK(ucal_getWindowsTimeZoneID, libicui18n, false) \ + PER_FUNCTION_BLOCK(ucal_getTimeZoneIDForWindowsID, libicui18n, false) \ + PER_FUNCTION_BLOCK(ucol_setMaxVariable, libicui18n, false) \ + PER_FUNCTION_BLOCK(ucol_clone, libicui18n, false) + +#define FOR_ALL_ICU_FUNCTIONS \ + FOR_ALL_UNCONDITIONAL_ICU_FUNCTIONS \ + FOR_ALL_OPTIONAL_ICU_FUNCTIONS \ + FOR_ALL_OS_CONDITIONAL_ICU_FUNCTIONS + +// Declare pointers to all the used ICU functions +#define PER_FUNCTION_BLOCK(fn, lib, required) EXTERN_C TYPEOF(fn)* fn##_ptr; +FOR_ALL_ICU_FUNCTIONS +#undef PER_FUNCTION_BLOCK + +// Redefine all calls to ICU functions as calls through pointers that are set +// to the functions of the selected version of ICU in the initialization. +#define u_charsToUChars(...) u_charsToUChars_ptr(__VA_ARGS__) +#define u_getVersion(...) u_getVersion_ptr(__VA_ARGS__) +#define u_strcmp(...) u_strcmp_ptr(__VA_ARGS__) +#define u_strcpy(...) u_strcpy_ptr(__VA_ARGS__) +#define u_strlen(...) u_strlen_ptr(__VA_ARGS__) +#define u_strncpy(...) u_strncpy_ptr(__VA_ARGS__) +#define u_tolower(...) u_tolower_ptr(__VA_ARGS__) +#define u_toupper(...) u_toupper_ptr(__VA_ARGS__) +#define u_uastrncpy(...) u_uastrncpy_ptr(__VA_ARGS__) +#define ubrk_close(...) ubrk_close_ptr(__VA_ARGS__) +#define ubrk_openRules(...) ubrk_openRules_ptr(__VA_ARGS__) +#define ucal_add(...) ucal_add_ptr(__VA_ARGS__) +#define ucal_close(...) ucal_close_ptr(__VA_ARGS__) +#define ucal_get(...) ucal_get_ptr(__VA_ARGS__) +#define ucal_getAttribute(...) ucal_getAttribute_ptr(__VA_ARGS__) +#define ucal_getKeywordValuesForLocale(...) ucal_getKeywordValuesForLocale_ptr(__VA_ARGS__) +#define ucal_getLimit(...) ucal_getLimit_ptr(__VA_ARGS__) +#define ucal_getNow(...) ucal_getNow_ptr(__VA_ARGS__) +#define ucal_getTimeZoneDisplayName(...) ucal_getTimeZoneDisplayName_ptr(__VA_ARGS__) +#define ucal_getTimeZoneIDForWindowsID(...) ucal_getTimeZoneIDForWindowsID_ptr(__VA_ARGS__) +#define ucal_getWindowsTimeZoneID(...) ucal_getWindowsTimeZoneID_ptr(__VA_ARGS__) +#define ucal_open(...) ucal_open_ptr(__VA_ARGS__) +#define ucal_openTimeZoneIDEnumeration(...) ucal_openTimeZoneIDEnumeration_ptr(__VA_ARGS__) +#define ucal_set(...) ucal_set_ptr(__VA_ARGS__) +#define ucal_setMillis(...) ucal_setMillis_ptr(__VA_ARGS__) +#define ucol_clone(...) ucol_clone_ptr(__VA_ARGS__) +#define ucol_close(...) ucol_close_ptr(__VA_ARGS__) +#define ucol_closeElements(...) ucol_closeElements_ptr(__VA_ARGS__) +#define ucol_getOffset(...) ucol_getOffset_ptr(__VA_ARGS__) +#define ucol_getRules(...) ucol_getRules_ptr(__VA_ARGS__) +#define ucol_getSortKey(...) ucol_getSortKey_ptr(__VA_ARGS__) +#define ucol_getStrength(...) ucol_getStrength_ptr(__VA_ARGS__) +#define ucol_getVersion(...) ucol_getVersion_ptr(__VA_ARGS__) +#define ucol_next(...) ucol_next_ptr(__VA_ARGS__) +#define ucol_previous(...) ucol_previous_ptr(__VA_ARGS__) +#define ucol_open(...) ucol_open_ptr(__VA_ARGS__) +#define ucol_openElements(...) ucol_openElements_ptr(__VA_ARGS__) +#define ucol_openRules(...) ucol_openRules_ptr(__VA_ARGS__) +#define ucol_setAttribute(...) ucol_setAttribute_ptr(__VA_ARGS__) +#define ucol_setMaxVariable(...) ucol_setMaxVariable_ptr(__VA_ARGS__) +#define ucol_strcoll(...) ucol_strcoll_ptr(__VA_ARGS__) +#define ucurr_forLocale(...) ucurr_forLocale_ptr(__VA_ARGS__) +#define ucurr_getName(...) ucurr_getName_ptr(__VA_ARGS__) +#define udat_close(...) udat_close_ptr(__VA_ARGS__) +#define udat_countSymbols(...) udat_countSymbols_ptr(__VA_ARGS__) +#define udat_format(...) udat_format_ptr(__VA_ARGS__) +#define udat_getSymbols(...) udat_getSymbols_ptr(__VA_ARGS__) +#define udat_open(...) udat_open_ptr(__VA_ARGS__) +#define udat_setCalendar(...) udat_setCalendar_ptr(__VA_ARGS__) +#define udat_toPattern(...) udat_toPattern_ptr(__VA_ARGS__) +#define udatpg_close(...) udatpg_close_ptr(__VA_ARGS__) +#define udatpg_getBestPattern(...) udatpg_getBestPattern_ptr(__VA_ARGS__) +#define udatpg_open(...) udatpg_open_ptr(__VA_ARGS__) +#define uenum_close(...) uenum_close_ptr(__VA_ARGS__) +#define uenum_count(...) uenum_count_ptr(__VA_ARGS__) +#define uenum_next(...) uenum_next_ptr(__VA_ARGS__) +#define uidna_close(...) uidna_close_ptr(__VA_ARGS__) +#define uidna_nameToASCII(...) uidna_nameToASCII_ptr(__VA_ARGS__) +#define uidna_nameToUnicode(...) uidna_nameToUnicode_ptr(__VA_ARGS__) +#define uidna_openUTS46(...) uidna_openUTS46_ptr(__VA_ARGS__) +#define uldn_close(...) uldn_close_ptr(__VA_ARGS__) +#define uldn_keyValueDisplayName(...) uldn_keyValueDisplayName_ptr(__VA_ARGS__) +#define uldn_open(...) uldn_open_ptr(__VA_ARGS__) +#define uloc_canonicalize(...) uloc_canonicalize_ptr(__VA_ARGS__) +#define uloc_countAvailable(...) uloc_countAvailable_ptr(__VA_ARGS__) +#define uloc_getAvailable(...) uloc_getAvailable_ptr(__VA_ARGS__) +#define uloc_getBaseName(...) uloc_getBaseName_ptr(__VA_ARGS__) +#define uloc_getCharacterOrientation(...) uloc_getCharacterOrientation_ptr(__VA_ARGS__) +#define uloc_getCountry(...) uloc_getCountry_ptr(__VA_ARGS__) +#define uloc_getDefault(...) uloc_getDefault_ptr(__VA_ARGS__) +#define uloc_getDisplayCountry(...) uloc_getDisplayCountry_ptr(__VA_ARGS__) +#define uloc_getDisplayLanguage(...) uloc_getDisplayLanguage_ptr(__VA_ARGS__) +#define uloc_getDisplayName(...) uloc_getDisplayName_ptr(__VA_ARGS__) +#define uloc_getISO3Country(...) uloc_getISO3Country_ptr(__VA_ARGS__) +#define uloc_getISO3Language(...) uloc_getISO3Language_ptr(__VA_ARGS__) +#define uloc_getKeywordValue(...) uloc_getKeywordValue_ptr(__VA_ARGS__) +#define uloc_getLanguage(...) uloc_getLanguage_ptr(__VA_ARGS__) +#define uloc_getLCID(...) uloc_getLCID_ptr(__VA_ARGS__) +#define uloc_getName(...) uloc_getName_ptr(__VA_ARGS__) +#define uloc_getParent(...) uloc_getParent_ptr(__VA_ARGS__) +#define uloc_setKeywordValue(...) uloc_setKeywordValue_ptr(__VA_ARGS__) +#define ulocdata_getCLDRVersion(...) ulocdata_getCLDRVersion_ptr(__VA_ARGS__) +#define ulocdata_getMeasurementSystem(...) ulocdata_getMeasurementSystem_ptr(__VA_ARGS__) +#define unorm2_getNFCInstance(...) unorm2_getNFCInstance_ptr(__VA_ARGS__) +#define unorm2_getNFDInstance(...) unorm2_getNFDInstance_ptr(__VA_ARGS__) +#define unorm2_getNFKCInstance(...) unorm2_getNFKCInstance_ptr(__VA_ARGS__) +#define unorm2_getNFKDInstance(...) unorm2_getNFKDInstance_ptr(__VA_ARGS__) +#define unorm2_isNormalized(...) unorm2_isNormalized_ptr(__VA_ARGS__) +#define unorm2_normalize(...) unorm2_normalize_ptr(__VA_ARGS__) +#define unum_close(...) unum_close_ptr(__VA_ARGS__) +#define unum_getAttribute(...) unum_getAttribute_ptr(__VA_ARGS__) +#define unum_getSymbol(...) unum_getSymbol_ptr(__VA_ARGS__) +#define unum_open(...) unum_open_ptr(__VA_ARGS__) +#define unum_toPattern(...) unum_toPattern_ptr(__VA_ARGS__) +#define ures_close(...) ures_close_ptr(__VA_ARGS__) +#define ures_getByKey(...) ures_getByKey_ptr(__VA_ARGS__) +#define ures_getSize(...) ures_getSize_ptr(__VA_ARGS__) +#define ures_getStringByIndex(...) ures_getStringByIndex_ptr(__VA_ARGS__) +#define ures_open(...) ures_open_ptr(__VA_ARGS__) +#define usearch_close(...) usearch_close_ptr(__VA_ARGS__) +#define usearch_first(...) usearch_first_ptr(__VA_ARGS__) +#define usearch_getBreakIterator(...) usearch_getBreakIterator_ptr(__VA_ARGS__) +#define usearch_getMatchedLength(...) usearch_getMatchedLength_ptr(__VA_ARGS__) +#define usearch_last(...) usearch_last_ptr(__VA_ARGS__) +#define usearch_openFromCollator(...) usearch_openFromCollator_ptr(__VA_ARGS__) +#define usearch_reset(...) usearch_reset_ptr(__VA_ARGS__) +#define usearch_setPattern(...) usearch_setPattern_ptr(__VA_ARGS__) +#define usearch_setText(...) usearch_setText_ptr(__VA_ARGS__) + +#else // !defined(STATIC_ICU) + +#define ucal_getWindowsTimeZoneID_ptr ucal_getWindowsTimeZoneID +#define ucal_getTimeZoneIDForWindowsID_ptr ucal_getTimeZoneIDForWindowsID + +#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) +const char* GlobalizationNative_GetICUDataPathRelativeToAppBundleRoot(const char* path); +const char* GlobalizationNative_GetICUDataPathFallback(void); +#endif + +#endif // !defined(STATIC_ICU) +#if defined(APPLE_HYBRID_GLOBALIZATION) +/** + * Append a code point to a string, overwriting 1 or 2 code units. + * The offset points to the current end of the string contents + * and is advanced (post-increment). + * "Safe" macro, checks for a valid code point. + * Converts code points outside of Basic Multilingual Plane into + * corresponding surrogate pairs if sufficient space in the string. + * High surrogate range: 0xD800 - 0xDBFF + * Low surrogate range: 0xDC00 - 0xDFFF + * If the code point is not valid or a trail surrogate does not fit, + * then isError is set to true. + * + * @param buffer const uint16_t * string buffer + * @param offset string offset, must be offset= (capacity)) /* insufficiently sized destination buffer */ { \ + (isError) = InsufficientBuffer; \ + } else if ((uint32_t)(codePoint) > 0x10ffff) /* invalid code point */ { \ + (isError) = InvalidCodePoint; \ + } else if ((uint32_t)(codePoint) <= 0xffff) { \ + (buffer)[(offset)++] = (uint16_t)(codePoint); \ + } else { \ + (buffer)[(offset)++] = (uint16_t)(((codePoint) >> 10) + 0xd7c0); \ + (buffer)[(offset)++] = (uint16_t)(((codePoint)&0x3ff) | 0xdc00); \ + } \ +} +#endif \ No newline at end of file diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_icushim_internal_android.h b/src/native/libs/System.HybridGlobalization.Native/pal_icushim_internal_android.h new file mode 100644 index 0000000000000..424f72597dc7d --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/pal_icushim_internal_android.h @@ -0,0 +1,542 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +// definitions for ICU types and functions available in Android, +// extracted from ICU header files + +#pragma once + +#define U_MAX_VERSION_LENGTH 4 + +#define U_SUCCESS(x) ((x)<=U_ZERO_ERROR) +#define U_FAILURE(x) ((x)>U_ZERO_ERROR) + +typedef struct UCollator UCollator; +typedef struct UCollationElements UCollationElements; +typedef struct UEnumeration UEnumeration; +typedef struct UIDNA UIDNA; +typedef struct UNormalizer2 UNormalizer2; +typedef struct ULocaleDisplayNames ULocaleDisplayNames; +typedef struct UResourceBundle UResourceBundle; +typedef struct UStringSearch UStringSearch; +typedef struct UBreakIterator UBreakIterator; + +typedef int8_t UBool; +typedef uint16_t UChar; +typedef int32_t UChar32; +typedef double UDate; +typedef uint8_t UVersionInfo[U_MAX_VERSION_LENGTH]; + +typedef void* UNumberFormat; +typedef void* UDateFormat; +typedef void* UDateTimePatternGenerator; +typedef void* UCalendar; + +#ifndef TRUE +# define TRUE 1 +#endif +#ifndef FALSE +# define FALSE 0 +#endif + +#define USEARCH_DONE -1 + +#define UCOL_NULLORDER ((int32_t)0xFFFFFFFF) +#define UCOL_BUILDER_VERSION 9 +#define UCOL_RUNTIME_VERSION 9 + +#define ULOC_FULLNAME_CAPACITY 157 +#define ULOC_LANG_CAPACITY 12 +#define ULOC_KEYWORDS_CAPACITY 96 +#define ULOC_ENGLISH "en" +#define ULOC_US "en_US" + +#define U16_IS_LEAD(c) (((c)&0xfffffc00)==0xd800) +#define U16_IS_TRAIL(c) (((c)&0xfffffc00)==0xdc00) +#define U16_SURROGATE_OFFSET ((0xd800<<10UL)+0xdc00-0x10000) + +#define U16_GET_SUPPLEMENTARY(lead, trail) \ + (((UChar32)(lead)<<10UL)+(UChar32)(trail)-U16_SURROGATE_OFFSET) + +#define U16_APPEND(s, i, capacity, c, isError) { \ + if((uint32_t)(c)<=0xffff) { \ + (s)[(i)++]=(uint16_t)(c); \ + } else if((uint32_t)(c)<=0x10ffff && (i)+1<(capacity)) { \ + (s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \ + (s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \ + } else { \ + (isError)=TRUE; \ + } \ +} + +#define U16_NEXT(s, i, length, c) { \ + (c)=(s)[(i)++]; \ + if(U16_IS_LEAD(c)) { \ + uint16_t __c2; \ + if((i)!=(length) && U16_IS_TRAIL(__c2=(s)[(i)])) { \ + ++(i); \ + (c)=U16_GET_SUPPLEMENTARY((c), __c2); \ + } \ + } \ +} + +#define U16_FWD_1(s, i, length) { \ + if(U16_IS_LEAD((s)[(i)++]) && (i)!=(length) && U16_IS_TRAIL((s)[i])) { \ + ++(i); \ + } \ +} + +#define UIDNA_INFO_INITIALIZER { \ + (int16_t)sizeof(UIDNAInfo), \ + FALSE, FALSE, \ + 0, 0, 0 } + +typedef enum UErrorCode { + U_STRING_NOT_TERMINATED_WARNING = -124, + U_USING_DEFAULT_WARNING = -127, + U_ZERO_ERROR = 0, + U_ILLEGAL_ARGUMENT_ERROR = 1, + U_INTERNAL_PROGRAM_ERROR = 5, + U_MEMORY_ALLOCATION_ERROR = 7, + U_BUFFER_OVERFLOW_ERROR = 15, + U_UNSUPPORTED_ERROR = 16, +} UErrorCode; + +typedef enum UCalendarDateFields { + UCAL_ERA, + UCAL_YEAR, + UCAL_MONTH, + UCAL_WEEK_OF_YEAR, + UCAL_WEEK_OF_MONTH, + UCAL_DATE, + UCAL_DAY_OF_YEAR, + UCAL_DAY_OF_WEEK, + UCAL_DAY_OF_WEEK_IN_MONTH, + UCAL_AM_PM, + UCAL_HOUR, + UCAL_HOUR_OF_DAY, + UCAL_MINUTE, + UCAL_SECOND, + UCAL_MILLISECOND, + UCAL_ZONE_OFFSET, + UCAL_DST_OFFSET, + UCAL_YEAR_WOY, + UCAL_DOW_LOCAL, + UCAL_EXTENDED_YEAR, + UCAL_JULIAN_DAY, + UCAL_MILLISECONDS_IN_DAY, + UCAL_IS_LEAP_MONTH, + UCAL_FIELD_COUNT, + UCAL_DAY_OF_MONTH = UCAL_DATE +} UCalendarDateFields; + +typedef enum UColAttribute { + UCOL_FRENCH_COLLATION, + UCOL_ALTERNATE_HANDLING, + UCOL_CASE_FIRST, + UCOL_CASE_LEVEL, + UCOL_NORMALIZATION_MODE, + UCOL_DECOMPOSITION_MODE = UCOL_NORMALIZATION_MODE, + UCOL_STRENGTH, + UCOL_NUMERIC_COLLATION = UCOL_STRENGTH + 2, + UCOL_ATTRIBUTE_COUNT +} UColAttribute; + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wduplicate-enum" +typedef enum UColAttributeValue { + UCOL_DEFAULT = -1, + UCOL_PRIMARY = 0, + UCOL_SECONDARY = 1, + UCOL_TERTIARY = 2, + UCOL_DEFAULT_STRENGTH = UCOL_TERTIARY, + UCOL_CE_STRENGTH_LIMIT, + UCOL_QUATERNARY=3, + UCOL_IDENTICAL=15, + UCOL_STRENGTH_LIMIT, + UCOL_OFF = 16, + UCOL_ON = 17, + UCOL_SHIFTED = 20, + UCOL_NON_IGNORABLE = 21, + UCOL_LOWER_FIRST = 24, + UCOL_UPPER_FIRST = 25, +} UColAttributeValue; +#pragma clang diagnostic pop + +typedef UColAttributeValue UCollationStrength; + +typedef enum UCalendarAttribute { + UCAL_LENIENT, + UCAL_FIRST_DAY_OF_WEEK, + UCAL_MINIMAL_DAYS_IN_FIRST_WEEK, + UCAL_REPEATED_WALL_TIME, + UCAL_SKIPPED_WALL_TIME +} UCalendarAttribute; + +typedef enum UCalendarLimitType { + UCAL_MINIMUM, + UCAL_MAXIMUM, + UCAL_GREATEST_MINIMUM, + UCAL_LEAST_MAXIMUM, + UCAL_ACTUAL_MINIMUM, + UCAL_ACTUAL_MAXIMUM +} UCalendarLimitType; + +typedef enum UCalendarDisplayNameType { + UCAL_STANDARD, + UCAL_SHORT_STANDARD, + UCAL_DST, + UCAL_SHORT_DST +} UCalendarDisplayNameType; + +typedef enum ULayoutType { + ULOC_LAYOUT_LTR = 0, + ULOC_LAYOUT_RTL = 1, + ULOC_LAYOUT_TTB = 2, + ULOC_LAYOUT_BTT = 3, + ULOC_LAYOUT_UNKNOWN +} ULayoutType; + +typedef enum UDialectHandling { + ULDN_STANDARD_NAMES = 0, + ULDN_DIALECT_NAMES +} UDialectHandling; + +typedef enum UMeasurementSystem { + UMS_SI, + UMS_US, + UMS_UK, +} UMeasurementSystem; + +typedef enum UNumberFormatSymbol { + UNUM_DECIMAL_SEPARATOR_SYMBOL = 0, + UNUM_GROUPING_SEPARATOR_SYMBOL = 1, + UNUM_PATTERN_SEPARATOR_SYMBOL = 2, + UNUM_PERCENT_SYMBOL = 3, + UNUM_ZERO_DIGIT_SYMBOL = 4, + UNUM_DIGIT_SYMBOL = 5, + UNUM_MINUS_SIGN_SYMBOL = 6, + UNUM_PLUS_SIGN_SYMBOL = 7, + UNUM_CURRENCY_SYMBOL = 8, + UNUM_INTL_CURRENCY_SYMBOL = 9, + UNUM_MONETARY_SEPARATOR_SYMBOL = 10, + UNUM_EXPONENTIAL_SYMBOL = 11, + UNUM_PERMILL_SYMBOL = 12, + UNUM_PAD_ESCAPE_SYMBOL = 13, + UNUM_INFINITY_SYMBOL = 14, + UNUM_NAN_SYMBOL = 15, + UNUM_SIGNIFICANT_DIGIT_SYMBOL = 16, + UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL = 17, + UNUM_ONE_DIGIT_SYMBOL = 18, + UNUM_TWO_DIGIT_SYMBOL = 19, + UNUM_THREE_DIGIT_SYMBOL = 20, + UNUM_FOUR_DIGIT_SYMBOL = 21, + UNUM_FIVE_DIGIT_SYMBOL = 22, + UNUM_SIX_DIGIT_SYMBOL = 23, + UNUM_SEVEN_DIGIT_SYMBOL = 24, + UNUM_EIGHT_DIGIT_SYMBOL = 25, + UNUM_NINE_DIGIT_SYMBOL = 26, + UNUM_EXPONENT_MULTIPLICATION_SYMBOL = 27, +} UNumberFormatSymbol; + +typedef enum UNumberFormatAttribute { + UNUM_PARSE_INT_ONLY, + UNUM_GROUPING_USED, + UNUM_DECIMAL_ALWAYS_SHOWN, + UNUM_MAX_INTEGER_DIGITS, + UNUM_MIN_INTEGER_DIGITS, + UNUM_INTEGER_DIGITS, + UNUM_MAX_FRACTION_DIGITS, + UNUM_MIN_FRACTION_DIGITS, + UNUM_FRACTION_DIGITS, + UNUM_MULTIPLIER, + UNUM_GROUPING_SIZE, + UNUM_ROUNDING_MODE, + UNUM_ROUNDING_INCREMENT, + UNUM_FORMAT_WIDTH, + UNUM_PADDING_POSITION, + UNUM_SECONDARY_GROUPING_SIZE, + UNUM_SIGNIFICANT_DIGITS_USED, + UNUM_MIN_SIGNIFICANT_DIGITS, + UNUM_MAX_SIGNIFICANT_DIGITS, + UNUM_LENIENT_PARSE, + UNUM_SCALE = 21, + UNUM_CURRENCY_USAGE = 23, + UNUM_MAX_NONBOOLEAN_ATTRIBUTE = 0x0FFF, + UNUM_FORMAT_FAIL_IF_MORE_THAN_MAX_DIGITS = 0x1000, + UNUM_PARSE_NO_EXPONENT, + UNUM_PARSE_DECIMAL_MARK_REQUIRED = 0x1002, + UNUM_LIMIT_BOOLEAN_ATTRIBUTE = 0x1003 +} UNumberFormatAttribute; + +typedef enum UNumberFormatStyle { + UNUM_PATTERN_DECIMAL = 0, + UNUM_DECIMAL = 1, + UNUM_CURRENCY = 2, + UNUM_PERCENT = 3, + UNUM_SCIENTIFIC = 4, + UNUM_SPELLOUT = 5, + UNUM_ORDINAL = 6, + UNUM_DURATION = 7, + UNUM_NUMBERING_SYSTEM = 8, + UNUM_PATTERN_RULEBASED = 9, + UNUM_CURRENCY_ISO = 10, + UNUM_CURRENCY_PLURAL = 11, + UNUM_CURRENCY_ACCOUNTING = 12, + UNUM_CASH_CURRENCY = 13, + UNUM_DECIMAL_COMPACT_SHORT = 14, + UNUM_DECIMAL_COMPACT_LONG = 15, + UNUM_CURRENCY_STANDARD = 16, + UNUM_DEFAULT = UNUM_DECIMAL, + UNUM_IGNORE = UNUM_PATTERN_DECIMAL +} UNumberFormatStyle; + +typedef enum UScriptCode { + USCRIPT_UNKNOWN = 103, +} UScriptCode; + +typedef enum UColReorderCode { + UCOL_REORDER_CODE_DEFAULT = -1, + UCOL_REORDER_CODE_NONE = USCRIPT_UNKNOWN, + UCOL_REORDER_CODE_OTHERS = USCRIPT_UNKNOWN, + UCOL_REORDER_CODE_SPACE = 0x1000, + UCOL_REORDER_CODE_FIRST = UCOL_REORDER_CODE_SPACE, + UCOL_REORDER_CODE_PUNCTUATION = 0x1001, + UCOL_REORDER_CODE_SYMBOL = 0x1002, + UCOL_REORDER_CODE_CURRENCY = 0x1003, + UCOL_REORDER_CODE_DIGIT = 0x1004, +} UColReorderCode; + +typedef enum UDateFormatStyle { + UDAT_FULL, + UDAT_LONG, + UDAT_MEDIUM, + UDAT_SHORT, + UDAT_DEFAULT = UDAT_MEDIUM, + UDAT_RELATIVE = (1 << 7), + UDAT_FULL_RELATIVE = UDAT_FULL | UDAT_RELATIVE, + UDAT_LONG_RELATIVE = UDAT_LONG | UDAT_RELATIVE, + UDAT_MEDIUM_RELATIVE = UDAT_MEDIUM | UDAT_RELATIVE, + UDAT_SHORT_RELATIVE = UDAT_SHORT | UDAT_RELATIVE, + UDAT_NONE = -1, + UDAT_PATTERN = -2, +} UDateFormatStyle; + +typedef enum UDateFormatSymbolType { + UDAT_ERAS, + UDAT_MONTHS, + UDAT_SHORT_MONTHS, + UDAT_WEEKDAYS, + UDAT_SHORT_WEEKDAYS, + UDAT_AM_PMS, + UDAT_LOCALIZED_CHARS, + UDAT_ERA_NAMES, + UDAT_NARROW_MONTHS, + UDAT_NARROW_WEEKDAYS, + UDAT_STANDALONE_MONTHS, + UDAT_STANDALONE_SHORT_MONTHS, + UDAT_STANDALONE_NARROW_MONTHS, + UDAT_STANDALONE_WEEKDAYS, + UDAT_STANDALONE_SHORT_WEEKDAYS, + UDAT_STANDALONE_NARROW_WEEKDAYS, + UDAT_QUARTERS, + UDAT_SHORT_QUARTERS, + UDAT_STANDALONE_QUARTERS, + UDAT_STANDALONE_SHORT_QUARTERS, + UDAT_SHORTER_WEEKDAYS, + UDAT_STANDALONE_SHORTER_WEEKDAYS, + UDAT_CYCLIC_YEARS_WIDE, + UDAT_CYCLIC_YEARS_ABBREVIATED, + UDAT_CYCLIC_YEARS_NARROW, + UDAT_ZODIAC_NAMES_WIDE, + UDAT_ZODIAC_NAMES_ABBREVIATED, + UDAT_ZODIAC_NAMES_NARROW +} UDateFormatSymbolType; + +typedef enum UCurrNameStyle { + UCURR_SYMBOL_NAME, + UCURR_LONG_NAME +} UCurrNameStyle; + +typedef enum UCalendarType { + UCAL_TRADITIONAL, + UCAL_DEFAULT = UCAL_TRADITIONAL, + UCAL_GREGORIAN +} UCalendarType; + +typedef enum UCollationResult { + UCOL_EQUAL = 0, + UCOL_GREATER = 1, + UCOL_LESS = -1 +} UCollationResult; + +typedef enum USystemTimeZoneType { + UCAL_ZONE_TYPE_ANY, + UCAL_ZONE_TYPE_CANONICAL, + UCAL_ZONE_TYPE_CANONICAL_LOCATION +} USystemTimeZoneType; + +enum { + UIDNA_ERROR_EMPTY_LABEL = 1, + UIDNA_ERROR_LABEL_TOO_LONG = 2, + UIDNA_ERROR_DOMAIN_NAME_TOO_LONG = 4, + UIDNA_ERROR_LEADING_HYPHEN = 8, + UIDNA_ERROR_TRAILING_HYPHEN = 0x10, + UIDNA_ERROR_HYPHEN_3_4 = 0x20, + UIDNA_ERROR_LEADING_COMBINING_MARK = 0x40, + UIDNA_ERROR_DISALLOWED = 0x80, + UIDNA_ERROR_PUNYCODE = 0x100, + UIDNA_ERROR_LABEL_HAS_DOT = 0x200, + UIDNA_ERROR_INVALID_ACE_LABEL = 0x400, + UIDNA_ERROR_BIDI = 0x800, + UIDNA_ERROR_CONTEXTJ = 0x1000, + UIDNA_ERROR_CONTEXTO_PUNCTUATION = 0x2000, + UIDNA_ERROR_CONTEXTO_DIGITS = 0x4000 +}; + +enum { + UIDNA_DEFAULT = 0, + UIDNA_ALLOW_UNASSIGNED = 1, + UIDNA_USE_STD3_RULES = 2, + UIDNA_CHECK_BIDI = 4, + UIDNA_CHECK_CONTEXTJ = 8, + UIDNA_NONTRANSITIONAL_TO_ASCII = 0x10, + UIDNA_NONTRANSITIONAL_TO_UNICODE = 0x20, + UIDNA_CHECK_CONTEXTO = 0x40 +}; + +enum { + U_PARSE_CONTEXT_LEN = 16 +}; + +typedef struct UParseError { + int32_t line; + int32_t offset; + UChar preContext[U_PARSE_CONTEXT_LEN]; + UChar postContext[U_PARSE_CONTEXT_LEN]; + +} UParseError; + +typedef struct UIDNAInfo { + int16_t size; + UBool isTransitionalDifferent; + UBool reservedB3; + uint32_t errors; + int32_t reservedI2; + int32_t reservedI3; +} UIDNAInfo; + +typedef struct UFieldPosition { + int32_t field; + int32_t beginIndex; + int32_t endIndex; +} UFieldPosition; + +void u_charsToUChars(const char * cs, UChar * us, int32_t length); +void u_getVersion(UVersionInfo versionArray); +int32_t u_strlen(const UChar * s); +int32_t u_strcmp(const UChar * s1, const UChar * s2); +UChar * u_strcpy(UChar * dst, const UChar * src); +UChar * u_strncpy(UChar * dst, const UChar * src, int32_t n); +UChar32 u_tolower(UChar32 c); +UChar32 u_toupper(UChar32 c); +UChar* u_uastrncpy(UChar * dst, const char * src, int32_t n); +void ubrk_close(UBreakIterator * bi); +UBreakIterator* ubrk_openRules(const UChar * rules, int32_t rulesLength, const UChar * text, int32_t textLength, UParseError * parseErr, UErrorCode * status); +void ucal_add(UCalendar * cal, UCalendarDateFields field, int32_t amount, UErrorCode * status); +void ucal_close(UCalendar * cal); +int32_t ucal_get(const UCalendar * cal, UCalendarDateFields field, UErrorCode * status); +int32_t ucal_getAttribute(const UCalendar * cal, UCalendarAttribute attr); +UEnumeration * ucal_getKeywordValuesForLocale(const char * key, const char * locale, UBool commonlyUsed, UErrorCode * status); +int32_t ucal_getLimit(const UCalendar * cal, UCalendarDateFields field, UCalendarLimitType type, UErrorCode * status); +UDate ucal_getNow(void); +int32_t ucal_getTimeZoneDisplayName(const UCalendar * cal, UCalendarDisplayNameType type, const char * locale, UChar * result, int32_t resultLength, UErrorCode * status); +int32_t ucal_getTimeZoneIDForWindowsID(const UChar * winid, int32_t len, const char * region, UChar * id, int32_t idCapacity, UErrorCode * status); +int32_t ucal_getWindowsTimeZoneID(const UChar * id, int32_t len, UChar * winid, int32_t winidCapacity, UErrorCode * status); +UCalendar * ucal_open(const UChar * zoneID, int32_t len, const char * locale, UCalendarType type, UErrorCode * status); +UEnumeration * ucal_openTimeZoneIDEnumeration(USystemTimeZoneType zoneType, const char * region, const int32_t * rawOffset, UErrorCode * ec); +void ucal_set(UCalendar * cal, UCalendarDateFields field, int32_t value); +void ucal_setMillis(UCalendar * cal, UDate dateTime, UErrorCode * status); +void ucol_close(UCollator * coll); +void ucol_closeElements(UCollationElements * elems); +int32_t ucol_getOffset(const UCollationElements *elems); +const UChar * ucol_getRules(const UCollator * coll, int32_t * length); +int32_t ucol_getSortKey(const UCollator * coll, const UChar * source, int32_t sourceLength, uint8_t * result, int32_t resultLength); +UCollationStrength ucol_getStrength(const UCollator * coll); +void ucol_getVersion(const UCollator * coll, UVersionInfo info); +int32_t ucol_next(UCollationElements * elems, UErrorCode * status); +int32_t ucol_previous(UCollationElements * elems, UErrorCode * status); +UCollator * ucol_open(const char * loc, UErrorCode * status); +UCollationElements * ucol_openElements(const UCollator * coll, const UChar * text, int32_t textLength, UErrorCode * status); +UCollator * ucol_openRules(const UChar * rules, int32_t rulesLength, UColAttributeValue normalizationMode, UCollationStrength strength, UParseError * parseError, UErrorCode * status); +UCollator * ucol_clone(const UCollator * coll, UErrorCode * status); +void ucol_setAttribute(UCollator * coll, UColAttribute attr, UColAttributeValue value, UErrorCode * status); +UCollationResult ucol_strcoll(const UCollator * coll, const UChar * source, int32_t sourceLength, const UChar * target, int32_t targetLength); +int32_t ucurr_forLocale(const char * locale, UChar * buff, int32_t buffCapacity, UErrorCode * ec); +const UChar * ucurr_getName(const UChar * currency, const char * locale, UCurrNameStyle nameStyle, UBool * isChoiceFormat, int32_t * len, UErrorCode * ec); +void udat_close(UDateFormat * format); +int32_t udat_countSymbols(const UDateFormat * fmt, UDateFormatSymbolType type); +int32_t udat_format(const UDateFormat * format, UDate dateToFormat, UChar * result, int32_t resultLength, UFieldPosition * position, UErrorCode * status); +int32_t udat_getSymbols(const UDateFormat * fmt, UDateFormatSymbolType type, int32_t symbolIndex, UChar * result, int32_t resultLength, UErrorCode * status); +UDateFormat * udat_open(UDateFormatStyle timeStyle, UDateFormatStyle dateStyle, const char * locale, const UChar * tzID, int32_t tzIDLength, const UChar * pattern, int32_t patternLength, UErrorCode * status); +void udat_setCalendar(UDateFormat * fmt, const UCalendar * calendarToSet); +int32_t udat_toPattern(const UDateFormat * fmt, UBool localized, UChar * result, int32_t resultLength, UErrorCode * status); +void udatpg_close(UDateTimePatternGenerator * dtpg); +int32_t udatpg_getBestPattern(UDateTimePatternGenerator * dtpg, const UChar * skeleton, int32_t length, UChar * bestPattern, int32_t capacity, UErrorCode * pErrorCode); +UDateTimePatternGenerator * udatpg_open(const char * locale, UErrorCode * pErrorCode); +void uenum_close(UEnumeration * en); +int32_t uenum_count(UEnumeration * en, UErrorCode * status); +const char * uenum_next(UEnumeration * en, int32_t * resultLength, UErrorCode * status); +void uidna_close(UIDNA * idna); +int32_t uidna_nameToASCII(const UIDNA * idna, const UChar * name, int32_t length, UChar * dest, int32_t capacity, UIDNAInfo * pInfo, UErrorCode * pErrorCode); +int32_t uidna_nameToUnicode(const UIDNA * idna, const UChar * name, int32_t length, UChar * dest, int32_t capacity, UIDNAInfo * pInfo, UErrorCode * pErrorCode); +UIDNA * uidna_openUTS46(uint32_t options, UErrorCode * pErrorCode); +void uldn_close(ULocaleDisplayNames * ldn); +int32_t uldn_keyValueDisplayName(const ULocaleDisplayNames * ldn, const char * key, const char * value, UChar * result, int32_t maxResultSize, UErrorCode * pErrorCode); +ULocaleDisplayNames * uldn_open(const char * locale, UDialectHandling dialectHandling, UErrorCode * pErrorCode); +int32_t uloc_canonicalize(const char * localeID, char * name, int32_t nameCapacity, UErrorCode * err); +int32_t uloc_countAvailable(void); +const char * uloc_getAvailable(int32_t n); +int32_t uloc_getBaseName(const char * localeID, char * name, int32_t nameCapacity, UErrorCode * err); +ULayoutType uloc_getCharacterOrientation(const char * localeId, UErrorCode * status); +int32_t uloc_getCountry(const char * localeID, char * country, int32_t countryCapacity, UErrorCode * err); +const char * uloc_getDefault(void); +int32_t uloc_getDisplayCountry(const char * locale, const char * displayLocale, UChar * country, int32_t countryCapacity, UErrorCode * status); +int32_t uloc_getDisplayLanguage(const char * locale, const char * displayLocale, UChar * language, int32_t languageCapacity, UErrorCode * status); +int32_t uloc_getDisplayName(const char * localeID, const char * inLocaleID, UChar * result, int32_t maxResultSize, UErrorCode * err); +const char * uloc_getISO3Country(const char * localeID); +const char * uloc_getISO3Language(const char * localeID); +int32_t uloc_getKeywordValue(const char * localeID, const char * keywordName, char * buffer, int32_t bufferCapacity, UErrorCode * status); +int32_t uloc_getLanguage(const char * localeID, char * language, int32_t languageCapacity, UErrorCode * err); +uint32_t uloc_getLCID(const char * localeID); +int32_t uloc_getName(const char * localeID, char * name, int32_t nameCapacity, UErrorCode * err); +int32_t uloc_getParent(const char * localeID, char * parent, int32_t parentCapacity, UErrorCode * err); +int32_t uloc_setKeywordValue(const char * keywordName, const char * keywordValue, char * buffer, int32_t bufferCapacity, UErrorCode * status); +void ulocdata_getCLDRVersion(UVersionInfo versionArray, UErrorCode * status); +UMeasurementSystem ulocdata_getMeasurementSystem(const char * localeID, UErrorCode * status); +const UNormalizer2 * unorm2_getNFCInstance(UErrorCode * pErrorCode); +const UNormalizer2 * unorm2_getNFDInstance(UErrorCode * pErrorCode); +const UNormalizer2 * unorm2_getNFKCInstance(UErrorCode * pErrorCode); +const UNormalizer2 * unorm2_getNFKDInstance(UErrorCode * pErrorCode); +UBool unorm2_isNormalized(const UNormalizer2 * norm2, const UChar * s, int32_t length, UErrorCode * pErrorCode); +int32_t unorm2_normalize(const UNormalizer2 * norm2, const UChar * src, int32_t length, UChar * dest, int32_t capacity, UErrorCode * pErrorCode); +void unum_close(UNumberFormat * fmt); +int32_t unum_getAttribute(const UNumberFormat * fmt, UNumberFormatAttribute attr); +int32_t unum_getSymbol(const UNumberFormat * fmt, UNumberFormatSymbol symbol, UChar * buffer, int32_t size, UErrorCode * status); +UNumberFormat * unum_open(UNumberFormatStyle style, const UChar * pattern, int32_t patternLength, const char * locale, UParseError * parseErr, UErrorCode * status); +int32_t unum_toPattern(const UNumberFormat * fmt, UBool isPatternLocalized, UChar * result, int32_t resultLength, UErrorCode * status); +void ures_close(UResourceBundle * resourceBundle); +UResourceBundle * ures_getByKey(const UResourceBundle * resourceBundle, const char * key, UResourceBundle * fillIn, UErrorCode * status); +int32_t ures_getSize(const UResourceBundle * resourceBundle); +const UChar * ures_getStringByIndex(const UResourceBundle * resourceBundle, int32_t indexS, int32_t * len, UErrorCode * status); +UResourceBundle * ures_open(const char * packageName, const char * locale, UErrorCode * status); +void usearch_close(UStringSearch * searchiter); +int32_t usearch_first(UStringSearch * strsrch, UErrorCode * status); +const UBreakIterator* usearch_getBreakIterator(const UStringSearch * strsrch); +int32_t usearch_getMatchedLength(const UStringSearch * strsrch); +int32_t usearch_last(UStringSearch * strsrch, UErrorCode * status); +UStringSearch * usearch_openFromCollator(const UChar * pattern, int32_t patternlength, const UChar * text, int32_t textlength, const UCollator * collator, UBreakIterator * breakiter, UErrorCode * status); +void usearch_setPattern(UStringSearch * strsrch, const UChar * pattern, int32_t patternlength, UErrorCode * status); +void usearch_setText(UStringSearch * strsrch, const UChar * text, int32_t textlength, UErrorCode * status); +void ucol_setMaxVariable(UCollator * coll, UColReorderCode group, UErrorCode * pErrorCode); diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_icushim_static.c b/src/native/libs/System.HybridGlobalization.Native/pal_icushim_static.c new file mode 100644 index 0000000000000..8b46bfffefbad --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/pal_icushim_static.c @@ -0,0 +1,253 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +#include +#include +#include +#include "pal_icushim_internal.h" +#include "pal_icushim.h" +#include +#include +#include + +#if !defined(APPLE_HYBRID_GLOBALIZATION) +#include +#endif + +#if defined(TARGET_UNIX) +#include +#elif defined(TARGET_WINDOWS) +#define strcasecmp _stricmp +#define strncasecmp _strnicmp +#endif +#if !defined(TARGET_MACCATALYST) && !defined(TARGET_IOS) && !defined(TARGET_TVOS) +static int32_t isLoaded = 0; +static int32_t isDataSet = 0; + +static void log_shim_error(const char* format, ...) +{ + va_list args; + + va_start(args, format); + vfprintf(stderr, format, args); + fputc('\n', stderr); + va_end(args); +} + +static void log_icu_error(const char* name, UErrorCode status) +{ + const char * statusText = u_errorName(status); + log_shim_error("ICU call %s failed with error #%d '%s'.", name, status, statusText); +} + +#if defined(ICU_TRACING) +static void U_CALLCONV icu_trace_data(const void* context, int32_t fnNumber, int32_t level, const char* fmt, va_list args) +{ + char buf[1000]; + utrace_vformat(buf, sizeof(buf), 0, fmt, args); + printf("[ICUDT] %s: %s\n", utrace_functionName(fnNumber), buf); +} +#endif + +static int32_t load_icu_data(const void* pData); + +#ifdef __EMSCRIPTEN__ +#include + +EMSCRIPTEN_KEEPALIVE int32_t mono_wasm_load_icu_data(const void* pData); + +EMSCRIPTEN_KEEPALIVE int32_t mono_wasm_load_icu_data(const void* pData) +{ + return load_icu_data(pData); +} + +/* + * driver.c calls this to make sure this file is linked, otherwise + * its not, meaning the EMSCRIPTEN_KEEPALIVE functions above + * are not kept. + */ +void mono_wasm_link_icu_shim(void); + +void mono_wasm_link_icu_shim(void) +{ +} + +#endif + +int32_t mono_wasi_load_icu_data(const void* pData); + +int32_t mono_wasi_load_icu_data(const void* pData) +{ + return load_icu_data(pData); +} + +static int32_t load_icu_data(const void* pData) +{ + + UErrorCode status = 0; + udata_setCommonData(pData, &status); + + if (U_FAILURE(status)) + { + log_icu_error("udata_setCommonData", status); + return 0; + } + else + { + +#if defined(ICU_TRACING) + // see https://github.com/unicode-org/icu/blob/master/docs/userguide/icu_data/tracing.md + utrace_setFunctions(0, 0, 0, icu_trace_data); + utrace_setLevel(UTRACE_VERBOSE); +#endif + isDataSet = 1; + return 1; + } +} + +static const char * +cstdlib_load_icu_data(const char *path) +{ + char *file_buf = NULL; + FILE *fp = fopen(path, "rb"); + + if (fp == NULL) + { + log_shim_error("Unable to load ICU dat file '%s'.", path); + goto error; + } + + if (fseek(fp, 0L, SEEK_END) != 0) + { + log_shim_error("Unable to determine size of the dat file"); + goto error; + } + + long file_buf_size = ftell(fp); + + if (file_buf_size == -1) + { + log_shim_error("Unable to determine size of the ICU dat file."); + goto error; + } + + file_buf = malloc(sizeof(char) * (unsigned long)(file_buf_size + 1)); + + if (file_buf == NULL) + { + log_shim_error("Unable to allocate enough to read the ICU dat file"); + goto error; + } + + if (fseek(fp, 0L, SEEK_SET) != 0) + { + log_shim_error("Unable to seek ICU dat file."); + goto error; + } + + fread(file_buf, sizeof(char), (unsigned long)file_buf_size, fp); + if (ferror( fp ) != 0) + { + log_shim_error("Unable to read ICU dat file"); + goto error; + } + + fclose(fp); + fp = NULL; + + return file_buf; + +error: + if (fp != NULL) + { + fclose(fp); + } + if (file_buf != NULL) + { + free(file_buf); + } + return NULL; +} + +int32_t +GlobalizationNative_LoadICUData(const char* path) +{ +#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) + if (path && path[0] != '/') + { + // if the path is relative, prepend the app bundle root + path = GlobalizationNative_GetICUDataPathRelativeToAppBundleRoot(path); + } + if (!path) + { + // fallback to icudt.dat in the app bundle resources in case the path isn't set + path = GlobalizationNative_GetICUDataPathFallback(); + } +#endif + + const char *icu_data = cstdlib_load_icu_data(path); + + if (icu_data == NULL) + { + log_shim_error("Failed to load ICU data."); + return 0; + } + + if (load_icu_data(icu_data) == 0) + { + log_shim_error("ICU BAD EXIT."); + return 0; + } + + return GlobalizationNative_LoadICU(); +} + +int32_t GlobalizationNative_LoadICU(void) +{ +#if !defined(LOCAL_BUILD) +// Static NativeAOT compilation does not have +// GlobalizationNative_LoadICUData() as entrypoint + if (!isDataSet) + { + // don't try to locate icudt.dat automatically if mono_wasm_load_icu_data wasn't called + // and fallback to invariant mode + return 0; + } +#endif + + UErrorCode status = 0; + UVersionInfo version; + // Request the CLDR version to perform basic ICU initialization and find out + // whether it worked. + ulocdata_getCLDRVersion(version, &status); + + if (U_FAILURE(status)) + { + log_icu_error("ulocdata_getCLDRVersion", status); + return 0; + } + + isLoaded = 1; + return 1; +} + +void GlobalizationNative_InitICUFunctions(void* icuuc, void* icuin, const char* version, const char* suffix) +{ + // no-op for static +} + +int32_t GlobalizationNative_GetICUVersion(void) +{ + // this method is only used from our tests + // this way we ensure we're testing on the right mode + // even though we can call u_getVersion without loading since it is statically linked. + if (!isLoaded) + return 0; + + UVersionInfo versionInfo; + u_getVersion(versionInfo); + + return (versionInfo[0] << 24) + (versionInfo[1] << 16) + (versionInfo[2] << 8) + versionInfo[3]; +} +#endif \ No newline at end of file diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_idna.c b/src/native/libs/System.HybridGlobalization.Native/pal_idna.c new file mode 100644 index 0000000000000..ac2b0bbaf2a4b --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/pal_idna.c @@ -0,0 +1,99 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +#include + +#include "pal_icushim_internal.h" +#include "pal_idna.h" + +#if defined(TARGET_WINDOWS) +// Windows icu headers doesn't define this member as it is marked as deprecated as of ICU 55. +enum { + UIDNA_ALLOW_UNASSIGNED=1 +}; +#endif + +static const uint32_t AllowUnassigned = 0x1; +static const uint32_t UseStd3AsciiRules = 0x2; + +static uint32_t GetOptions(uint32_t flags, uint32_t useToAsciiFlags) +{ + uint32_t options = UIDNA_CHECK_CONTEXTJ; + + if ((flags & AllowUnassigned) == AllowUnassigned) + { + options |= UIDNA_ALLOW_UNASSIGNED; + } + + if ((flags & UseStd3AsciiRules) == UseStd3AsciiRules) + { + options |= UIDNA_USE_STD3_RULES; + } + + if (useToAsciiFlags) + { + options |= UIDNA_NONTRANSITIONAL_TO_ASCII; + } + else + { + options |= UIDNA_NONTRANSITIONAL_TO_UNICODE; + } + + return options; +} + +/* +Function: +ToASCII + +Used by System.Globalization.IdnMapping.GetAsciiCore to convert an Unicode +domain name to ASCII + +Return values: +0: internal error during conversion. +>0: the length of the converted string (not including the null terminator). +*/ +int32_t GlobalizationNative_ToAscii( + uint32_t flags, const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength) +{ + UErrorCode err = U_ZERO_ERROR; + UIDNAInfo info = UIDNA_INFO_INITIALIZER; + + UIDNA* pIdna = uidna_openUTS46(GetOptions(flags, /* useToAsciiFlags */ 1), &err); + + int32_t asciiStrLen = uidna_nameToASCII(pIdna, lpSrc, cwSrcLength, lpDst, cwDstLength, &info, &err); + + // To have a consistent behavior with Windows, we mask out the error when having 2 hyphens in the third and fourth place. + info.errors &= (uint32_t)~UIDNA_ERROR_HYPHEN_3_4; + + uidna_close(pIdna); + + return ((U_SUCCESS(err) || (err == U_BUFFER_OVERFLOW_ERROR)) && (info.errors == 0)) ? asciiStrLen : 0; +} + +/* +Function: +ToUnicode + +Used by System.Globalization.IdnMapping.GetUnicodeCore to convert an ASCII name +to Unicode + +Return values: +0: internal error during conversion. +>0: the length of the converted string (not including the null terminator). +*/ +int32_t GlobalizationNative_ToUnicode( + uint32_t flags, const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength) +{ + UErrorCode err = U_ZERO_ERROR; + UIDNAInfo info = UIDNA_INFO_INITIALIZER; + + UIDNA* pIdna = uidna_openUTS46(GetOptions(flags, /* useToAsciiFlags */ 0), &err); + + int32_t unicodeStrLen = uidna_nameToUnicode(pIdna, lpSrc, cwSrcLength, lpDst, cwDstLength, &info, &err); + + uidna_close(pIdna); + + return ((U_SUCCESS(err) || (err == U_BUFFER_OVERFLOW_ERROR)) && (info.errors == 0)) ? unicodeStrLen : 0; +} diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_idna.h b/src/native/libs/System.HybridGlobalization.Native/pal_idna.h new file mode 100644 index 0000000000000..d50f90f36ad94 --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/pal_idna.h @@ -0,0 +1,20 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +#pragma once + +#include "pal_locale.h" +#include "pal_compiler.h" + +PALEXPORT int32_t GlobalizationNative_ToAscii(uint32_t flags, + const UChar* lpSrc, + int32_t cwSrcLength, + UChar* lpDst, + int32_t cwDstLength); + +PALEXPORT int32_t GlobalizationNative_ToUnicode(uint32_t flags, + const UChar* lpSrc, + int32_t cwSrcLength, + UChar* lpDst, + int32_t cwDstLength); diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_locale.h b/src/native/libs/System.HybridGlobalization.Native/pal_locale.h new file mode 100644 index 0000000000000..8ded749d3c11c --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/pal_locale.h @@ -0,0 +1,404 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#pragma once + +#include "pal_compiler.h" + +PALEXPORT int32_t GlobalizationNative_GetLocales(UChar *value, int32_t valueLength); + +PALEXPORT int32_t GlobalizationNative_GetLocaleName(const UChar* localeName, UChar* value, int32_t valueLength); + +PALEXPORT int32_t GlobalizationNative_GetDefaultLocaleName(UChar* value, int32_t valueLength); + +PALEXPORT int32_t GlobalizationNative_IsPredefinedLocale(const UChar* localeName); + +PALEXPORT int32_t GlobalizationNative_GetLocaleTimeFormat(const UChar* localeName, + int shortFormat, UChar* value, + int32_t valueLength); +#if defined(APPLE_HYBRID_GLOBALIZATION) + +PALEXPORT const char* GlobalizationNative_GetDefaultLocaleNameNative(void); + +PALEXPORT const char* GlobalizationNative_GetLocaleNameNative(const char* localeName); + +PALEXPORT const char* GlobalizationNative_GetLocaleTimeFormatNative(const char* localeName, int shortFormat); + +PALEXPORT int32_t GlobalizationNative_GetLocalesNative(UChar* locales, int32_t length); + +PALEXPORT int32_t GlobalizationNative_IsPredefinedLocaleNative(const char* localeName); + +/* ### Data tables **************************************************/ + +/** + * Table of language codes, both 2- and 3-letter, with preference + * given to 2-letter codes where possible. Includes 3-letter codes + * that lack a 2-letter equivalent. + * + * This list must be in sorted order. This list is returned directly + * to the user by some API. + * + * This list must be kept in sync with LANGUAGES_3, with corresponding + * entries matched. + * + * This table should be terminated with a NULL entry, followed by a + * second list, and another NULL entry. The first list is visible to + * user code when this array is returned by API. The second list + * contains codes we support, but do not expose through user API. + * + * Notes + * + * Tables updated per http://lcweb.loc.gov/standards/iso639-2/ to + * include the revisions up to 2001/7/27 *CWB* + * + * The 3 character codes are the terminology codes like RFC 3066. + * + * "in" "iw" "ji" "jw" & "sh" have been withdrawn but are still in the + * table but now at the end of the table because 3 character codes are + * duplicates. This avoids bad searches going from 3 to 2 character + * codes. + * + * The range qaa-qtz is reserved for local use + */ +/* Subsequent hand addition of selected languages */ +static const char * const LANGUAGES[] = { + "aa", "ab", "ace", "ach", "ada", "ady", "ae", "aeb", + "af", "afh", "agq", "ain", "ak", "akk", "akz", "ale", + "aln", "alt", "am", "an", "ang", "anp", "ar", "arc", + "arn", "aro", "arp", "arq", "ars", "arw", "ary", "arz", "as", + "asa", "ase", "ast", "av", "avk", "awa", "ay", "az", + "ba", "bal", "ban", "bar", "bas", "bax", "bbc", "bbj", + "be", "bej", "bem", "bew", "bez", "bfd", "bfq", "bg", + "bgn", "bho", "bi", "bik", "bin", "bjn", "bkm", "bla", + "bm", "bn", "bo", "bpy", "bqi", "br", "bra", "brh", + "brx", "bs", "bss", "bua", "bug", "bum", "byn", "byv", + "ca", "cad", "car", "cay", "cch", "ccp", "ce", "ceb", "cgg", + "ch", "chb", "chg", "chk", "chm", "chn", "cho", "chp", + "chr", "chy", "ckb", "co", "cop", "cps", "cr", "crh", + "cs", "csb", "cu", "cv", "cy", + "da", "dak", "dar", "dav", "de", "del", "den", "dgr", + "din", "dje", "doi", "dsb", "dtp", "dua", "dum", "dv", + "dyo", "dyu", "dz", "dzg", + "ebu", "ee", "efi", "egl", "egy", "eka", "el", "elx", + "en", "enm", "eo", "es", "esu", "et", "eu", "ewo", + "ext", + "fa", "fan", "fat", "ff", "fi", "fil", "fit", "fj", + "fo", "fon", "fr", "frc", "frm", "fro", "frp", "frr", + "frs", "fur", "fy", + "ga", "gaa", "gag", "gan", "gay", "gba", "gbz", "gd", + "gez", "gil", "gl", "glk", "gmh", "gn", "goh", "gom", + "gon", "gor", "got", "grb", "grc", "gsw", "gu", "guc", + "gur", "guz", "gv", "gwi", + "ha", "hai", "hak", "haw", "he", "hi", "hif", "hil", + "hit", "hmn", "ho", "hr", "hsb", "hsn", "ht", "hu", + "hup", "hy", "hz", + "ia", "iba", "ibb", "id", "ie", "ig", "ii", "ik", + "ilo", "inh", "io", "is", "it", "iu", "izh", + "ja", "jam", "jbo", "jgo", "jmc", "jpr", "jrb", "jut", + "jv", + "ka", "kaa", "kab", "kac", "kaj", "kam", "kaw", "kbd", + "kbl", "kcg", "kde", "kea", "ken", "kfo", "kg", "kgp", + "kha", "kho", "khq", "khw", "ki", "kiu", "kj", "kk", + "kkj", "kl", "kln", "km", "kmb", "kn", "ko", "koi", + "kok", "kos", "kpe", "kr", "krc", "kri", "krj", "krl", + "kru", "ks", "ksb", "ksf", "ksh", "ku", "kum", "kut", + "kv", "kw", "ky", + "la", "lad", "lag", "lah", "lam", "lb", "lez", "lfn", + "lg", "li", "lij", "liv", "lkt", "lmo", "ln", "lo", + "lol", "loz", "lrc", "lt", "ltg", "lu", "lua", "lui", + "lun", "luo", "lus", "luy", "lv", "lzh", "lzz", + "mad", "maf", "mag", "mai", "mak", "man", "mas", "mde", + "mdf", "mdh", "mdr", "men", "mer", "mfe", "mg", "mga", + "mgh", "mgo", "mh", "mi", "mic", "min", "mis", "mk", + "ml", "mn", "mnc", "mni", "mo", + "moh", "mos", "mr", "mrj", + "ms", "mt", "mua", "mul", "mus", "mwl", "mwr", "mwv", + "my", "mye", "myv", "mzn", + "na", "nan", "nap", "naq", "nb", "nd", "nds", "ne", + "new", "ng", "nia", "niu", "njo", "nl", "nmg", "nn", + "nnh", "no", "nog", "non", "nov", "nqo", "nr", "nso", + "nus", "nv", "nwc", "ny", "nym", "nyn", "nyo", "nzi", + "oc", "oj", "om", "or", "os", "osa", "ota", + "pa", "pag", "pal", "pam", "pap", "pau", "pcd", "pcm", "pdc", + "pdt", "peo", "pfl", "phn", "pi", "pl", "pms", "pnt", + "pon", "prg", "pro", "ps", "pt", + "qu", "quc", "qug", + "raj", "rap", "rar", "rgn", "rif", "rm", "rn", "ro", + "rof", "rom", "rtm", "ru", "rue", "rug", "rup", + "rw", "rwk", + "sa", "sad", "sah", "sam", "saq", "sas", "sat", "saz", + "sba", "sbp", "sc", "scn", "sco", "sd", "sdc", "sdh", + "se", "see", "seh", "sei", "sel", "ses", "sg", "sga", + "sgs", "shi", "shn", "shu", "si", "sid", "sk", + "sl", "sli", "sly", "sm", "sma", "smj", "smn", "sms", + "sn", "snk", "so", "sog", "sq", "sr", "srn", "srr", + "ss", "ssy", "st", "stq", "su", "suk", "sus", "sux", + "sv", "sw", "swb", "swc", "syc", "syr", "szl", + "ta", "tcy", "te", "tem", "teo", "ter", "tet", "tg", + "th", "ti", "tig", "tiv", "tk", "tkl", "tkr", "tl", + "tlh", "tli", "tly", "tmh", "tn", "to", "tog", "tpi", + "tr", "tru", "trv", "ts", "tsd", "tsi", "tt", "ttt", + "tum", "tvl", "tw", "twq", "ty", "tyv", "tzm", + "udm", "ug", "uga", "uk", "umb", "und", "ur", "uz", + "vai", "ve", "vec", "vep", "vi", "vls", "vmf", "vo", + "vot", "vro", "vun", + "wa", "wae", "wal", "war", "was", "wbp", "wo", "wuu", + "xal", "xh", "xmf", "xog", + "yao", "yap", "yav", "ybb", "yi", "yo", "yrl", "yue", + "za", "zap", "zbl", "zea", "zen", "zgh", "zh", "zu", + "zun", "zxx", "zza", +NULL, + "in", "iw", "ji", "jw", "sh", /* obsolete language codes */ +NULL +}; + +/** + * Table of 3-letter language codes. + * + * This is a lookup table used to convert 3-letter language codes to + * their 2-letter equivalent, where possible. It must be kept in sync + * with LANGUAGES. For all valid i, LANGUAGES[i] must refer to the + * same language as LANGUAGES_3[i]. The commented-out lines are + * copied from LANGUAGES to make eyeballing this baby easier. + * + * Where a 3-letter language code has no 2-letter equivalent, the + * 3-letter code occupies both LANGUAGES[i] and LANGUAGES_3[i]. + * + * This table should be terminated with a NULL entry, followed by a + * second list, and another NULL entry. The two lists correspond to + * the two lists in LANGUAGES. + */ +/* Subsequent hand addition of selected languages */ +static const char * const LANGUAGES_3[] = { + "aar", "abk", "ace", "ach", "ada", "ady", "ave", "aeb", + "afr", "afh", "agq", "ain", "aka", "akk", "akz", "ale", + "aln", "alt", "amh", "arg", "ang", "anp", "ara", "arc", + "arn", "aro", "arp", "arq", "ars", "arw", "ary", "arz", "asm", + "asa", "ase", "ast", "ava", "avk", "awa", "aym", "aze", + "bak", "bal", "ban", "bar", "bas", "bax", "bbc", "bbj", + "bel", "bej", "bem", "bew", "bez", "bfd", "bfq", "bul", + "bgn", "bho", "bis", "bik", "bin", "bjn", "bkm", "bla", + "bam", "ben", "bod", "bpy", "bqi", "bre", "bra", "brh", + "brx", "bos", "bss", "bua", "bug", "bum", "byn", "byv", + "cat", "cad", "car", "cay", "cch", "ccp", "che", "ceb", "cgg", + "cha", "chb", "chg", "chk", "chm", "chn", "cho", "chp", + "chr", "chy", "ckb", "cos", "cop", "cps", "cre", "crh", + "ces", "csb", "chu", "chv", "cym", + "dan", "dak", "dar", "dav", "deu", "del", "den", "dgr", + "din", "dje", "doi", "dsb", "dtp", "dua", "dum", "div", + "dyo", "dyu", "dzo", "dzg", + "ebu", "ewe", "efi", "egl", "egy", "eka", "ell", "elx", + "eng", "enm", "epo", "spa", "esu", "est", "eus", "ewo", + "ext", + "fas", "fan", "fat", "ful", "fin", "fil", "fit", "fij", + "fao", "fon", "fra", "frc", "frm", "fro", "frp", "frr", + "frs", "fur", "fry", + "gle", "gaa", "gag", "gan", "gay", "gba", "gbz", "gla", + "gez", "gil", "glg", "glk", "gmh", "grn", "goh", "gom", + "gon", "gor", "got", "grb", "grc", "gsw", "guj", "guc", + "gur", "guz", "glv", "gwi", + "hau", "hai", "hak", "haw", "heb", "hin", "hif", "hil", + "hit", "hmn", "hmo", "hrv", "hsb", "hsn", "hat", "hun", + "hup", "hye", "her", + "ina", "iba", "ibb", "ind", "ile", "ibo", "iii", "ipk", + "ilo", "inh", "ido", "isl", "ita", "iku", "izh", + "jpn", "jam", "jbo", "jgo", "jmc", "jpr", "jrb", "jut", + "jav", + "kat", "kaa", "kab", "kac", "kaj", "kam", "kaw", "kbd", + "kbl", "kcg", "kde", "kea", "ken", "kfo", "kon", "kgp", + "kha", "kho", "khq", "khw", "kik", "kiu", "kua", "kaz", + "kkj", "kal", "kln", "khm", "kmb", "kan", "kor", "koi", + "kok", "kos", "kpe", "kau", "krc", "kri", "krj", "krl", + "kru", "kas", "ksb", "ksf", "ksh", "kur", "kum", "kut", + "kom", "cor", "kir", + "lat", "lad", "lag", "lah", "lam", "ltz", "lez", "lfn", + "lug", "lim", "lij", "liv", "lkt", "lmo", "lin", "lao", + "lol", "loz", "lrc", "lit", "ltg", "lub", "lua", "lui", + "lun", "luo", "lus", "luy", "lav", "lzh", "lzz", + "mad", "maf", "mag", "mai", "mak", "man", "mas", "mde", + "mdf", "mdh", "mdr", "men", "mer", "mfe", "mlg", "mga", + "mgh", "mgo", "mah", "mri", "mic", "min", "mis", "mkd", + "mal", "mon", "mnc", "mni", "mol", + "moh", "mos", "mar", "mrj", + "msa", "mlt", "mua", "mul", "mus", "mwl", "mwr", "mwv", + "mya", "mye", "myv", "mzn", + "nau", "nan", "nap", "naq", "nob", "nde", "nds", "nep", + "new", "ndo", "nia", "niu", "njo", "nld", "nmg", "nno", + "nnh", "nor", "nog", "non", "nov", "nqo", "nbl", "nso", + "nus", "nav", "nwc", "nya", "nym", "nyn", "nyo", "nzi", + "oci", "oji", "orm", "ori", "oss", "osa", "ota", + "pan", "pag", "pal", "pam", "pap", "pau", "pcd", "pcm", "pdc", + "pdt", "peo", "pfl", "phn", "pli", "pol", "pms", "pnt", + "pon", "prg", "pro", "pus", "por", + "que", "quc", "qug", + "raj", "rap", "rar", "rgn", "rif", "roh", "run", "ron", + "rof", "rom", "rtm", "rus", "rue", "rug", "rup", + "kin", "rwk", + "san", "sad", "sah", "sam", "saq", "sas", "sat", "saz", + "sba", "sbp", "srd", "scn", "sco", "snd", "sdc", "sdh", + "sme", "see", "seh", "sei", "sel", "ses", "sag", "sga", + "sgs", "shi", "shn", "shu", "sin", "sid", "slk", + "slv", "sli", "sly", "smo", "sma", "smj", "smn", "sms", + "sna", "snk", "som", "sog", "sqi", "srp", "srn", "srr", + "ssw", "ssy", "sot", "stq", "sun", "suk", "sus", "sux", + "swe", "swa", "swb", "swc", "syc", "syr", "szl", + "tam", "tcy", "tel", "tem", "teo", "ter", "tet", "tgk", + "tha", "tir", "tig", "tiv", "tuk", "tkl", "tkr", "tgl", + "tlh", "tli", "tly", "tmh", "tsn", "ton", "tog", "tpi", + "tur", "tru", "trv", "tso", "tsd", "tsi", "tat", "ttt", + "tum", "tvl", "twi", "twq", "tah", "tyv", "tzm", + "udm", "uig", "uga", "ukr", "umb", "und", "urd", "uzb", + "vai", "ven", "vec", "vep", "vie", "vls", "vmf", "vol", + "vot", "vro", "vun", + "wln", "wae", "wal", "war", "was", "wbp", "wol", "wuu", + "xal", "xho", "xmf", "xog", + "yao", "yap", "yav", "ybb", "yid", "yor", "yrl", "yue", + "zha", "zap", "zbl", "zea", "zen", "zgh", "zho", "zul", + "zun", "zxx", "zza", +NULL, +/* "in", "iw", "ji", "jw", "sh", */ + "ind", "heb", "yid", "jaw", "srp", +NULL +}; + +/** + * Table of 2-letter country codes. + * + * This list must be in sorted order. This list is returned directly + * to the user by some API. + * + * This list must be kept in sync with COUNTRIES_3, with corresponding + * entries matched. + * + * This table should be terminated with a NULL entry, followed by a + * second list, and another NULL entry. The first list is visible to + * user code when this array is returned by API. The second list + * contains codes we support, but do not expose through user API. + * + * Notes: + * + * ZR(ZAR) is now CD(COD) and FX(FXX) is PS(PSE) as per + * http://www.evertype.com/standards/iso3166/iso3166-1-en.html added + * new codes keeping the old ones for compatibility updated to include + * 1999/12/03 revisions *CWB* + * + * RO(ROM) is now RO(ROU) according to + * http://www.iso.org/iso/en/prods-services/iso3166ma/03updates-on-iso-3166/nlv3e-rou.html + */ +static const char * const COUNTRIES[] = { + "AD", "AE", "AF", "AG", "AI", "AL", "AM", + "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", + "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", + "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", + "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", + "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", + "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", + "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", + "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", + "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", + "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", + "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", + "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", + "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", + "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", + "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", + "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", + "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", + "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", + "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", + "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", + "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", + "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", + "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", + "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", + "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", + "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", + "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", + "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", + "WS", "YE", "YT", "ZA", "ZM", "ZW", +NULL, + "AN", "BU", "CS", "FX", "RO", "SU", "TP", "YD", "YU", "ZR", /* obsolete country codes */ +NULL +}; + +/** + * Table of 3-letter country codes. + * + * This is a lookup table used to convert 3-letter country codes to + * their 2-letter equivalent. It must be kept in sync with COUNTRIES. + * For all valid i, COUNTRIES[i] must refer to the same country as + * COUNTRIES_3[i]. The commented-out lines are copied from COUNTRIES + * to make eyeballing this baby easier. + * + * This table should be terminated with a NULL entry, followed by a + * second list, and another NULL entry. The two lists correspond to + * the two lists in COUNTRIES. + */ +static const char * const COUNTRIES_3[] = { +/* "AD", "AE", "AF", "AG", "AI", "AL", "AM", */ + "AND", "ARE", "AFG", "ATG", "AIA", "ALB", "ARM", +/* "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", */ + "AGO", "ATA", "ARG", "ASM", "AUT", "AUS", "ABW", "ALA", "AZE", +/* "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", */ + "BIH", "BRB", "BGD", "BEL", "BFA", "BGR", "BHR", "BDI", +/* "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", */ + "BEN", "BLM", "BMU", "BRN", "BOL", "BES", "BRA", "BHS", "BTN", "BVT", +/* "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", */ + "BWA", "BLR", "BLZ", "CAN", "CCK", "COD", "CAF", "COG", +/* "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", */ + "CHE", "CIV", "COK", "CHL", "CMR", "CHN", "COL", "CRI", +/* "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", */ + "CUB", "CPV", "CUW", "CXR", "CYP", "CZE", "DEU", "DJI", "DNK", +/* "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", */ + "DMA", "DOM", "DZA", "ECU", "EST", "EGY", "ESH", "ERI", +/* "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", */ + "ESP", "ETH", "FIN", "FJI", "FLK", "FSM", "FRO", "FRA", +/* "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", */ + "GAB", "GBR", "GRD", "GEO", "GUF", "GGY", "GHA", "GIB", "GRL", +/* "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", */ + "GMB", "GIN", "GLP", "GNQ", "GRC", "SGS", "GTM", "GUM", +/* "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", */ + "GNB", "GUY", "HKG", "HMD", "HND", "HRV", "HTI", "HUN", +/* "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS" */ + "IDN", "IRL", "ISR", "IMN", "IND", "IOT", "IRQ", "IRN", "ISL", +/* "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", */ + "ITA", "JEY", "JAM", "JOR", "JPN", "KEN", "KGZ", "KHM", "KIR", +/* "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", */ + "COM", "KNA", "PRK", "KOR", "KWT", "CYM", "KAZ", "LAO", +/* "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", */ + "LBN", "LCA", "LIE", "LKA", "LBR", "LSO", "LTU", "LUX", +/* "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", */ + "LVA", "LBY", "MAR", "MCO", "MDA", "MNE", "MAF", "MDG", "MHL", "MKD", +/* "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", */ + "MLI", "MMR", "MNG", "MAC", "MNP", "MTQ", "MRT", "MSR", +/* "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", */ + "MLT", "MUS", "MDV", "MWI", "MEX", "MYS", "MOZ", "NAM", +/* "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", */ + "NCL", "NER", "NFK", "NGA", "NIC", "NLD", "NOR", "NPL", +/* "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", */ + "NRU", "NIU", "NZL", "OMN", "PAN", "PER", "PYF", "PNG", +/* "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", */ + "PHL", "PAK", "POL", "SPM", "PCN", "PRI", "PSE", "PRT", +/* "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", */ + "PLW", "PRY", "QAT", "REU", "ROU", "SRB", "RUS", "RWA", "SAU", +/* "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", */ + "SLB", "SYC", "SDN", "SWE", "SGP", "SHN", "SVN", "SJM", +/* "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", */ + "SVK", "SLE", "SMR", "SEN", "SOM", "SUR", "SSD", "STP", "SLV", +/* "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", */ + "SXM", "SYR", "SWZ", "TCA", "TCD", "ATF", "TGO", "THA", "TJK", +/* "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", */ + "TKL", "TLS", "TKM", "TUN", "TON", "TUR", "TTO", "TUV", +/* "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", */ + "TWN", "TZA", "UKR", "UGA", "UMI", "USA", "URY", "UZB", +/* "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", */ + "VAT", "VCT", "VEN", "VGB", "VIR", "VNM", "VUT", "WLF", +/* "WS", "YE", "YT", "ZA", "ZM", "ZW", */ + "WSM", "YEM", "MYT", "ZAF", "ZMB", "ZWE", +NULL, +/* "AN", "BU", "CS", "FX", "RO", "SU", "TP", "YD", "YU", "ZR" */ + "ANT", "BUR", "SCG", "FXX", "ROM", "SUN", "TMP", "YMD", "YUG", "ZAR", +NULL +}; + +#endif diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_locale.m b/src/native/libs/System.HybridGlobalization.Native/pal_locale.m new file mode 100644 index 0000000000000..a1f63b99acb5c --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/pal_locale.m @@ -0,0 +1,839 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include +#include +#include "pal_locale_internal.h" +#include "pal_localeStringData.h" +#include "pal_localeNumberData.h" + +#import +#import + +#if !__has_feature(objc_arc) +#error This file relies on ARC for memory management, but ARC is not enabled. +#endif + +char* DetectDefaultAppleLocaleName(void) +{ + NSLocale *currentLocale = [NSLocale currentLocale]; + NSString *localeName = @""; + + if (!currentLocale) + { + return strdup([localeName UTF8String]); + } + + if ([currentLocale.languageCode length] > 0 && [currentLocale.countryCode length] > 0) + { + localeName = [NSString stringWithFormat:@"%@-%@", currentLocale.languageCode, currentLocale.countryCode]; + } + else + { + localeName = currentLocale.localeIdentifier; + } + + return strdup([localeName UTF8String]); +} + +#if defined(APPLE_HYBRID_GLOBALIZATION) +const char* GlobalizationNative_GetLocaleNameNative(const char* localeName) +{ + @autoreleasepool + { + NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; + const char* value = [currentLocale.localeIdentifier UTF8String]; + return strdup(value); + } +} + +/** + * Useful constant for the maximum size of the whole locale ID + * (including the terminating NULL and all keywords). + */ +#define FULLNAME_CAPACITY 157 + +static void GetParent(const char* localeID, char* parent, int32_t parentCapacity) +{ + const char *lastUnderscore; + int32_t i; + + if (localeID == NULL) + localeID = [NSLocale systemLocale].localeIdentifier.UTF8String; + + lastUnderscore = strrchr(localeID, '-'); + if (lastUnderscore != NULL) + { + i = (int32_t)(lastUnderscore - localeID); + } + else + { + i = 0; + } + + if (i > 0) + { + // primary lang subtag und (undefined). + if (strncasecmp(localeID, "und-", 4) == 0) + { + localeID += 3; + i -= 3; + memmove(parent, localeID, MIN(i, parentCapacity)); + } + else if (parent != localeID) + { + memcpy(parent, localeID, MIN(i, parentCapacity)); + } + } + + // terminate chars + if (i >= 0 && i < parentCapacity) + parent[i] = 0; +} + +/** + * Lookup 'key' in the array 'list'. The array 'list' should contain + * a NULL entry, followed by more entries, and a second NULL entry. + * + * The 'list' param should be LANGUAGES, LANGUAGES_3, COUNTRIES, or + * COUNTRIES_3. + */ +static int16_t _findIndex(const char* const* list, const char* key) +{ + const char* const* anchor = list; + int32_t pass = 0; + + /* Make two passes through two NULL-terminated arrays at 'list' */ + while (pass++ < 2) { + while (*list) { + if (strcmp(key, *list) == 0) { + return (int16_t)(list - anchor); + } + list++; + } + ++list; /* skip final NULL *CWB*/ + } + return -1; +} + +static const char* getISO3CountryByCountryCode(const char* countryCode) +{ + int16_t offset = _findIndex(COUNTRIES, countryCode); + if (offset < 0) + return ""; + + return COUNTRIES_3[offset]; +} + +static const char* getISO3LanguageByLangCode(const char* langCode) +{ + int16_t offset = _findIndex(LANGUAGES, langCode); + if (offset < 0) + return ""; + return LANGUAGES_3[offset]; +} + +const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData, const char* currentUILocaleName) +{ + @autoreleasepool + { + NSString *value; + NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; + NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; + numberFormatter.locale = currentLocale; + NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; + [dateFormatter setLocale:currentLocale]; + NSLocale *gbLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"]; + + switch (localeStringData) + { + ///// localized name of locale, eg "German (Germany)" in UI language (corresponds to LOCALE_SLOCALIZEDDISPLAYNAME) + case LocaleString_LocalizedDisplayName: + { + NSString *currUILocaleName = [NSString stringWithFormat:@"%s", currentUILocaleName == NULL ? GlobalizationNative_GetDefaultLocaleNameNative() : currentUILocaleName]; + NSLocale *currentUILocale = [[NSLocale alloc] initWithLocaleIdentifier:currUILocaleName]; + value = [currentUILocale displayNameForKey:NSLocaleIdentifier value:currentLocale.localeIdentifier]; + break; + } + /// Display name (language + country usually) in English, eg "German (Germany)" (corresponds to LOCALE_SENGLISHDISPLAYNAME) + case LocaleString_EnglishDisplayName: + value = [gbLocale displayNameForKey:NSLocaleIdentifier value:currentLocale.localeIdentifier]; + break; + /// Display name in native locale language, eg "Deutsch (Deutschland) (corresponds to LOCALE_SNATIVEDISPLAYNAME) + case LocaleString_NativeDisplayName: + value = [currentLocale displayNameForKey:NSLocaleIdentifier value:currentLocale.localeIdentifier]; + break; + /// Language Display Name for a language, eg "German" in UI language (corresponds to LOCALE_SLOCALIZEDLANGUAGENAME) + case LocaleString_LocalizedLanguageName: + { + NSString *currUILocaleName = [NSString stringWithFormat:@"%s", currentUILocaleName == NULL ? GlobalizationNative_GetDefaultLocaleNameNative() : currentUILocaleName]; + NSLocale *currentUILocale = [[NSLocale alloc] initWithLocaleIdentifier:currUILocaleName]; + value = [currentUILocale localizedStringForLanguageCode:currentLocale.languageCode]; + break; + } + /// English name of language, eg "German" (corresponds to LOCALE_SENGLISHLANGUAGENAME) + case LocaleString_EnglishLanguageName: + value = [gbLocale localizedStringForLanguageCode:currentLocale.languageCode]; + break; + /// native name of language, eg "Deutsch" (corresponds to LOCALE_SNATIVELANGUAGENAME) + case LocaleString_NativeLanguageName: + value = [currentLocale localizedStringForLanguageCode:currentLocale.languageCode]; + break; + /// English name of country, eg "Germany" (corresponds to LOCALE_SENGLISHCOUNTRYNAME) + case LocaleString_EnglishCountryName: + value = [gbLocale localizedStringForCountryCode:currentLocale.countryCode]; + break; + /// native name of country, eg "Deutschland" (corresponds to LOCALE_SNATIVECOUNTRYNAME) + case LocaleString_NativeCountryName: + value = [currentLocale localizedStringForCountryCode:currentLocale.countryCode]; + break; + case LocaleString_ThousandSeparator: + value = currentLocale.groupingSeparator; + break; + case LocaleString_DecimalSeparator: + value = currentLocale.decimalSeparator; + // or value = [[currentLocale objectForKey:NSLocaleDecimalSeparator] UTF8String]; + break; + case LocaleString_Digits: + { + NSString *digitsString = @"0123456789"; + NSNumberFormatter *nf1 = [[NSNumberFormatter alloc] init]; + [nf1 setLocale:currentLocale]; + + NSNumber *newNum = [nf1 numberFromString:digitsString]; + value = [newNum stringValue]; + break; + } + case LocaleString_MonetarySymbol: + value = currentLocale.currencySymbol; + break; + case LocaleString_Iso4217MonetarySymbol: + // check if this is correct, check currencyISOCode + value = currentLocale.currencyCode; + break; + case LocaleString_CurrencyEnglishName: + value = [gbLocale localizedStringForCurrencyCode:currentLocale.currencyCode]; + break; + case LocaleString_CurrencyNativeName: + value = [currentLocale localizedStringForCurrencyCode:currentLocale.currencyCode]; + break; + case LocaleString_MonetaryDecimalSeparator: + value = numberFormatter.currencyDecimalSeparator; + break; + case LocaleString_MonetaryThousandSeparator: + value = numberFormatter.currencyGroupingSeparator; + break; + case LocaleString_AMDesignator: + value = dateFormatter.AMSymbol; + break; + case LocaleString_PMDesignator: + value = dateFormatter.PMSymbol; + break; + case LocaleString_PositiveSign: + value = numberFormatter.plusSign; + break; + case LocaleString_NegativeSign: + value = numberFormatter.minusSign; + break; + case LocaleString_Iso639LanguageTwoLetterName: + value = [currentLocale objectForKey:NSLocaleLanguageCode]; + break; + case LocaleString_Iso639LanguageThreeLetterName: + { + NSString *iso639_2 = [currentLocale objectForKey:NSLocaleLanguageCode]; + return iso639_2 == nil ? strdup("") : strdup(getISO3LanguageByLangCode([iso639_2 UTF8String])); + } + case LocaleString_Iso3166CountryName: + value = [currentLocale objectForKey:NSLocaleCountryCode]; + break; + case LocaleString_Iso3166CountryName2: + { + NSString* countryCode = [currentLocale objectForKey:NSLocaleCountryCode]; + return countryCode == nil ? strdup("") : strdup(getISO3CountryByCountryCode([countryCode UTF8String])); + } + case LocaleString_NaNSymbol: + value = numberFormatter.notANumberSymbol; + break; + case LocaleString_PositiveInfinitySymbol: + value = numberFormatter.positiveInfinitySymbol; + break; + case LocaleString_NegativeInfinitySymbol: + value = numberFormatter.negativeInfinitySymbol; + break; + case LocaleString_PercentSymbol: + value = numberFormatter.percentSymbol; + break; + case LocaleString_PerMilleSymbol: + value = numberFormatter.perMillSymbol; + break; + case LocaleString_ParentName: + { + char localeNameTemp[FULLNAME_CAPACITY]; + const char* lName = [currentLocale.localeIdentifier UTF8String]; + GetParent(lName, localeNameTemp, FULLNAME_CAPACITY); + return strdup(localeNameTemp); + } + default: + value = nil; + break; + } + + return value == nil ? strdup("") : strdup([value UTF8String]); + } +} + +// invariant character definitions +#define CHAR_CURRENCY ((char)0x00A4) // international currency +#define CHAR_SPACE ((char)0x0020) // space +#define CHAR_NBSPACE ((char)0x00A0) // no-break space +#define CHAR_DIGIT ((char)0x0023) // '#' +#define CHAR_MINUS ((char)0x002D) // '-' +#define CHAR_PERCENT ((char)0x0025) // '%' +#define CHAR_OPENPAREN ((char)0x0028) // '(' +#define CHAR_CLOSEPAREN ((char)0x0029) // ')' +#define CHAR_ZERO ((char)0x0030) // '0' + +/* +Function: +NormalizeNumericPattern + +Returns a numeric string pattern in a format that we can match against the +appropriate managed pattern. Examples: +For PositiveMonetaryNumberFormat "¤#,##0.00" becomes "Cn" +For NegativeNumberFormat "#,##0.00;(#,##0.00)" becomes "(n)" +*/ +static char* NormalizeNumericPattern(const char* srcPattern, int isNegative) +{ + int iStart = 0; + int iEnd = strlen(srcPattern); + + // ';' separates positive and negative subpatterns. + // When there is no explicit negative subpattern, + // an implicit negative subpattern is formed from the positive pattern with a prefixed '-'. + char * ptrNegativePattern = strrchr(srcPattern,';'); + if (ptrNegativePattern) + { + int32_t iNegativePatternStart = ptrNegativePattern - srcPattern; + if (isNegative) + { + iStart = iNegativePatternStart + 1; + } + else + { + iEnd = iNegativePatternStart - 1; + } + } + + int minusAdded = false; + + for (int i = iStart; i <= iEnd; i++) + { + switch (srcPattern[i]) + { + case CHAR_MINUS: + case CHAR_OPENPAREN: + case CHAR_CLOSEPAREN: + minusAdded = true; + break; + } + + if (minusAdded) + break; + } + + // international currency symbol (CHAR_CURRENCY) + // The positive pattern comes first, then an optional negative pattern + // separated by a semicolon + // A destPattern example: "(C n)" where C represents the currency symbol, and + // n is the number + char* destPattern; + int index = 0; + + // if there is no negative subpattern, prefix the minus sign + if (isNegative && !minusAdded) + { + int length = (iEnd - iStart) + 2; + destPattern = (char*)calloc((size_t)length, sizeof(char)); + if (!destPattern) + { + return NULL; + } + destPattern[index++] = '-'; + } + else + { + int length = (iEnd - iStart) + 1; + destPattern = (char*)calloc((size_t)length, sizeof(char)); + if (!destPattern) + { + return NULL; + } + } + + int digitAdded = false; + int currencyAdded = false; + int spaceAdded = false; + + for (int i = iStart; i <= iEnd; i++) + { + char ch = srcPattern[i]; + switch (ch) + { + case CHAR_DIGIT: + case CHAR_ZERO: + if (!digitAdded) + { + digitAdded = true; + destPattern[index++] = 'n'; + } + break; + + case CHAR_CURRENCY: + if (!currencyAdded) + { + currencyAdded = true; + destPattern[index++] = 'C'; + } + break; + + case CHAR_SPACE: + case CHAR_NBSPACE: + if (!spaceAdded) + { + spaceAdded = true; + destPattern[index++] = ' '; + } + break; + + case CHAR_MINUS: + case CHAR_OPENPAREN: + case CHAR_CLOSEPAREN: + case CHAR_PERCENT: + destPattern[index++] = ch; + break; + } + } + + const int MAX_DOTNET_NUMERIC_PATTERN_LENGTH = 6; // example: "(C n)" plus terminator + + if (destPattern[0] == '\0' || strlen (destPattern) >= MAX_DOTNET_NUMERIC_PATTERN_LENGTH) + { + free (destPattern); + return NULL; + } + + return destPattern; +} + +/* +Function: +GetNumericPattern + +Determines the pattern from the decimalFormat and returns the matching pattern's +index from patterns[]. +Returns index -1 if no pattern is found. +*/ +static int GetPatternIndex(char* normalizedPattern,const char* patterns[], int patternsCount) +{ + const int INVALID_FORMAT = -1; + + if (!normalizedPattern) + { + return INVALID_FORMAT; + } + + for (int i = 0; i < patternsCount; i++) + { + if (strcmp(normalizedPattern, patterns[i]) == 0) + { + free(normalizedPattern); + return i; + } + } + + assert(false); // should have found a valid pattern + + free(normalizedPattern); + return INVALID_FORMAT; +} + +static int32_t GetValueForNumberFormat(NSLocale *currentLocale, LocaleNumberData localeNumberData) +{ + NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; + numberFormatter.locale = currentLocale; + const char *pFormat; + int32_t value; + + switch(localeNumberData) + { + case LocaleNumber_PositiveMonetaryNumberFormat: + { + numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle; + static const char* Patterns[] = {"Cn", "nC", "C n", "n C"}; + pFormat = [[numberFormatter positiveFormat] UTF8String]; + char* normalizedPattern = NormalizeNumericPattern(pFormat, false); + value = GetPatternIndex(normalizedPattern, Patterns, sizeof(Patterns)/sizeof(Patterns[0])); + break; + } + case LocaleNumber_NegativeMonetaryNumberFormat: + { + numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle; + static const char* Patterns[] = {"(Cn)", "-Cn", "C-n", "Cn-", "(nC)", "-nC", "n-C", "nC-", "-n C", + "-C n", "n C-", "C n-", "C -n", "n- C", "(C n)", "(n C)", "C- n" }; + pFormat = [[numberFormatter negativeFormat] UTF8String]; + char* normalizedPattern = NormalizeNumericPattern(pFormat, true); + value = GetPatternIndex(normalizedPattern, Patterns, sizeof(Patterns)/sizeof(Patterns[0])); + break; + } + case LocaleNumber_NegativeNumberFormat: + { + numberFormatter.numberStyle = NSNumberFormatterDecimalStyle; + static const char* Patterns[] = {"(n)", "-n", "- n", "n-", "n -"}; + pFormat = [[numberFormatter negativeFormat] UTF8String]; + char* normalizedPattern = NormalizeNumericPattern(pFormat, true); + value = GetPatternIndex(normalizedPattern, Patterns, sizeof(Patterns)/sizeof(Patterns[0])); + break; + } + case LocaleNumber_NegativePercentFormat: + { + numberFormatter.numberStyle = NSNumberFormatterPercentStyle; + static const char* Patterns[] = {"-n %", "-n%", "-%n", "%-n", "%n-", "n-%", "n%-", "-% n", "n %-", "% n-", "% -n", "n- %"}; + pFormat = [[numberFormatter negativeFormat] UTF8String]; + char* normalizedPattern = NormalizeNumericPattern(pFormat, true); + value = GetPatternIndex(normalizedPattern, Patterns, sizeof(Patterns)/sizeof(Patterns[0])); + break; + } + case LocaleNumber_PositivePercentFormat: + { + numberFormatter.numberStyle = NSNumberFormatterPercentStyle; + static const char* Patterns[] = {"n %", "n%", "%n", "% n"}; + pFormat = [[numberFormatter positiveFormat] UTF8String]; + char* normalizedPattern = NormalizeNumericPattern(pFormat, false); + value = GetPatternIndex(normalizedPattern, Patterns, sizeof(Patterns)/sizeof(Patterns[0])); + break; + } + default: + return -1; + } + + return value; +} + +int32_t GlobalizationNative_GetLocaleInfoIntNative(const char* localeName, LocaleNumberData localeNumberData) +{ + @autoreleasepool + { +#ifndef NDEBUG + bool isSuccess = true; +#endif + int32_t value; + NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; + + switch (localeNumberData) + { + case LocaleNumber_MeasurementSystem: + { + const char *measurementSystem = [[currentLocale objectForKey:NSLocaleMeasurementSystem] UTF8String]; + NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; + const char *us_measurementSystem = [[usLocale objectForKey:NSLocaleMeasurementSystem] UTF8String]; + value = (measurementSystem == us_measurementSystem) ? 1 : 0; + break; + } + case LocaleNumber_FractionalDigitsCount: + { + NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; + numberFormatter.locale = currentLocale; + numberFormatter.numberStyle = NSNumberFormatterDecimalStyle; + value = (int32_t)numberFormatter.maximumFractionDigits; + break; + } + case LocaleNumber_MonetaryFractionalDigitsCount: + { + NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; + numberFormatter.locale = currentLocale; + numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle; + value = (int32_t)numberFormatter.maximumFractionDigits; + break; + } + case LocaleNumber_PositiveMonetaryNumberFormat: + case LocaleNumber_NegativeMonetaryNumberFormat: + case LocaleNumber_NegativeNumberFormat: + case LocaleNumber_NegativePercentFormat: + case LocaleNumber_PositivePercentFormat: + { + value = GetValueForNumberFormat(currentLocale, localeNumberData); +#ifndef NDEBUG + if (value < 0) + { + isSuccess = false; + } +#endif + break; + } + case LocaleNumber_FirstWeekOfYear: + { + NSCalendar *calendar = [currentLocale objectForKey:NSLocaleCalendar]; + int minDaysInWeek = (int32_t)[calendar minimumDaysInFirstWeek]; + if (minDaysInWeek == 1) + { + value = WeekRule_FirstDay; + } + else if (minDaysInWeek == 7) + { + value = WeekRule_FirstFullWeek; + } + else if (minDaysInWeek >= 4) + { + value = WeekRule_FirstFourDayWeek; + } + else + { + value = -1; +#ifndef NDEBUG + isSuccess = false; +#endif + } + break; + } + case LocaleNumber_ReadingLayout: + { + NSLocaleLanguageDirection langDir = [NSLocale characterDirectionForLanguage:[currentLocale objectForKey:NSLocaleLanguageCode]]; + // 0 - Left to right (such as en-US) + // 1 - Right to left (such as arabic locales) + value = NSLocaleLanguageDirectionRightToLeft == langDir ? 1 : 0; + break; + } + case LocaleNumber_FirstDayofWeek: + { + NSCalendar *calendar = [currentLocale objectForKey:NSLocaleCalendar]; + value = [calendar firstWeekday] - 1; // .NET is 0-based and in Apple is 1-based; + break; + } + default: + value = -1; +#ifndef NDEBUG + isSuccess = false; +#endif + break; + } + + assert(isSuccess); + + return value; + } +} + +/* +PAL Function: +GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative + +Returns primary grouping size for decimal and currency +*/ +int32_t GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative(const char* localeName, LocaleNumberData localeGroupingData) +{ + @autoreleasepool + { + NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; + NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; + numberFormatter.locale = currentLocale; + + switch (localeGroupingData) + { + case LocaleNumber_Digit: + numberFormatter.numberStyle = NSNumberFormatterDecimalStyle; + break; + case LocaleNumber_Monetary: + numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle; + break; + default: + assert(false); + break; + } + return [numberFormatter groupingSize]; + } +} + +/* +PAL Function: +GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative + +Returns secondary grouping size for decimal and currency +*/ +int32_t GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative(const char* localeName, LocaleNumberData localeGroupingData) +{ + @autoreleasepool + { + NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; + NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; + numberFormatter.locale = currentLocale; + + switch (localeGroupingData) + { + case LocaleNumber_Digit: + numberFormatter.numberStyle = NSNumberFormatterDecimalStyle; + break; + case LocaleNumber_Monetary: + numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle; + break; + default: + assert(false); + break; + } + + return [numberFormatter secondaryGroupingSize]; + } +} + +/* +PAL Function: +GlobalizationNative_GetLocaleTimeFormatNative + +Returns time format information (in native format, it needs to be converted to .NET's format). +*/ +const char* GlobalizationNative_GetLocaleTimeFormatNative(const char* localeName, int shortFormat) +{ + @autoreleasepool + { + NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; + NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; + [dateFormatter setLocale:currentLocale]; + + if (shortFormat != 0) + { + [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; + } + else + { + [dateFormatter setTimeStyle:NSDateFormatterMediumStyle]; + } + + return strdup([[dateFormatter dateFormat] UTF8String]); + } +} + +// GlobalizationNative_GetLocalesNative gets all locale names and store it in the value buffer +// in case of success, it returns the count of the characters stored in value buffer +// in case of failure, it returns negative number. +// if the input value buffer is null, it returns the length needed to store the +// locale names list. +// if the value is not null, it fills the value with locale names separated by the length +// of each name. +int32_t GlobalizationNative_GetLocalesNative(UChar* value, int32_t length) +{ + @autoreleasepool + { + NSArray* availableLocaleIdentifiers = [NSLocale availableLocaleIdentifiers]; + int32_t index = 0; + int32_t totalLength = 0; + int32_t availableLength = (int32_t)[availableLocaleIdentifiers count]; + + if (availableLength <= 0) + return -1; // failed + + for (NSInteger i = 0; i < availableLength; i++) + { + NSString *localeIdentifier = availableLocaleIdentifiers[i]; + int32_t localeNameLength = localeIdentifier.length; + totalLength += localeNameLength + 1; // add 1 for the name length + if (value != NULL) + { + if (totalLength > length) + return -3; + + value[index++] = (UChar) localeNameLength; + + for (int j = 0; j < localeNameLength; j++) + { + if ((UChar)[localeIdentifier characterAtIndex:j] == '_') + { + value[index++] = (UChar) '-'; + } + else + { + value[index++] = (UChar) [localeIdentifier characterAtIndex:j]; + } + } + } + } + return totalLength; + } +} + +const char* GlobalizationNative_GetICUDataPathRelativeToAppBundleRoot(const char* path) +{ + @autoreleasepool + { + NSString *bundlePath = [[NSBundle mainBundle] bundlePath]; + NSString *dataPath = [bundlePath stringByAppendingPathComponent: [NSString stringWithFormat:@"%s", path]]; + + return strdup([dataPath UTF8String]); + } +} + +const char* GlobalizationNative_GetICUDataPathFallback(void) +{ + @autoreleasepool + { + NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"icudt" ofType:@"dat"]; + return strdup([dataPath UTF8String]); + } +} + +const char* GlobalizationNative_GetDefaultLocaleNameNative(void) +{ + @autoreleasepool + { + if (NSLocale.preferredLanguages.count > 0) + { + return strdup([NSLocale.preferredLanguages[0] UTF8String]); + } + else + { + NSLocale *currentLocale = [NSLocale currentLocale]; + NSString *localeName = @""; + + if (!currentLocale) + { + return strdup([localeName UTF8String]); + } + + if ([currentLocale.languageCode length] > 0 && [currentLocale.countryCode length] > 0) + { + localeName = [NSString stringWithFormat:@"%@-%@", currentLocale.languageCode, currentLocale.countryCode]; + } + else + { + localeName = currentLocale.localeIdentifier; + } + + return strdup([localeName UTF8String]); + } + } +} + +// GlobalizationNative_IsPredefinedLocaleNative returns TRUE if localeName exists in availableLocaleIdentifiers. +// Otherwise it returns FALSE; + +int32_t GlobalizationNative_IsPredefinedLocaleNative(const char* localeName) +{ + @autoreleasepool + { + NSString *localeIdentifier = [NSString stringWithFormat:@"%s", localeName]; + NSString *localeIdentifierByRegionDesignator = [localeIdentifier stringByReplacingOccurrencesOfString:@"-" withString:@"_"]; + NSArray *availableLocales = [NSLocale availableLocaleIdentifiers]; + + if ([availableLocales containsObject:localeIdentifier] || [availableLocales containsObject:localeIdentifierByRegionDesignator]) + { + return true; + } + + return false; + } +} +#endif diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_localeNumberData.h b/src/native/libs/System.HybridGlobalization.Native/pal_localeNumberData.h new file mode 100644 index 0000000000000..f609c654e1292 --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/pal_localeNumberData.h @@ -0,0 +1,54 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +#pragma once + +#include "pal_locale.h" +#include "pal_compiler.h" + +// Enum that corresponds to managed enum CultureData.LocaleNumberData. +// The numeric values of the enum members match their Win32 counterparts. +typedef enum +{ + LocaleNumber_LanguageId = 0x01, + LocaleNumber_MeasurementSystem = 0x0D, + LocaleNumber_FractionalDigitsCount = 0x00000011, + LocaleNumber_NegativeNumberFormat = 0x00001010, + LocaleNumber_MonetaryFractionalDigitsCount = 0x00000019, + LocaleNumber_PositiveMonetaryNumberFormat = 0x0000001B, + LocaleNumber_NegativeMonetaryNumberFormat = 0x0000001C, + LocaleNumber_FirstDayofWeek = 0x0000100C, + LocaleNumber_FirstWeekOfYear = 0x0000100D, + LocaleNumber_ReadingLayout = 0x00000070, + LocaleNumber_NegativePercentFormat = 0x00000074, + LocaleNumber_PositivePercentFormat = 0x00000075, + LocaleNumber_Digit = 0x00000010, + LocaleNumber_Monetary = 0x00000018 +} LocaleNumberData; + +// Enum that corresponds to managed enum System.Globalization.CalendarWeekRule +typedef enum +{ + WeekRule_FirstDay = 0, + WeekRule_FirstFullWeek = 1, + WeekRule_FirstFourDayWeek = 2 +} CalendarWeekRule; +PALEXPORT int32_t GlobalizationNative_GetLocaleInfoInt(const UChar* localeName, + LocaleNumberData localeNumberData, + int32_t* value); + +PALEXPORT int32_t GlobalizationNative_GetLocaleInfoGroupingSizes(const UChar* localeName, + LocaleNumberData localeGroupingData, + int32_t* primaryGroupSize, + int32_t* secondaryGroupSize); +#if defined(APPLE_HYBRID_GLOBALIZATION) +PALEXPORT int32_t GlobalizationNative_GetLocaleInfoIntNative(const char* localeName, + LocaleNumberData localeNumberData); + +PALEXPORT int32_t GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative(const char* localeName, + LocaleNumberData localeGroupingData); + +PALEXPORT int32_t GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative(const char* localeName, + LocaleNumberData localeGroupingData); +#endif diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_localeStringData.h b/src/native/libs/System.HybridGlobalization.Native/pal_localeStringData.h new file mode 100644 index 0000000000000..957021dffa697 --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/pal_localeStringData.h @@ -0,0 +1,54 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +#pragma once + +#include "pal_locale.h" +#include "pal_compiler.h" + +// Enum that corresponds to managed enum CultureData.LocaleStringData. +// The numeric values of the enum members match their Win32 counterparts. +typedef enum +{ + LocaleString_LocalizedDisplayName = 0x02, + LocaleString_EnglishDisplayName = 0x00000072, + LocaleString_NativeDisplayName = 0x00000073, + LocaleString_LocalizedLanguageName = 0x0000006f, + LocaleString_EnglishLanguageName = 0x00001001, + LocaleString_NativeLanguageName = 0x04, + LocaleString_EnglishCountryName = 0x00001002, + LocaleString_NativeCountryName = 0x08, + LocaleString_DecimalSeparator = 0x0E, + LocaleString_ThousandSeparator = 0x0F, + LocaleString_Digits = 0x00000013, + LocaleString_MonetarySymbol = 0x00000014, + LocaleString_CurrencyEnglishName = 0x00001007, + LocaleString_CurrencyNativeName = 0x00001008, + LocaleString_Iso4217MonetarySymbol = 0x00000015, + LocaleString_MonetaryDecimalSeparator = 0x00000016, + LocaleString_MonetaryThousandSeparator = 0x00000017, + LocaleString_AMDesignator = 0x00000028, + LocaleString_PMDesignator = 0x00000029, + LocaleString_PositiveSign = 0x00000050, + LocaleString_NegativeSign = 0x00000051, + LocaleString_Iso639LanguageTwoLetterName = 0x00000059, + LocaleString_Iso639LanguageThreeLetterName = 0x00000067, + LocaleString_Iso3166CountryName = 0x0000005A, + LocaleString_Iso3166CountryName2= 0x00000068, + LocaleString_NaNSymbol = 0x00000069, + LocaleString_PositiveInfinitySymbol = 0x0000006a, + LocaleString_NegativeInfinitySymbol = 0x0000006b, + LocaleString_ParentName = 0x0000006d, + LocaleString_PercentSymbol = 0x00000076, + LocaleString_PerMilleSymbol = 0x00000077 +} LocaleStringData; +PALEXPORT int32_t GlobalizationNative_GetLocaleInfoString(const UChar* localeName, + LocaleStringData localeStringData, + UChar* value, + int32_t valueLength, + const UChar* uiLocaleName); +#if defined(APPLE_HYBRID_GLOBALIZATION) +PALEXPORT const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData, const char* currentUILocaleName); +#endif + diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_locale_internal.h b/src/native/libs/System.HybridGlobalization.Native/pal_locale_internal.h new file mode 100644 index 0000000000000..c754554bbfdd5 --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/pal_locale_internal.h @@ -0,0 +1,63 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#pragma once + +#include "pal_icushim_internal.h" + +/* +Function: +UErrorCodeToBool + +Convert an ICU UErrorCode to a Bool compatible with Win32 +Returns 1 for success, 0 otherwise +*/ +int32_t UErrorCodeToBool(UErrorCode code); + +/* +Function: +GetLocale + +Converts a managed localeName into something ICU understands and can use as a localeName. +*/ +int32_t GetLocale(const UChar* localeName, + char* localeNameResult, + int32_t localeNameResultLength, + UBool canonicalize, + UErrorCode* err); + +/* +Function: +u_charsToUChars_safe + +Copies the given null terminated char* to UChar with error checking. Replacement for ICU u_charsToUChars +*/ +void u_charsToUChars_safe(const char* str, UChar* value, int32_t valueLength, UErrorCode* err); + +/* +Function: +FixupLocaleName + +Replace underscores with hyphens to interop with existing .NET code. +Returns the length of the string. +*/ +int32_t FixupLocaleName(UChar* value, int32_t valueLength); + +/* +Function: +DetectDefaultLocaleName + +Detect the default locale for the machine, defaulting to Invaraint if +we can't compute one (different from uloc_getDefault()) would do. +*/ +const char* DetectDefaultLocaleName(void); + +#ifdef __APPLE__ +/* +Function: +DetectDefaultSystemLocaleName + +Detects the default locale string for Apple platforms +*/ +char* DetectDefaultAppleLocaleName(void); +#endif diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_normalization.h b/src/native/libs/System.HybridGlobalization.Native/pal_normalization.h new file mode 100644 index 0000000000000..a05ac2005543e --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/pal_normalization.h @@ -0,0 +1,39 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +#pragma once + +#include "pal_locale.h" +#include "pal_compiler.h" + +/* + * These values should be kept in sync with System.Text.NormalizationForm + */ +typedef enum +{ + FormC = 0x1, + FormD = 0x2, + FormKC = 0x5, + FormKD = 0x6 +} NormalizationForm; +PALEXPORT int32_t GlobalizationNative_IsNormalized(NormalizationForm normalizationForm, + const UChar* lpStr, + int32_t cwStrLength); + +PALEXPORT int32_t GlobalizationNative_NormalizeString(NormalizationForm normalizationForm, + const UChar* lpSrc, + int32_t cwSrcLength, + UChar* lpDst, + int32_t cwDstLength); +#if defined(APPLE_HYBRID_GLOBALIZATION) +PALEXPORT int32_t GlobalizationNative_IsNormalizedNative(NormalizationForm normalizationForm, + const uint16_t* lpStr, + int32_t cwStrLength); + +PALEXPORT int32_t GlobalizationNative_NormalizeStringNative(NormalizationForm normalizationForm, + const uint16_t* lpSource, + int32_t cwSourceLength, + uint16_t* lpDst, + int32_t cwDstLength); +#endif diff --git a/src/native/libs/System.Globalization.Native/pal_normalization.m b/src/native/libs/System.HybridGlobalization.Native/pal_normalization.m similarity index 99% rename from src/native/libs/System.Globalization.Native/pal_normalization.m rename to src/native/libs/System.HybridGlobalization.Native/pal_normalization.m index c029a16328bb2..35aa9fc63e618 100644 --- a/src/native/libs/System.Globalization.Native/pal_normalization.m +++ b/src/native/libs/System.HybridGlobalization.Native/pal_normalization.m @@ -88,4 +88,3 @@ int32_t GlobalizationNative_NormalizeStringNative(NormalizationForm normalizatio } } #endif - diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_placeholders.c b/src/native/libs/System.HybridGlobalization.Native/pal_placeholders.c new file mode 100644 index 0000000000000..7d0f9624e082b --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/pal_placeholders.c @@ -0,0 +1,276 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include +#include + +#include "pal_icushim_internal.h" +#include "pal_icushim.h" +#include "pal_calendarData.h" +#include "pal_casing.h" +#include "pal_collation.h" +#include "pal_locale.h" +#include "pal_localeNumberData.h" +#include "pal_localeStringData.h" +#include "pal_normalization.h" +#include "pal_timeZoneInfo.h" + +#ifdef DEBUG +#define assert_err(cond, msg, err) do \ +{ \ + if(!(cond)) \ + { \ + fprintf(stderr, "%s (%d): error %d: %s. %s (%s failed)\n", __FILE__, __LINE__, err, msg, strerror(err), #cond); \ + assert(false && "assert_err failed"); \ + } \ +} while(0) +#define assert_msg(cond, msg, val) do \ +{ \ + if(!(cond)) \ + { \ + fprintf(stderr, "%s (%d): error %d: %s (%s failed)\n", __FILE__, __LINE__, val, msg, #cond); \ + assert(false && "assert_msg failed"); \ + } \ +} while(0) +#else // DEBUG +#define assert_err(cond, msg, err) +#define assert_msg(cond, msg, val) +#endif // DEBUG + + +// Placeholder for calendar data +int32_t GlobalizationNative_GetCalendars( + const UChar* localeName, CalendarId* calendars, int32_t calendarsCapacity) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +ResultCode GlobalizationNative_GetCalendarInfo( + const UChar* localeName, CalendarId calendarId, CalendarDataType dataType, UChar* result, int32_t resultCapacity) +{ + assert_msg(false, "Not supported on this platform", 0); + return UnknownError; +} + +int32_t GlobalizationNative_EnumCalendarInfo( + EnumCalendarInfoCallback callback, const UChar* localeName, CalendarId calendarId, CalendarDataType dataType, const void* context) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +int32_t GlobalizationNative_GetLatestJapaneseEra(void) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +int32_t GlobalizationNative_GetJapaneseEraStartDate( + int32_t era, int32_t* startYear, int32_t* startMonth, int32_t* startDay) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +// Placeholder for casing data +void GlobalizationNative_ChangeCase( + const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength, int32_t bToUpper) +{ + assert_msg(false, "Not supported on this platform", 0); +} + +void GlobalizationNative_ChangeCaseInvariant( + const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength, int32_t bToUpper) +{ + assert_msg(false, "Not supported on this platform", 0); +} + +void GlobalizationNative_ChangeCaseTurkish( + const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength, int32_t bToUpper) +{ + assert_msg(false, "Not supported on this platform", 0); +} + +// Placeholder for collation data +ResultCode GlobalizationNative_GetSortHandle( + const char* lpLocaleName, SortHandle** pSortHandle) +{ + assert_msg(false, "Not supported on this platform", 0); + return UnknownError; +} + +void GlobalizationNative_CloseSortHandle(SortHandle* pSortHandle) +{ + assert_msg(false, "Not supported on this platform", 0); +} + +int32_t GlobalizationNative_GetSortVersion(SortHandle* pSortHandle) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +int32_t GlobalizationNative_CompareString( + SortHandle* pSortHandle, const UChar* lpStr1, int32_t cwStr1Length, const UChar* lpStr2, int32_t cwStr2Length, int32_t options) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +int32_t GlobalizationNative_IndexOf( + SortHandle* pSortHandle, const UChar* lpTarget, int32_t cwTargetLength, const UChar* lpSource, int32_t cwSourceLength, int32_t options, int32_t* pMatchedLength) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +int32_t GlobalizationNative_LastIndexOf( + SortHandle* pSortHandle, const UChar* lpTarget, int32_t cwTargetLength, const UChar* lpSource, int32_t cwSourceLength, int32_t options, int32_t* pMatchedLength) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +int32_t GlobalizationNative_StartsWith( + SortHandle* pSortHandle, const UChar* lpTarget, int32_t cwTargetLength, const UChar* lpSource, int32_t cwSourceLength, int32_t options, int32_t* pMatchedLength) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +int32_t GlobalizationNative_EndsWith( + SortHandle* pSortHandle, const UChar* lpTarget, int32_t cwTargetLength, const UChar* lpSource, int32_t cwSourceLength, int32_t options, int32_t* pMatchedLength) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +int32_t GlobalizationNative_GetSortKey( + SortHandle* pSortHandle, const UChar* lpStr, int32_t cwStrLength, uint8_t* sortKey, int32_t cbSortKeyLength, int32_t options) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +// Placeholder for locale data +int32_t GlobalizationNative_GetLocales( + UChar *value, int32_t valueLength) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +int32_t GlobalizationNative_GetLocaleName( + const UChar* localeName, UChar* value, int32_t valueLength) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +int32_t GlobalizationNative_GetDefaultLocaleName( + UChar* value, int32_t valueLength) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +int32_t GlobalizationNative_IsPredefinedLocale( + const UChar* localeName) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +int32_t GlobalizationNative_GetLocaleTimeFormat( + const UChar* localeName, int shortFormat, UChar* value, int32_t valueLength) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +// Placeholder for locale number data +int32_t GlobalizationNative_GetLocaleInfoInt( + const UChar* localeName, LocaleNumberData localeNumberData, int32_t* value) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +int32_t GlobalizationNative_GetLocaleInfoGroupingSizes( + const UChar* localeName, LocaleNumberData localeGroupingData, int32_t* primaryGroupSize, int32_t* secondaryGroupSize) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +// Placeholder for icu shim data +int32_t GlobalizationNative_LoadICU(void) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +void GlobalizationNative_InitICUFunctions( + void* icuuc, void* icuin, const char* version, const char* suffix) +{ + assert_msg(false, "Not supported on this platform", 0); +} + +int32_t GlobalizationNative_GetICUVersion(void) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +int32_t +GlobalizationNative_LoadICUData(const char* path) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +// Placeholder for locale string data +int32_t GlobalizationNative_GetLocaleInfoString( + const UChar* localeName, LocaleStringData localeStringData, UChar* value, int32_t valueLength, const UChar* uiLocaleName) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +//Placeholder for normalization data +int32_t GlobalizationNative_IsNormalized( + NormalizationForm normalizationForm, const UChar* lpStr, int32_t cwStrLength) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +int32_t GlobalizationNative_NormalizeString( + NormalizationForm normalizationForm, const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +// Placeholder for time zone data +int32_t GlobalizationNative_WindowsIdToIanaId( + const UChar* windowsId, const char* region, UChar* ianaId, int32_t ianaIdLength) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} + +ResultCode GlobalizationNative_GetTimeZoneDisplayName( + const UChar* localeName, const UChar* timeZoneId, TimeZoneDisplayNameType type, UChar* result, int32_t resultLength) +{ + assert_msg(false, "Not supported on this platform", 0); + return UnknownError; +} + +int32_t GlobalizationNative_IanaIdToWindowsId( + const UChar* ianaId, UChar* windowsId, int32_t windowsIdLength) +{ + assert_msg(false, "Not supported on this platform", 0); + return 0; +} diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_timeZoneInfo.h b/src/native/libs/System.HybridGlobalization.Native/pal_timeZoneInfo.h new file mode 100644 index 0000000000000..bb32c41d43db9 --- /dev/null +++ b/src/native/libs/System.HybridGlobalization.Native/pal_timeZoneInfo.h @@ -0,0 +1,29 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +#pragma once + +#include "pal_locale.h" +#include "pal_compiler.h" +#include "pal_errors.h" + +/* +These values should be kept in sync with the managed Interop.GlobalizationInterop.TimeZoneDisplayNameType enum. +*/ +typedef enum +{ + TimeZoneDisplayName_Generic = 0, + TimeZoneDisplayName_Standard = 1, + TimeZoneDisplayName_DaylightSavings = 2, + TimeZoneDisplayName_GenericLocation = 3, + TimeZoneDisplayName_ExemplarCity = 4, + TimeZoneDisplayName_TimeZoneName = 5, +} TimeZoneDisplayNameType; +PALEXPORT int32_t GlobalizationNative_WindowsIdToIanaId(const UChar* windowsId, const char* region, UChar* ianaId, int32_t ianaIdLength); +PALEXPORT int32_t GlobalizationNative_IanaIdToWindowsId(const UChar* ianaId, UChar* windowsId, int32_t windowsIdLength); +PALEXPORT ResultCode GlobalizationNative_GetTimeZoneDisplayName(const UChar* localeName, const UChar* timeZoneId, TimeZoneDisplayNameType type, UChar* result, int32_t resultLength); +#if defined(APPLE_HYBRID_GLOBALIZATION) +PALEXPORT int32_t GlobalizationNative_GetTimeZoneDisplayNameNative(const uint16_t* localeName, int32_t lNameLength, const uint16_t* timeZoneId, int32_t timeZoneIdLength, + TimeZoneDisplayNameType type, uint16_t* result, int32_t resultLength); +#endif diff --git a/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.m b/src/native/libs/System.HybridGlobalization.Native/pal_timeZoneInfo.m similarity index 100% rename from src/native/libs/System.Globalization.Native/pal_timeZoneInfo.m rename to src/native/libs/System.HybridGlobalization.Native/pal_timeZoneInfo.m diff --git a/src/native/libs/build-native.proj b/src/native/libs/build-native.proj index bbf272365a899..f0b394604a7a2 100644 --- a/src/native/libs/build-native.proj +++ b/src/native/libs/build-native.proj @@ -16,7 +16,7 @@ <_UsePThreads /> <_UsePThreads Condition="'$(MonoWasmBuildVariant)' == 'multithread'"> usepthreads - <_IcuDir Condition="'$(TargetsAppleMobile)' != 'true' and '$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)' != ''">$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)/runtimes/$(TargetOS)-$(TargetArchitecture)$(_RuntimeVariant)/native + <_IcuDir Condition="'$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)' != ''">$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)/runtimes/$(TargetOS)-$(TargetArchitecture)$(_RuntimeVariant)/native <_IcuDirArg Condition="'$(_IcuDir)' != ''"> icudir "$(_IcuDir)" <_BuildNativeArgs>$(_BuildNativeArgs)$(_IcuDirArg)$(_UsePThreads) @@ -55,7 +55,7 @@ - <_IcuArtifacts Condition="'$(_IcuDir)' != '' and '$(TargetsAppleMobile)' != 'true'" + <_IcuArtifacts Condition="'$(_IcuDir)' != ''" Include="$(_IcuDir)/lib/libicuuc.a; $(_IcuDir)/lib/libicui18n.a; $(_IcuDir)/lib/libicudata.a; diff --git a/src/tasks/AppleAppBuilder/Templates/runtime.m b/src/tasks/AppleAppBuilder/Templates/runtime.m index 3d825f50f0079..925e8175fc73d 100644 --- a/src/tasks/AppleAppBuilder/Templates/runtime.m +++ b/src/tasks/AppleAppBuilder/Templates/runtime.m @@ -261,6 +261,10 @@ static bool is_pinvoke_override_library (const char* libraryName) setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1", TRUE); #endif +#if HYBRID_GLOBALIZATION + setenv ("DOTNET_SYSTEM_GLOBALIZATION_HYBRID", "1", TRUE); +#endif + #if ENABLE_RUNTIME_LOGGING setenv ("MONO_LOG_LEVEL", "debug", TRUE); setenv ("MONO_LOG_MASK", "all", TRUE); From 6fd58f0cace48cc5ad484f0866d5f6a4722808b3 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Mon, 22 Jan 2024 12:58:54 +0100 Subject: [PATCH 02/30] Fix build on Apple platforms --- src/coreclr/vm/pinvokeoverride.cpp | 1 + .../libs/System.HybridGlobalization.Native/CMakeLists.txt | 2 +- .../libs/System.HybridGlobalization.Native/entrypoints.c | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/coreclr/vm/pinvokeoverride.cpp b/src/coreclr/vm/pinvokeoverride.cpp index 1b65b5b8d7c9f..e192b2cf23dc2 100644 --- a/src/coreclr/vm/pinvokeoverride.cpp +++ b/src/coreclr/vm/pinvokeoverride.cpp @@ -11,6 +11,7 @@ #include "pinvokeoverride.h" extern "C" const void* GlobalizationResolveDllImport(const char* name); +extern "C" const void* HybridGlobalizationResolveDllImport(const char* name); namespace { diff --git a/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt b/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt index 479f88b131e17..56adce424a40e 100644 --- a/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt +++ b/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt @@ -88,7 +88,7 @@ if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CM link_libraries(stdc++) endif() -if ((CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) AND NOT DEFINED CMAKE_ICU_DIR) +if ((CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS)) link_libraries(icucore) endif() diff --git a/src/native/libs/System.HybridGlobalization.Native/entrypoints.c b/src/native/libs/System.HybridGlobalization.Native/entrypoints.c index 91bda0a13b551..9f1766747aa01 100644 --- a/src/native/libs/System.HybridGlobalization.Native/entrypoints.c +++ b/src/native/libs/System.HybridGlobalization.Native/entrypoints.c @@ -84,9 +84,9 @@ static const Entry s_globalizationNative[] = DllImportEntry(GlobalizationNative_InitOrdinalCasingPage) }; -EXTERN_C const void* GlobalizationResolveDllImport(const char* name); +EXTERN_C const void* HybridGlobalizationResolveDllImport(const char* name); -EXTERN_C const void* GlobalizationResolveDllImport(const char* name) +EXTERN_C const void* HybridGlobalizationResolveDllImport(const char* name) { return minipal_resolve_dllimport(s_globalizationNative, ARRAY_SIZE(s_globalizationNative), name); } \ No newline at end of file From d0a6820c63e8e87fe7125634227549ff8d989712 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Mon, 22 Jan 2024 14:59:10 +0100 Subject: [PATCH 03/30] HYBRID_GLOBALIZATION_DLL_NAME define only for Apple --- src/coreclr/vm/pinvokeoverride.cpp | 1 + src/tasks/AppleAppBuilder/Templates/main-console.m | 4 ++++ src/tasks/AppleAppBuilder/Templates/main-simple.m | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/src/coreclr/vm/pinvokeoverride.cpp b/src/coreclr/vm/pinvokeoverride.cpp index e192b2cf23dc2..beb3021ea3088 100644 --- a/src/coreclr/vm/pinvokeoverride.cpp +++ b/src/coreclr/vm/pinvokeoverride.cpp @@ -23,6 +23,7 @@ namespace #define GLOBALIZATION_DLL_NAME "System.Globalization.Native" #else #define GLOBALIZATION_DLL_NAME "libSystem.Globalization.Native" +#if defined(__APPLE__) #define HYBRID_GLOBALIZATION_DLL_NAME "libSystem.HybridGlobalization.Native" #endif diff --git a/src/tasks/AppleAppBuilder/Templates/main-console.m b/src/tasks/AppleAppBuilder/Templates/main-console.m index bd3a9e78ca0e1..ffd703f32a6cd 100644 --- a/src/tasks/AppleAppBuilder/Templates/main-console.m +++ b/src/tasks/AppleAppBuilder/Templates/main-console.m @@ -81,6 +81,10 @@ - (void)viewDidLoad { #if INVARIANT_GLOBALIZATION setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1", TRUE); #endif // INVARIANT_GLOBALIZATION + +#if HYBRID_GLOBALIZATION + setenv ("DOTNET_SYSTEM_GLOBALIZATION_HYBRID", "1", TRUE); +#endif // HYBRID_GLOBALIZATION char **managed_argv; int managed_argc = get_managed_args (&managed_argv); int ret_val = __managed__Main (managed_argc, managed_argv); diff --git a/src/tasks/AppleAppBuilder/Templates/main-simple.m b/src/tasks/AppleAppBuilder/Templates/main-simple.m index 36bf576d51397..cb689b50b04ba 100644 --- a/src/tasks/AppleAppBuilder/Templates/main-simple.m +++ b/src/tasks/AppleAppBuilder/Templates/main-simple.m @@ -57,6 +57,10 @@ - (void)viewDidLoad { #if INVARIANT_GLOBALIZATION setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1", TRUE); #endif + +#if HYBRID_GLOBALIZATION + setenv ("DOTNET_SYSTEM_GLOBALIZATION_HYBRID", "1", TRUE); +#endif char **managed_argv; int managed_argc = get_managed_args (&managed_argv); int ret_val = __managed__Main (managed_argc, managed_argv); From 9d91003e4d3c697aac8205b9a0478326214a0b8a Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Mon, 22 Jan 2024 15:48:51 +0100 Subject: [PATCH 04/30] Fix build failure --- src/coreclr/vm/pinvokeoverride.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/coreclr/vm/pinvokeoverride.cpp b/src/coreclr/vm/pinvokeoverride.cpp index beb3021ea3088..136e35bc01b0e 100644 --- a/src/coreclr/vm/pinvokeoverride.cpp +++ b/src/coreclr/vm/pinvokeoverride.cpp @@ -26,6 +26,7 @@ namespace #if defined(__APPLE__) #define HYBRID_GLOBALIZATION_DLL_NAME "libSystem.HybridGlobalization.Native" #endif +#endif // here we handle PInvokes whose implementation is always statically linked (even in .so/.dll case) static const void* DefaultResolveDllImport(const char* libraryName, const char* entrypointName) @@ -34,12 +35,13 @@ static const void* DefaultResolveDllImport(const char* libraryName, const char* { return GlobalizationResolveDllImport(entrypointName); } +#if defined(__APPLE__) // Add hybrid globalization here if (strcmp(libraryName, HYBRID_GLOBALIZATION_DLL_NAME) == 0) { return HybridGlobalizationResolveDllImport(entrypointName); } - +#endif return nullptr; } From 29a248ea7d5dd9c83d17157dccb3a681aee6bd90 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Mon, 22 Jan 2024 17:06:29 +0100 Subject: [PATCH 05/30] Fix non-Apple build --- .../Microsoft.NETCore.Native.Unix.targets | 3 +- .../Microsoft.DotNet.ILCompiler.pkgproj | 1 - .../corehost/apphost/static/CMakeLists.txt | 7 +- .../pal_placeholders.c | 276 ------------------ .../CMakeLists.txt | 14 +- 5 files changed, 12 insertions(+), 289 deletions(-) delete mode 100644 src/native/libs/System.Globalization.Native/pal_placeholders.c diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 19485ec753df5..53d675270398e 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -115,7 +115,8 @@ The .NET Foundation licenses this file to you under the MIT license. - + + diff --git a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj index 5612e5b3f3cc1..3995419fc9098 100644 --- a/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj +++ b/src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/Microsoft.DotNet.ILCompiler.pkgproj @@ -18,7 +18,6 @@ - diff --git a/src/native/corehost/apphost/static/CMakeLists.txt b/src/native/corehost/apphost/static/CMakeLists.txt index 68231734bdc70..8cb3f0a535ed1 100644 --- a/src/native/corehost/apphost/static/CMakeLists.txt +++ b/src/native/corehost/apphost/static/CMakeLists.txt @@ -114,10 +114,8 @@ endif() if(CLR_CMAKE_TARGET_WIN32) set(NATIVE_LIBS coreclr_static - System.Globalization.Native-Static System.IO.Compression.Native-Static - kernel32.lib advapi32.lib ole32.lib @@ -138,12 +136,13 @@ else() if(CLR_CMAKE_HOST_OSX OR (CLR_CMAKE_HOST_LINUX AND NOT CLR_CMAKE_HOST_UNIX_X86 AND NOT CLR_CMAKE_HOST_ANDROID)) LIST(APPEND NATIVE_LIBS createdump_static) endif() + if(CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) + LIST(APPEND NATIVE_LIBS System.HybridGlobalization.Native-Static) + endif() LIST(APPEND NATIVE_LIBS coreclr_static - System.Globalization.Native-Static - System.HybridGlobalization.Native-Static System.IO.Compression.Native-Static System.Net.Security.Native-Static System.Native-Static diff --git a/src/native/libs/System.Globalization.Native/pal_placeholders.c b/src/native/libs/System.Globalization.Native/pal_placeholders.c deleted file mode 100644 index 7d0f9624e082b..0000000000000 --- a/src/native/libs/System.Globalization.Native/pal_placeholders.c +++ /dev/null @@ -1,276 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#include -#include - -#include "pal_icushim_internal.h" -#include "pal_icushim.h" -#include "pal_calendarData.h" -#include "pal_casing.h" -#include "pal_collation.h" -#include "pal_locale.h" -#include "pal_localeNumberData.h" -#include "pal_localeStringData.h" -#include "pal_normalization.h" -#include "pal_timeZoneInfo.h" - -#ifdef DEBUG -#define assert_err(cond, msg, err) do \ -{ \ - if(!(cond)) \ - { \ - fprintf(stderr, "%s (%d): error %d: %s. %s (%s failed)\n", __FILE__, __LINE__, err, msg, strerror(err), #cond); \ - assert(false && "assert_err failed"); \ - } \ -} while(0) -#define assert_msg(cond, msg, val) do \ -{ \ - if(!(cond)) \ - { \ - fprintf(stderr, "%s (%d): error %d: %s (%s failed)\n", __FILE__, __LINE__, val, msg, #cond); \ - assert(false && "assert_msg failed"); \ - } \ -} while(0) -#else // DEBUG -#define assert_err(cond, msg, err) -#define assert_msg(cond, msg, val) -#endif // DEBUG - - -// Placeholder for calendar data -int32_t GlobalizationNative_GetCalendars( - const UChar* localeName, CalendarId* calendars, int32_t calendarsCapacity) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -ResultCode GlobalizationNative_GetCalendarInfo( - const UChar* localeName, CalendarId calendarId, CalendarDataType dataType, UChar* result, int32_t resultCapacity) -{ - assert_msg(false, "Not supported on this platform", 0); - return UnknownError; -} - -int32_t GlobalizationNative_EnumCalendarInfo( - EnumCalendarInfoCallback callback, const UChar* localeName, CalendarId calendarId, CalendarDataType dataType, const void* context) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_GetLatestJapaneseEra(void) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_GetJapaneseEraStartDate( - int32_t era, int32_t* startYear, int32_t* startMonth, int32_t* startDay) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -// Placeholder for casing data -void GlobalizationNative_ChangeCase( - const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength, int32_t bToUpper) -{ - assert_msg(false, "Not supported on this platform", 0); -} - -void GlobalizationNative_ChangeCaseInvariant( - const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength, int32_t bToUpper) -{ - assert_msg(false, "Not supported on this platform", 0); -} - -void GlobalizationNative_ChangeCaseTurkish( - const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength, int32_t bToUpper) -{ - assert_msg(false, "Not supported on this platform", 0); -} - -// Placeholder for collation data -ResultCode GlobalizationNative_GetSortHandle( - const char* lpLocaleName, SortHandle** pSortHandle) -{ - assert_msg(false, "Not supported on this platform", 0); - return UnknownError; -} - -void GlobalizationNative_CloseSortHandle(SortHandle* pSortHandle) -{ - assert_msg(false, "Not supported on this platform", 0); -} - -int32_t GlobalizationNative_GetSortVersion(SortHandle* pSortHandle) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_CompareString( - SortHandle* pSortHandle, const UChar* lpStr1, int32_t cwStr1Length, const UChar* lpStr2, int32_t cwStr2Length, int32_t options) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_IndexOf( - SortHandle* pSortHandle, const UChar* lpTarget, int32_t cwTargetLength, const UChar* lpSource, int32_t cwSourceLength, int32_t options, int32_t* pMatchedLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_LastIndexOf( - SortHandle* pSortHandle, const UChar* lpTarget, int32_t cwTargetLength, const UChar* lpSource, int32_t cwSourceLength, int32_t options, int32_t* pMatchedLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_StartsWith( - SortHandle* pSortHandle, const UChar* lpTarget, int32_t cwTargetLength, const UChar* lpSource, int32_t cwSourceLength, int32_t options, int32_t* pMatchedLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_EndsWith( - SortHandle* pSortHandle, const UChar* lpTarget, int32_t cwTargetLength, const UChar* lpSource, int32_t cwSourceLength, int32_t options, int32_t* pMatchedLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_GetSortKey( - SortHandle* pSortHandle, const UChar* lpStr, int32_t cwStrLength, uint8_t* sortKey, int32_t cbSortKeyLength, int32_t options) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -// Placeholder for locale data -int32_t GlobalizationNative_GetLocales( - UChar *value, int32_t valueLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_GetLocaleName( - const UChar* localeName, UChar* value, int32_t valueLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_GetDefaultLocaleName( - UChar* value, int32_t valueLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_IsPredefinedLocale( - const UChar* localeName) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_GetLocaleTimeFormat( - const UChar* localeName, int shortFormat, UChar* value, int32_t valueLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -// Placeholder for locale number data -int32_t GlobalizationNative_GetLocaleInfoInt( - const UChar* localeName, LocaleNumberData localeNumberData, int32_t* value) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_GetLocaleInfoGroupingSizes( - const UChar* localeName, LocaleNumberData localeGroupingData, int32_t* primaryGroupSize, int32_t* secondaryGroupSize) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -// Placeholder for icu shim data -int32_t GlobalizationNative_LoadICU(void) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -void GlobalizationNative_InitICUFunctions( - void* icuuc, void* icuin, const char* version, const char* suffix) -{ - assert_msg(false, "Not supported on this platform", 0); -} - -int32_t GlobalizationNative_GetICUVersion(void) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t -GlobalizationNative_LoadICUData(const char* path) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -// Placeholder for locale string data -int32_t GlobalizationNative_GetLocaleInfoString( - const UChar* localeName, LocaleStringData localeStringData, UChar* value, int32_t valueLength, const UChar* uiLocaleName) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -//Placeholder for normalization data -int32_t GlobalizationNative_IsNormalized( - NormalizationForm normalizationForm, const UChar* lpStr, int32_t cwStrLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_NormalizeString( - NormalizationForm normalizationForm, const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -// Placeholder for time zone data -int32_t GlobalizationNative_WindowsIdToIanaId( - const UChar* windowsId, const char* region, UChar* ianaId, int32_t ianaIdLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -ResultCode GlobalizationNative_GetTimeZoneDisplayName( - const UChar* localeName, const UChar* timeZoneId, TimeZoneDisplayNameType type, UChar* result, int32_t resultLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return UnknownError; -} - -int32_t GlobalizationNative_IanaIdToWindowsId( - const UChar* ianaId, UChar* windowsId, int32_t windowsIdLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} diff --git a/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt b/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt index 56adce424a40e..5722620d44b41 100644 --- a/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt +++ b/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt @@ -126,10 +126,10 @@ if (CLR_CMAKE_TARGET_APPLE) set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} ${NATIVEGLOBALIZATION_SOURCES_OBJC}) endif() -# time zone names are filtered out of icu data for the browser and associated functionality is disabled -if (NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) - set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_timeZoneInfo.c) -endif() +# # time zone names are filtered out of icu data for the browser and associated functionality is disabled +# if (NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) +# set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_timeZoneInfo.c) +# endif() if (MSVC) set_source_files_properties(${NATIVEGLOBALIZATION_SOURCES} PROPERTIES LANGUAGE CXX) @@ -164,9 +164,9 @@ add_library(System.HybridGlobalization.Native-Static entrypoints.c ) -if(CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_WASI) - set_target_properties(System.HybridGlobalization.Native-Static PROPERTIES OUTPUT_NAME System.HybridGlobalization.Native CLEAN_DIRECT_OUTPUT 1) -endif() +# if(CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_WASI) +# set_target_properties(System.HybridGlobalization.Native-Static PROPERTIES OUTPUT_NAME System.HybridGlobalization.Native CLEAN_DIRECT_OUTPUT 1) +# endif() install (TARGETS System.HybridGlobalization.Native-Static DESTINATION ${STATIC_LIB_DESTINATION} COMPONENT libs) From 8bc9d03621966e304ba7f0fc620d935a5fb7904c Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Mon, 22 Jan 2024 17:51:59 +0100 Subject: [PATCH 06/30] Fix syntax error --- .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 53d675270398e..e908b663c0a6e 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -115,7 +115,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + From 50f4ce89a2eac57bd7bb29e8450c1d727f353508 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Mon, 22 Jan 2024 19:04:25 +0100 Subject: [PATCH 07/30] Fix linux builds --- .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index e908b663c0a6e..5f3214a17a92a 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -116,7 +116,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + From b082055f448a90e7bbdf534fd7388de32a068913 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Tue, 23 Jan 2024 13:42:10 +0100 Subject: [PATCH 08/30] Fix duplicate symbol issue --- src/native/corehost/apphost/static/CMakeLists.txt | 6 +++--- .../libs/System.HybridGlobalization.Native/CMakeLists.txt | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/native/corehost/apphost/static/CMakeLists.txt b/src/native/corehost/apphost/static/CMakeLists.txt index 8cb3f0a535ed1..707c8b8598f00 100644 --- a/src/native/corehost/apphost/static/CMakeLists.txt +++ b/src/native/corehost/apphost/static/CMakeLists.txt @@ -136,9 +136,9 @@ else() if(CLR_CMAKE_HOST_OSX OR (CLR_CMAKE_HOST_LINUX AND NOT CLR_CMAKE_HOST_UNIX_X86 AND NOT CLR_CMAKE_HOST_ANDROID)) LIST(APPEND NATIVE_LIBS createdump_static) endif() - if(CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) - LIST(APPEND NATIVE_LIBS System.HybridGlobalization.Native-Static) - endif() + # if(CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) + # LIST(APPEND NATIVE_LIBS System.HybridGlobalization.Native-Static) + # endif() LIST(APPEND NATIVE_LIBS coreclr_static diff --git a/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt b/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt index 5722620d44b41..1f72e8d9e6ee8 100644 --- a/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt +++ b/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt @@ -164,9 +164,9 @@ add_library(System.HybridGlobalization.Native-Static entrypoints.c ) -# if(CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_WASI) -# set_target_properties(System.HybridGlobalization.Native-Static PROPERTIES OUTPUT_NAME System.HybridGlobalization.Native CLEAN_DIRECT_OUTPUT 1) -# endif() +if(CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_WASI) + set_target_properties(System.HybridGlobalization.Native-Static PROPERTIES OUTPUT_NAME System.HybridGlobalization.Native CLEAN_DIRECT_OUTPUT 1) +endif() install (TARGETS System.HybridGlobalization.Native-Static DESTINATION ${STATIC_LIB_DESTINATION} COMPONENT libs) From e1ac526ed3ed634f7dd7d243f11b96d07d0e607c Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Tue, 23 Jan 2024 14:50:49 +0100 Subject: [PATCH 09/30] Filter in Xcode libs depending on hybrid mode, pinvoke changes --- src/coreclr/vm/pinvokeoverride.cpp | 11 ----------- .../src/Interop/Unix/Interop.Libraries.cs | 4 +++- src/mono/mono/metadata/native-library.c | 19 ------------------- src/tasks/AppleAppBuilder/Xcode.cs | 8 ++++++++ 4 files changed, 11 insertions(+), 31 deletions(-) diff --git a/src/coreclr/vm/pinvokeoverride.cpp b/src/coreclr/vm/pinvokeoverride.cpp index 136e35bc01b0e..b5532c529e2eb 100644 --- a/src/coreclr/vm/pinvokeoverride.cpp +++ b/src/coreclr/vm/pinvokeoverride.cpp @@ -11,7 +11,6 @@ #include "pinvokeoverride.h" extern "C" const void* GlobalizationResolveDllImport(const char* name); -extern "C" const void* HybridGlobalizationResolveDllImport(const char* name); namespace { @@ -23,9 +22,6 @@ namespace #define GLOBALIZATION_DLL_NAME "System.Globalization.Native" #else #define GLOBALIZATION_DLL_NAME "libSystem.Globalization.Native" -#if defined(__APPLE__) -#define HYBRID_GLOBALIZATION_DLL_NAME "libSystem.HybridGlobalization.Native" -#endif #endif // here we handle PInvokes whose implementation is always statically linked (even in .so/.dll case) @@ -35,13 +31,6 @@ static const void* DefaultResolveDllImport(const char* libraryName, const char* { return GlobalizationResolveDllImport(entrypointName); } -#if defined(__APPLE__) - // Add hybrid globalization here - if (strcmp(libraryName, HYBRID_GLOBALIZATION_DLL_NAME) == 0) - { - return HybridGlobalizationResolveDllImport(entrypointName); - } -#endif return nullptr; } diff --git a/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs b/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs index 7ec51da64f254..4f64014c289b5 100644 --- a/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs +++ b/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs @@ -12,7 +12,9 @@ internal static partial class Libraries internal const string NetSecurityNative = "libSystem.Net.Security.Native"; internal const string CryptoNative = "libSystem.Security.Cryptography.Native.OpenSsl"; internal const string CompressionNative = "libSystem.IO.Compression.Native"; - internal const string GlobalizationNative = "libSystem.Globalization.Native"; + // change this temporary + internal const string GlobalizationNative = "libSystem.HybridGlobalization.Native"; + internal const string HybridGlobalizationNative = "libSystem.HybridGlobalization.Native"; internal const string IOPortsNative = "libSystem.IO.Ports.Native"; internal const string HostPolicy = "libhostpolicy"; } diff --git a/src/mono/mono/metadata/native-library.c b/src/mono/mono/metadata/native-library.c index 4d02d2a2fe05f..8d393aaaaf38e 100644 --- a/src/mono/mono/metadata/native-library.c +++ b/src/mono/mono/metadata/native-library.c @@ -786,25 +786,6 @@ get_dllimportsearchpath_flags (MonoCustomAttrInfo *cinfo) return flags; } -// #ifndef NO_GLOBALIZATION_SHIM -// #ifdef HOST_WIN32 -// #define GLOBALIZATION_DLL_NAME "System.Globalization.Native" -// #else -// #define GLOBALIZATION_DLL_NAME "libSystem.Globalization.Native" -// #endif - -// static gpointer -// default_resolve_dllimport (const char *dll, const char *func) -// { -// if (strcmp (dll, GLOBALIZATION_DLL_NAME) == 0) { -// const void *method_impl = GlobalizationResolveDllImport (func); -// if (method_impl) -// return (gpointer)method_impl; -// } - -// return NULL; -// } -// #endif // NO_GLOBALIZATION_SHIM gpointer lookup_pinvoke_call_impl (MonoMethod *method, MonoLookupPInvokeStatus *status_out) diff --git a/src/tasks/AppleAppBuilder/Xcode.cs b/src/tasks/AppleAppBuilder/Xcode.cs index a9bf648f8129a..7fa6b66c5ed19 100644 --- a/src/tasks/AppleAppBuilder/Xcode.cs +++ b/src/tasks/AppleAppBuilder/Xcode.cs @@ -405,6 +405,10 @@ public string GenerateCMake( continue; string libName = Path.GetFileNameWithoutExtension(lib); + if(libName.StartsWith("libSystem.Globalization", StringComparison.OrdinalIgnoreCase) && hybridGlobalization) + continue; + else if (libName.StartsWith("libSystem.HybridGlobalization", StringComparison.OrdinalIgnoreCase) && !hybridGlobalization) + continue; // libmono must always be statically linked, for other librarires we can use dylibs bool dylibExists = libName != "libmonosgen-2.0" && dylibs.Any(dylib => Path.GetFileName(dylib) == libName + ".dylib"); @@ -532,6 +536,10 @@ public string GenerateCMake( foreach (string aFile in Directory.GetFiles(workspace, "*.a")) { string aFileName = Path.GetFileNameWithoutExtension(aFile); + if(aFileName.StartsWith("libSystem.Globalization", StringComparison.OrdinalIgnoreCase) && hybridGlobalization) + continue; + else if (aFileName.StartsWith("libSystem.HybridGlobalization", StringComparison.OrdinalIgnoreCase) && !hybridGlobalization) + continue; pinvokeOverrides.AppendLine($" \"{aFileName}\","); // also register with or without "lib" prefix From 156620007c504e97cd9f5090a33533279cb6284b Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Tue, 23 Jan 2024 14:57:09 +0100 Subject: [PATCH 10/30] Revert not needed changes --- src/mono/mono/metadata/native-library.c | 10 ---------- src/native/corehost/apphost/static/CMakeLists.txt | 3 +++ 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/mono/mono/metadata/native-library.c b/src/mono/mono/metadata/native-library.c index 8d393aaaaf38e..7a3588ed20229 100644 --- a/src/mono/mono/metadata/native-library.c +++ b/src/mono/mono/metadata/native-library.c @@ -47,10 +47,6 @@ static GHashTable *native_library_module_map; */ static GHashTable *native_library_module_blocklist; -// #ifndef NO_GLOBALIZATION_SHIM -// extern const void *GlobalizationResolveDllImport (const char *name); -// #endif - static GHashTable *global_module_map; // should only be accessed with the global loader data lock static MonoDl *internal_module; // used when pinvoking `__Internal` @@ -862,12 +858,6 @@ lookup_pinvoke_call_impl (MonoMethod *method, MonoLookupPInvokeStatus *status_ou } #endif -// #ifndef NO_GLOBALIZATION_SHIM -// addr = default_resolve_dllimport (new_scope, new_import); -// if (addr) -// goto exit; -// #endif - if (pinvoke_override) { addr = pinvoke_override (new_scope, new_import); if (addr) diff --git a/src/native/corehost/apphost/static/CMakeLists.txt b/src/native/corehost/apphost/static/CMakeLists.txt index 707c8b8598f00..f263d6ae1cd77 100644 --- a/src/native/corehost/apphost/static/CMakeLists.txt +++ b/src/native/corehost/apphost/static/CMakeLists.txt @@ -114,8 +114,10 @@ endif() if(CLR_CMAKE_TARGET_WIN32) set(NATIVE_LIBS coreclr_static + System.Globalization.Native-Static System.IO.Compression.Native-Static + kernel32.lib advapi32.lib ole32.lib @@ -142,6 +144,7 @@ else() LIST(APPEND NATIVE_LIBS coreclr_static + System.Globalization.Native-Static System.IO.Compression.Native-Static System.Net.Security.Native-Static From f660f6d52a95e897cf3aea07accbeecfeac6a37c Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Tue, 23 Jan 2024 14:59:10 +0100 Subject: [PATCH 11/30] Revert changes --- src/coreclr/vm/pinvokeoverride.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coreclr/vm/pinvokeoverride.cpp b/src/coreclr/vm/pinvokeoverride.cpp index b5532c529e2eb..d8f1d0972a399 100644 --- a/src/coreclr/vm/pinvokeoverride.cpp +++ b/src/coreclr/vm/pinvokeoverride.cpp @@ -31,6 +31,7 @@ static const void* DefaultResolveDllImport(const char* libraryName, const char* { return GlobalizationResolveDllImport(entrypointName); } + return nullptr; } From 4d009b184ab443e167e83ffbaa093f1adf3526f6 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Tue, 23 Jan 2024 16:17:33 +0100 Subject: [PATCH 12/30] Fix ICU lib flow --- eng/testing/tests.ioslike.targets | 2 +- .../src/Interop/Interop.Calendar.iOS.cs | 8 ++++---- .../Common/src/Interop/Interop.Casing.iOS.cs | 7 +++++-- .../src/Interop/Interop.Collation.iOS.cs | 10 +++++----- .../Common/src/Interop/Interop.Idna.iOS.cs | 17 ++++++++++++++++ .../Common/src/Interop/Interop.Locale.iOS.cs | 18 ++++++++--------- .../src/Interop/Interop.Normalization.iOS.cs | 4 ++-- .../src/Interop/Interop.TimeZoneInfo.iOS.cs | 2 +- .../src/Interop/Unix/Interop.Libraries.cs | 3 +-- .../System.Private.CoreLib.Shared.projitems | 3 +++ .../pal_icushim_static.c | 7 ++----- .../System.Globalization.Native/pal_locale.m | 20 +++++++++++++++++++ 12 files changed, 70 insertions(+), 31 deletions(-) create mode 100644 src/libraries/Common/src/Interop/Interop.Idna.iOS.cs diff --git a/eng/testing/tests.ioslike.targets b/eng/testing/tests.ioslike.targets index d4dfbe3ebe1e4..73ce3e606a94f 100644 --- a/eng/testing/tests.ioslike.targets +++ b/eng/testing/tests.ioslike.targets @@ -159,7 +159,7 @@ - true + true true AppleTestRunner.dll diff --git a/src/libraries/Common/src/Interop/Interop.Calendar.iOS.cs b/src/libraries/Common/src/Interop/Interop.Calendar.iOS.cs index 985e55b604e4f..5decc623f458e 100644 --- a/src/libraries/Common/src/Interop/Interop.Calendar.iOS.cs +++ b/src/libraries/Common/src/Interop/Interop.Calendar.iOS.cs @@ -9,16 +9,16 @@ internal static partial class Interop { internal static partial class Globalization { - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetCalendarsNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetCalendarsNative", StringMarshalling = StringMarshalling.Utf8)] internal static partial int GetCalendarsNative(string localeName, CalendarId[] calendars, int calendarsCapacity); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetCalendarInfoNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetCalendarInfoNative", StringMarshalling = StringMarshalling.Utf8)] internal static partial string GetCalendarInfoNative(string localeName, CalendarId calendarId, CalendarDataType calendarDataType); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLatestJapaneseEraNative")] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetLatestJapaneseEraNative")] internal static partial int GetLatestJapaneseEraNative(); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetJapaneseEraStartDateNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetJapaneseEraStartDateNative", StringMarshalling = StringMarshalling.Utf8)] [return: MarshalAs(UnmanagedType.Bool)] internal static partial bool GetJapaneseEraStartDateNative(int era, out int startYear, out int startMonth, out int startDay); diff --git a/src/libraries/Common/src/Interop/Interop.Casing.iOS.cs b/src/libraries/Common/src/Interop/Interop.Casing.iOS.cs index 5e0140faa4c43..4d9907c2ef338 100644 --- a/src/libraries/Common/src/Interop/Interop.Casing.iOS.cs +++ b/src/libraries/Common/src/Interop/Interop.Casing.iOS.cs @@ -7,10 +7,13 @@ internal static partial class Interop { internal static partial class Globalization { - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_ChangeCaseNative", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_ChangeCaseNative", StringMarshalling = StringMarshalling.Utf16)] internal static unsafe partial int ChangeCaseNative(string localeName, int lNameLen, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, [MarshalAs(UnmanagedType.Bool)] bool bToUpper); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_ChangeCaseInvariantNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_ChangeCaseInvariantNative", StringMarshalling = StringMarshalling.Utf8)] internal static unsafe partial int ChangeCaseInvariantNative(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, [MarshalAs(UnmanagedType.Bool)] bool bToUpper); + + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_InitOrdinalCasingPage", StringMarshalling = StringMarshalling.Utf16)] + internal static unsafe partial void InitOrdinalCasingPageNative(int pageNumber, char* pTarget); } } diff --git a/src/libraries/Common/src/Interop/Interop.Collation.iOS.cs b/src/libraries/Common/src/Interop/Interop.Collation.iOS.cs index 2dba31ddcd70e..32491721cafc9 100644 --- a/src/libraries/Common/src/Interop/Interop.Collation.iOS.cs +++ b/src/libraries/Common/src/Interop/Interop.Collation.iOS.cs @@ -16,21 +16,21 @@ internal struct Range internal static partial class Globalization { - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_CompareStringNative", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_CompareStringNative", StringMarshalling = StringMarshalling.Utf16)] internal static unsafe partial int CompareStringNative(string localeName, int lNameLen, char* lpStr1, int cwStr1Len, char* lpStr2, int cwStr2Len, CompareOptions options); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_EndsWithNative", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_EndsWithNative", StringMarshalling = StringMarshalling.Utf16)] [MethodImpl(MethodImplOptions.NoInlining)] internal static unsafe partial int EndsWithNative(string localeName, int lNameLen, char* target, int cwTargetLength, char* source, int cwSourceLength, CompareOptions options); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_IndexOfNative", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_IndexOfNative", StringMarshalling = StringMarshalling.Utf16)] internal static unsafe partial Range IndexOfNative(string localeName, int lNameLen, char* target, int cwTargetLength, char* pSource, int cwSourceLength, CompareOptions options, [MarshalAs(UnmanagedType.Bool)] bool fromBeginning); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_StartsWithNative", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_StartsWithNative", StringMarshalling = StringMarshalling.Utf16)] [MethodImpl(MethodImplOptions.NoInlining)] internal static unsafe partial int StartsWithNative(string localeName, int lNameLen, char* target, int cwTargetLength, char* source, int cwSourceLength, CompareOptions options); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetSortKeyNative", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetSortKeyNative", StringMarshalling = StringMarshalling.Utf16)] internal static unsafe partial int GetSortKeyNative(string localeName, int lNameLen, char* str, int strLength, byte* sortKey, int sortKeyLength, CompareOptions options); } } diff --git a/src/libraries/Common/src/Interop/Interop.Idna.iOS.cs b/src/libraries/Common/src/Interop/Interop.Idna.iOS.cs new file mode 100644 index 0000000000000..5d72c201f4f9d --- /dev/null +++ b/src/libraries/Common/src/Interop/Interop.Idna.iOS.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class Globalization + { + + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_ToAscii", StringMarshalling = StringMarshalling.Utf16)] + internal static unsafe partial int ToAsciiNative(uint flags, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity); + + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_ToUnicode", StringMarshalling = StringMarshalling.Utf16)] + internal static unsafe partial int ToUnicodeNative(uint flags, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity); + } +} diff --git a/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs b/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs index d0049b7a7a173..67de37e519c3e 100644 --- a/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs +++ b/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs @@ -7,31 +7,31 @@ internal static partial class Interop { internal static partial class Globalization { - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetDefaultLocaleNameNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetDefaultLocaleNameNative", StringMarshalling = StringMarshalling.Utf8)] internal static partial string GetDefaultLocaleNameNative(); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoStringNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoStringNative", StringMarshalling = StringMarshalling.Utf8)] internal static partial string GetLocaleInfoStringNative(string localeName, uint localeStringData, string? uiLocaleName = null); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoIntNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoIntNative", StringMarshalling = StringMarshalling.Utf8)] internal static partial int GetLocaleInfoIntNative(string localeName, uint localeNumberData); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative", StringMarshalling = StringMarshalling.Utf8)] internal static partial int GetLocaleInfoPrimaryGroupingSizeNative(string localeName, uint localeGroupingData); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative", StringMarshalling = StringMarshalling.Utf8)] internal static partial int GetLocaleInfoSecondaryGroupingSizeNative(string localeName, uint localeGroupingData); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleNameNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleNameNative", StringMarshalling = StringMarshalling.Utf8)] internal static partial string GetLocaleNameNative(string localeName); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocalesNative", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetLocalesNative", StringMarshalling = StringMarshalling.Utf16)] internal static partial int GetLocalesNative([Out] char[]? value, int valueLength); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleTimeFormatNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleTimeFormatNative", StringMarshalling = StringMarshalling.Utf8)] internal static partial string GetLocaleTimeFormatNative(string localeName, [MarshalAs(UnmanagedType.Bool)] bool shortFormat); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_IsPredefinedLocaleNative", StringMarshalling = StringMarshalling.Utf8)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_IsPredefinedLocaleNative", StringMarshalling = StringMarshalling.Utf8)] [return: MarshalAs(UnmanagedType.Bool)] internal static partial bool IsPredefinedLocaleNative(string localeName); } diff --git a/src/libraries/Common/src/Interop/Interop.Normalization.iOS.cs b/src/libraries/Common/src/Interop/Interop.Normalization.iOS.cs index 4ba97148b4538..001335fd29bf6 100644 --- a/src/libraries/Common/src/Interop/Interop.Normalization.iOS.cs +++ b/src/libraries/Common/src/Interop/Interop.Normalization.iOS.cs @@ -8,10 +8,10 @@ internal static partial class Interop { internal static partial class Globalization { - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_IsNormalizedNative", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_IsNormalizedNative", StringMarshalling = StringMarshalling.Utf16)] internal static unsafe partial int IsNormalizedNative(NormalizationForm normalizationForm, char* src, int srcLen); - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_NormalizeStringNative", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_NormalizeStringNative", StringMarshalling = StringMarshalling.Utf16)] internal static unsafe partial int NormalizeStringNative(NormalizationForm normalizationForm, char* src, int srcLen, char* buffer, int bufferLength); } } diff --git a/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.iOS.cs b/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.iOS.cs index 9575fc3dc3359..e61c5b30cab93 100644 --- a/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.iOS.cs +++ b/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.iOS.cs @@ -8,7 +8,7 @@ internal static partial class Interop { internal static partial class Globalization { - [LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetTimeZoneDisplayNameNative", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport(Libraries.HybridGlobalizationNative, EntryPoint = "GlobalizationNative_GetTimeZoneDisplayNameNative", StringMarshalling = StringMarshalling.Utf16)] internal static unsafe partial ResultCode GetTimeZoneDisplayNameNative( string localeName, int lNameLength, diff --git a/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs b/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs index 4f64014c289b5..5a26917071b30 100644 --- a/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs +++ b/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs @@ -12,8 +12,7 @@ internal static partial class Libraries internal const string NetSecurityNative = "libSystem.Net.Security.Native"; internal const string CryptoNative = "libSystem.Security.Cryptography.Native.OpenSsl"; internal const string CompressionNative = "libSystem.IO.Compression.Native"; - // change this temporary - internal const string GlobalizationNative = "libSystem.HybridGlobalization.Native"; + internal const string GlobalizationNative = "libSystem.Globalization.Native"; internal const string HybridGlobalizationNative = "libSystem.HybridGlobalization.Native"; internal const string IOPortsNative = "libSystem.IO.Ports.Native"; internal const string HostPolicy = "libhostpolicy"; diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index e166a7c85a09d..8c18bfc4466ff 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -1357,6 +1357,9 @@ Common\Interop\Interop.Idna.cs + + Common\Interop\Interop.Idna.iOS.cs + Common\Interop\Interop.Locale.cs diff --git a/src/native/libs/System.Globalization.Native/pal_icushim_static.c b/src/native/libs/System.Globalization.Native/pal_icushim_static.c index ecef84ab79335..0283be2f5f1ae 100644 --- a/src/native/libs/System.Globalization.Native/pal_icushim_static.c +++ b/src/native/libs/System.Globalization.Native/pal_icushim_static.c @@ -10,10 +10,7 @@ #include #include #include - -#if !defined(APPLE_HYBRID_GLOBALIZATION) #include -#endif #if defined(TARGET_UNIX) #include @@ -21,7 +18,7 @@ #define strcasecmp _stricmp #define strncasecmp _strnicmp #endif -#if !defined(TARGET_MACCATALYST) && !defined(TARGET_IOS) && !defined(TARGET_TVOS) + static int32_t isLoaded = 0; static int32_t isDataSet = 0; @@ -250,5 +247,5 @@ int32_t GlobalizationNative_GetICUVersion(void) return (versionInfo[0] << 24) + (versionInfo[1] << 16) + (versionInfo[2] << 8) + versionInfo[3]; } -#endif + diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index e7b53b1790e55..5390509dd7287 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -35,6 +35,26 @@ return strdup([localeName UTF8String]); } +const char* GlobalizationNative_GetICUDataPathRelativeToAppBundleRoot(const char* path) +{ + @autoreleasepool + { + NSString *bundlePath = [[NSBundle mainBundle] bundlePath]; + NSString *dataPath = [bundlePath stringByAppendingPathComponent: [NSString stringWithFormat:@"%s", path]]; + + return strdup([dataPath UTF8String]); + } +} + +const char* GlobalizationNative_GetICUDataPathFallback(void) +{ + @autoreleasepool + { + NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"icudt" ofType:@"dat"]; + return strdup([dataPath UTF8String]); + } +} + From f5d2926304bb877ab27829199cd2d1b62705c695 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Tue, 23 Jan 2024 17:03:43 +0100 Subject: [PATCH 13/30] Change hybrid casing and idn functions --- .../System/Globalization/IdnMapping.Icu.cs | 22 ++++++++++++++++--- .../System/Globalization/OrdinalCasing.Icu.cs | 5 +++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.Icu.cs index bfaeb2c721e6f..70c0a4facdcd5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.Icu.cs @@ -24,7 +24,12 @@ private unsafe string IcuGetAsciiCore(string unicodeString, char* unicode, int c if (estimatedLength < StackallocThreshold) { char* outputStack = stackalloc char[estimatedLength]; - actualLength = Interop.Globalization.ToAscii(flags, unicode, count, outputStack, estimatedLength); +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS + if (GlobalizationMode.Hybrid) + actualLength = Interop.Globalization.ToAsciiNative(flags, unicode, count, outputStack, estimatedLength); + else +#endif + actualLength = Interop.Globalization.ToAscii(flags, unicode, count, outputStack, estimatedLength); if (actualLength > 0 && actualLength <= estimatedLength) { return GetStringForOutput(unicodeString, unicode, count, outputStack, actualLength); @@ -32,7 +37,12 @@ private unsafe string IcuGetAsciiCore(string unicodeString, char* unicode, int c } else { - actualLength = Interop.Globalization.ToAscii(flags, unicode, count, null, 0); +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS + if (GlobalizationMode.Hybrid) + actualLength = Interop.Globalization.ToAsciiNative(flags, unicode, count, null, 0); + else +#endif + actualLength = Interop.Globalization.ToAscii(flags, unicode, count, null, 0); } if (actualLength == 0) { @@ -82,7 +92,13 @@ private unsafe string IcuGetUnicodeCore(string asciiString, char* ascii, int cou Debug.Assert(!GlobalizationMode.UseNls); Debug.Assert(asciiString != null && asciiString.Length >= count); - int realLen = Interop.Globalization.ToUnicode(flags, ascii, count, output, outputLength); + int realLen; +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS + if (GlobalizationMode.Hybrid) + realLen = Interop.Globalization.ToUnicodeNative(flags, ascii, count, output, outputLength); + else +#endif + realLen = Interop.Globalization.ToUnicode(flags, ascii, count, output, outputLength); if (realLen == 0) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/OrdinalCasing.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/OrdinalCasing.Icu.cs index 1d520c348723d..66c5cd175f084 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/OrdinalCasing.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/OrdinalCasing.Icu.cs @@ -434,6 +434,11 @@ private static unsafe ushort[] InitOrdinalCasingPage(int pageNumber) fixed (ushort* table = casingTable) { char* pTable = (char*)table; +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS + if (GlobalizationMode.Hybrid) + Interop.Globalization.InitOrdinalCasingPageNative(pageNumber, pTable); + else +#endif Interop.Globalization.InitOrdinalCasingPage(pageNumber, pTable); } Volatile.Write(ref s_casingTable[pageNumber], casingTable); From a7cc352b64742c8016a04c27ffd824a6c21740c3 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Thu, 25 Jan 2024 14:37:34 +0100 Subject: [PATCH 14/30] temporary solution for library mode not include hybrid libs --- src/tasks/LibraryBuilder/LibraryBuilder.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/tasks/LibraryBuilder/LibraryBuilder.cs b/src/tasks/LibraryBuilder/LibraryBuilder.cs index d96b5c4d316e8..b84a01252b9af 100644 --- a/src/tasks/LibraryBuilder/LibraryBuilder.cs +++ b/src/tasks/LibraryBuilder/LibraryBuilder.cs @@ -200,13 +200,26 @@ private void GatherSourcesAndLibs(List sources, List libs, List< foreach (ITaskItem lib in RuntimeLibraries) { string ext = Path.GetExtension(lib.ItemSpec); + string libName = Path.GetFileNameWithoutExtension(lib.ItemSpec); if (ext == ".so" || ext == ".dylib") { + // temporary solution, exclude HybridGlobalization from static linking , + // until we figure out how to link it properly depending on the hybrid globalization mode + if(libName.Contains("HybridGlobalization")) + { + continue; + } libs.Add(lib.ItemSpec); } else { + // temporary solution, exclude HybridGlobalization from static linking , + // until we figure out how to link it properly depending on the hybrid globalization mode + if(libName.Contains("HybridGlobalization")) + { + continue; + } sources.Add(lib.ItemSpec); } } From 376dcb0393ed8269309d23369bc1735e1b9071ac Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Fri, 26 Jan 2024 10:47:55 +0100 Subject: [PATCH 15/30] Refactoring and running tests on hybrid mode --- eng/testing/tests.ioslike.targets | 2 +- src/mono/mono/mini/CMakeLists.txt | 72 ------------------- .../corehost/apphost/static/CMakeLists.txt | 3 - .../CMakeLists.txt | 19 +---- .../config.h.in | 2 +- .../configure.cmake | 1 + .../entrypoints.c | 2 +- .../pal_calendarData.h | 1 + .../pal_icushim_internal.h | 2 +- .../pal_icushim_static.c | 2 +- src/tasks/LibraryBuilder/LibraryBuilder.cs | 8 +-- .../iOS.Device.LibraryMode.Test.csproj | 1 + 12 files changed, 13 insertions(+), 102 deletions(-) diff --git a/eng/testing/tests.ioslike.targets b/eng/testing/tests.ioslike.targets index 73ce3e606a94f..d4dfbe3ebe1e4 100644 --- a/eng/testing/tests.ioslike.targets +++ b/eng/testing/tests.ioslike.targets @@ -159,7 +159,7 @@ - + true true true AppleTestRunner.dll diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index 3b9621f8408bc..335867bac8eff 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -45,78 +45,6 @@ if(HOST_WIN32) add_link_options(/OPT:NOICF) endif() -# # ICU -# if(HAVE_SYS_ICU) -# if(STATIC_ICU) -# set(pal_icushim_sources_base -# pal_icushim_static.c) -# add_definitions(-DSTATIC_ICU=1) -# else() -# set(pal_icushim_sources_base -# pal_icushim.c) -# endif() - -# set(icu_shim_sources_base -# pal_idna.c -# pal_common.c -# entrypoints.c -# ${pal_icushim_sources_base}) - -# if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) -# set(icu_shim_sources_base -# ${icu_shim_sources_base} -# pal_calendarData.c -# pal_casing.c -# pal_collation.c -# pal_locale.c -# pal_localeNumberData.c -# pal_localeStringData.c -# pal_normalization.c -# pal_timeZoneInfo.c -# ) -# endif() - -# if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) -# set(icu_shim_sources_base -# ${icu_shim_sources_base} -# pal_placeholders.c -# ) -# endif() - -# addprefix(icu_shim_sources "${ICU_SHIM_PATH}" "${icu_shim_sources_base}") - -# if (TARGET_DARWIN) -# set(icu_shim_darwin_sources_base -# pal_locale.m -# pal_collation.m -# pal_casing.m -# pal_calendarData.m -# pal_normalization.m -# pal_timeZoneInfo.m) - -# addprefix(icu_shim_darwin_sources "${ICU_SHIM_PATH}" "${icu_shim_darwin_sources_base}") -# set(icu_shim_sources ${icu_shim_sources} ${icu_shim_darwin_sources}) -# endif() - -# set_source_files_properties(${icu_shim_sources} PROPERTIES COMPILE_DEFINITIONS OSX_ICU_LIBRARY_PATH="${OSX_ICU_LIBRARY_PATH}") -# set_source_files_properties(${icu_shim_sources} PROPERTIES COMPILE_FLAGS "-I\"${ICU_INCLUDEDIR}\" -I\"${CLR_SRC_NATIVE_DIR}/libs/System.Globalization.Native/\" -I\"${CLR_SRC_NATIVE_DIR}/libs/Common/\" ${ICU_FLAGS}") -# if(TARGET_DARWIN) -# set_property(SOURCE ${icu_shim_darwin_sources} APPEND_STRING PROPERTY COMPILE_FLAGS " -fobjc-arc ${CLR_CMAKE_COMMON_OBJC_FLAGS}") -# endif() -# if(TARGET_WIN32) -# set_source_files_properties(${icu_shim_sources} PROPERTIES LANGUAGE CXX) -# endif() -# if(ICU_LIBDIR) -# set(ICU_LDFLAGS "-L${ICU_LIBDIR}") -# endif() -# if(CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) -# set(ICU_LDFLAGS "-licucore") -# endif() - -# add_library(icu_shim_objects OBJECT "${icu_shim_sources}") -# set(HAVE_ICU_SHIM 1) -# endif() - # # MINI # diff --git a/src/native/corehost/apphost/static/CMakeLists.txt b/src/native/corehost/apphost/static/CMakeLists.txt index f263d6ae1cd77..7a14c7c92ed66 100644 --- a/src/native/corehost/apphost/static/CMakeLists.txt +++ b/src/native/corehost/apphost/static/CMakeLists.txt @@ -138,9 +138,6 @@ else() if(CLR_CMAKE_HOST_OSX OR (CLR_CMAKE_HOST_LINUX AND NOT CLR_CMAKE_HOST_UNIX_X86 AND NOT CLR_CMAKE_HOST_ANDROID)) LIST(APPEND NATIVE_LIBS createdump_static) endif() - # if(CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) - # LIST(APPEND NATIVE_LIBS System.HybridGlobalization.Native-Static) - # endif() LIST(APPEND NATIVE_LIBS coreclr_static diff --git a/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt b/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt index 1f72e8d9e6ee8..04dca8058020d 100644 --- a/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt +++ b/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt @@ -61,18 +61,6 @@ set(NATIVEGLOBALIZATION_SOURCES pal_idna.c pal_common.c ) -# if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) -# set(NATIVEGLOBALIZATION_SOURCES -# ${NATIVEGLOBALIZATION_SOURCES} -# pal_calendarData.c -# pal_casing.c -# pal_collation.c -# pal_locale.c -# pal_localeNumberData.c -# pal_localeStringData.c -# pal_normalization.c -# ) -# endif() if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) add_definitions(-DAPPLE_HYBRID_GLOBALIZATION) @@ -126,11 +114,6 @@ if (CLR_CMAKE_TARGET_APPLE) set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} ${NATIVEGLOBALIZATION_SOURCES_OBJC}) endif() -# # time zone names are filtered out of icu data for the browser and associated functionality is disabled -# if (NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) -# set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_timeZoneInfo.c) -# endif() - if (MSVC) set_source_files_properties(${NATIVEGLOBALIZATION_SOURCES} PROPERTIES LANGUAGE CXX) endif() @@ -200,4 +183,4 @@ if(CLR_CMAKE_TARGET_WIN32) install_static_library(System.HybridGlobalization.Native.Aot aotsdk nativeaot) install_static_library(System.HybridGlobalization.Native.Aot.GuardCF aotsdk nativeaot) endif() -endif() \ No newline at end of file +endif() diff --git a/src/native/libs/System.HybridGlobalization.Native/config.h.in b/src/native/libs/System.HybridGlobalization.Native/config.h.in index 933a3d0c5c419..8f4e659b5aa5d 100644 --- a/src/native/libs/System.HybridGlobalization.Native/config.h.in +++ b/src/native/libs/System.HybridGlobalization.Native/config.h.in @@ -2,4 +2,4 @@ #cmakedefine01 HAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS #cmakedefine01 HAVE_SET_MAX_VARIABLE -#cmakedefine01 HAVE_UCOL_CLONE \ No newline at end of file +#cmakedefine01 HAVE_UCOL_CLONE diff --git a/src/native/libs/System.HybridGlobalization.Native/configure.cmake b/src/native/libs/System.HybridGlobalization.Native/configure.cmake index 8163745c4c20a..0042d275003c2 100644 --- a/src/native/libs/System.HybridGlobalization.Native/configure.cmake +++ b/src/native/libs/System.HybridGlobalization.Native/configure.cmake @@ -34,3 +34,4 @@ endif() configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) + diff --git a/src/native/libs/System.HybridGlobalization.Native/entrypoints.c b/src/native/libs/System.HybridGlobalization.Native/entrypoints.c index 9f1766747aa01..7985e511ceefe 100644 --- a/src/native/libs/System.HybridGlobalization.Native/entrypoints.c +++ b/src/native/libs/System.HybridGlobalization.Native/entrypoints.c @@ -89,4 +89,4 @@ EXTERN_C const void* HybridGlobalizationResolveDllImport(const char* name); EXTERN_C const void* HybridGlobalizationResolveDllImport(const char* name) { return minipal_resolve_dllimport(s_globalizationNative, ARRAY_SIZE(s_globalizationNative), name); -} \ No newline at end of file +} diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_calendarData.h b/src/native/libs/System.HybridGlobalization.Native/pal_calendarData.h index 31ce76d869395..8b1d83e9e9d4b 100644 --- a/src/native/libs/System.HybridGlobalization.Native/pal_calendarData.h +++ b/src/native/libs/System.HybridGlobalization.Native/pal_calendarData.h @@ -117,3 +117,4 @@ PALEXPORT int32_t GlobalizationNative_GetJapaneseEraStartDateNative(int32_t era, int32_t* startMonth, int32_t* startDay); #endif + diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_icushim_internal.h b/src/native/libs/System.HybridGlobalization.Native/pal_icushim_internal.h index bb19906effd92..a7bad69cef319 100644 --- a/src/native/libs/System.HybridGlobalization.Native/pal_icushim_internal.h +++ b/src/native/libs/System.HybridGlobalization.Native/pal_icushim_internal.h @@ -383,4 +383,4 @@ const char* GlobalizationNative_GetICUDataPathFallback(void); (buffer)[(offset)++] = (uint16_t)(((codePoint)&0x3ff) | 0xdc00); \ } \ } -#endif \ No newline at end of file +#endif diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_icushim_static.c b/src/native/libs/System.HybridGlobalization.Native/pal_icushim_static.c index 8b46bfffefbad..ad6013d42e026 100644 --- a/src/native/libs/System.HybridGlobalization.Native/pal_icushim_static.c +++ b/src/native/libs/System.HybridGlobalization.Native/pal_icushim_static.c @@ -250,4 +250,4 @@ int32_t GlobalizationNative_GetICUVersion(void) return (versionInfo[0] << 24) + (versionInfo[1] << 16) + (versionInfo[2] << 8) + versionInfo[3]; } -#endif \ No newline at end of file +#endif diff --git a/src/tasks/LibraryBuilder/LibraryBuilder.cs b/src/tasks/LibraryBuilder/LibraryBuilder.cs index b84a01252b9af..f68f65c29ff74 100644 --- a/src/tasks/LibraryBuilder/LibraryBuilder.cs +++ b/src/tasks/LibraryBuilder/LibraryBuilder.cs @@ -204,9 +204,9 @@ private void GatherSourcesAndLibs(List sources, List libs, List< if (ext == ".so" || ext == ".dylib") { - // temporary solution, exclude HybridGlobalization from static linking , + // temporary solution, include only HybridGlobalization from static linking , // until we figure out how to link it properly depending on the hybrid globalization mode - if(libName.Contains("HybridGlobalization")) + if (libName.Contains("libSystem.Globalization.Native")) { continue; } @@ -214,9 +214,9 @@ private void GatherSourcesAndLibs(List sources, List libs, List< } else { - // temporary solution, exclude HybridGlobalization from static linking , + // temporary solution, include only HybridGlobalization from static linking , // until we figure out how to link it properly depending on the hybrid globalization mode - if(libName.Contains("HybridGlobalization")) + if (libName.Contains("libSystem.Globalization.Native")) { continue; } diff --git a/src/tests/FunctionalTests/iOS/Device/LibraryMode/iOS.Device.LibraryMode.Test.csproj b/src/tests/FunctionalTests/iOS/Device/LibraryMode/iOS.Device.LibraryMode.Test.csproj index 7f33aa52c112d..62fbe6f9b2965 100644 --- a/src/tests/FunctionalTests/iOS/Device/LibraryMode/iOS.Device.LibraryMode.Test.csproj +++ b/src/tests/FunctionalTests/iOS/Device/LibraryMode/iOS.Device.LibraryMode.Test.csproj @@ -14,6 +14,7 @@ shared false true + true From 7534dc688af0e959392f571fbe4d3ed8d6a10b7c Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Mon, 29 Jan 2024 15:35:13 +0100 Subject: [PATCH 16/30] When hybrid mode don't include icu libs --- .../System/Globalization/IdnMapping.Icu.cs | 5 +++++ .../CMakeLists.txt | 6 +++--- src/tasks/AppleAppBuilder/Xcode.cs | 20 +++++++++++++++---- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.Icu.cs index 70c0a4facdcd5..c78c93510e85b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.Icu.cs @@ -52,6 +52,11 @@ private unsafe string IcuGetAsciiCore(string unicodeString, char* unicode, int c char[] outputHeap = new char[actualLength]; fixed (char* pOutputHeap = &outputHeap[0]) { +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS + if (GlobalizationMode.Hybrid) + actualLength = Interop.Globalization.ToAsciiNative(flags, unicode, count, pOutputHeap, actualLength); + else +#endif actualLength = Interop.Globalization.ToAscii(flags, unicode, count, pOutputHeap, actualLength); if (actualLength == 0 || actualLength > outputHeap.Length) { diff --git a/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt b/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt index 04dca8058020d..fb4e2420a1ec1 100644 --- a/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt +++ b/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt @@ -22,7 +22,7 @@ if(CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_WASI) add_compile_options(-Wno-unknown-warning-option) # The mobile configurations in particular bring their own ICU, so skip - if (NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT DEFINED CMAKE_ICU_DIR) + if (NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) if (CLR_CMAKE_TARGET_OSX) execute_process(COMMAND brew --prefix OUTPUT_VARIABLE brew_prefix OUTPUT_STRIP_TRAILING_WHITESPACE) set(ICU_HOMEBREW_INC_PATH "${brew_prefix}/opt/icu4c/include") @@ -70,13 +70,13 @@ if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVO ) endif() -if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND DEFINED CMAKE_ICU_DIR) +if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) include_directories(${CMAKE_ICU_DIR}/include) link_libraries(${CMAKE_ICU_DIR}/lib/libicuuc.a ${CMAKE_ICU_DIR}/lib/libicui18n.a ${CMAKE_ICU_DIR}/lib/libicudata.a) link_libraries(stdc++) endif() -if ((CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS)) +if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) link_libraries(icucore) endif() diff --git a/src/tasks/AppleAppBuilder/Xcode.cs b/src/tasks/AppleAppBuilder/Xcode.cs index 7fa6b66c5ed19..bbb4bf52b0357 100644 --- a/src/tasks/AppleAppBuilder/Xcode.cs +++ b/src/tasks/AppleAppBuilder/Xcode.cs @@ -405,7 +405,10 @@ public string GenerateCMake( continue; string libName = Path.GetFileNameWithoutExtension(lib); - if(libName.StartsWith("libSystem.Globalization", StringComparison.OrdinalIgnoreCase) && hybridGlobalization) + if((libName.StartsWith("libSystem.Globalization", StringComparison.OrdinalIgnoreCase) || + libName.StartsWith("libicudata", StringComparison.OrdinalIgnoreCase) || + libName.StartsWith("libicui18n", StringComparison.OrdinalIgnoreCase) || + libName.StartsWith("libicuuc", StringComparison.OrdinalIgnoreCase)) && hybridGlobalization) continue; else if (libName.StartsWith("libSystem.HybridGlobalization", StringComparison.OrdinalIgnoreCase) && !hybridGlobalization) continue; @@ -536,7 +539,10 @@ public string GenerateCMake( foreach (string aFile in Directory.GetFiles(workspace, "*.a")) { string aFileName = Path.GetFileNameWithoutExtension(aFile); - if(aFileName.StartsWith("libSystem.Globalization", StringComparison.OrdinalIgnoreCase) && hybridGlobalization) + if((libName.StartsWith("libSystem.Globalization", StringComparison.OrdinalIgnoreCase) || + libName.StartsWith("libicudata", StringComparison.OrdinalIgnoreCase) || + libName.StartsWith("libicui18n", StringComparison.OrdinalIgnoreCase) || + libName.StartsWith("libicuuc", StringComparison.OrdinalIgnoreCase)) && hybridGlobalization) continue; else if (aFileName.StartsWith("libSystem.HybridGlobalization", StringComparison.OrdinalIgnoreCase) && !hybridGlobalization) continue; @@ -546,8 +552,14 @@ public string GenerateCMake( aFileName = aFileName.StartsWith("lib") ? aFileName.Remove(0, 3) : "lib" + aFileName; pinvokeOverrides.AppendLine($" \"{aFileName}\","); } - - pinvokeOverrides.AppendLine($" \"System.Globalization.Native\","); + if (hybridGlobalization) + { + pinvokeOverrides.AppendLine($" \"System.HybridGlobalization.Native\","); + } + else + { + pinvokeOverrides.AppendLine($" \"System.Globalization.Native\","); + } File.WriteAllText(Path.Combine(binDir, "runtime.m"), Utils.GetEmbeddedResource("runtime.m") From 0ede71f16e0f7595a6a46384df5b470019b89c7e Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Mon, 29 Jan 2024 15:46:19 +0100 Subject: [PATCH 17/30] Fix syntax error --- src/tasks/AppleAppBuilder/Xcode.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tasks/AppleAppBuilder/Xcode.cs b/src/tasks/AppleAppBuilder/Xcode.cs index bbb4bf52b0357..b124ab046d7b7 100644 --- a/src/tasks/AppleAppBuilder/Xcode.cs +++ b/src/tasks/AppleAppBuilder/Xcode.cs @@ -539,10 +539,10 @@ public string GenerateCMake( foreach (string aFile in Directory.GetFiles(workspace, "*.a")) { string aFileName = Path.GetFileNameWithoutExtension(aFile); - if((libName.StartsWith("libSystem.Globalization", StringComparison.OrdinalIgnoreCase) || - libName.StartsWith("libicudata", StringComparison.OrdinalIgnoreCase) || - libName.StartsWith("libicui18n", StringComparison.OrdinalIgnoreCase) || - libName.StartsWith("libicuuc", StringComparison.OrdinalIgnoreCase)) && hybridGlobalization) + if((aFileName.StartsWith("libSystem.Globalization", StringComparison.OrdinalIgnoreCase) || + aFileName.StartsWith("libicudata", StringComparison.OrdinalIgnoreCase) || + aFileName.StartsWith("libicui18n", StringComparison.OrdinalIgnoreCase) || + aFileName.StartsWith("libicuuc", StringComparison.OrdinalIgnoreCase)) && hybridGlobalization) continue; else if (aFileName.StartsWith("libSystem.HybridGlobalization", StringComparison.OrdinalIgnoreCase) && !hybridGlobalization) continue; From 6e3dc61e4130284a362734a5eb8f99afb274b400 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Mon, 29 Jan 2024 17:21:25 +0100 Subject: [PATCH 18/30] Fix OSX build failure --- .../CMakeLists.txt | 109 +++++++++--------- 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt b/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt index fb4e2420a1ec1..6e120902d9d82 100644 --- a/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt +++ b/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt @@ -2,11 +2,11 @@ cmake_minimum_required(VERSION 3.10..3.20) project(System.HybridGlobalization.Native C) - +if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) if(CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_WASI) - if (ANDROID_FORCE_ICU_DATA_DIR) - add_definitions(-DANDROID_FORCE_ICU_DATA_DIR) - endif() + # if (ANDROID_FORCE_ICU_DATA_DIR) + # add_definitions(-DANDROID_FORCE_ICU_DATA_DIR) + # endif() add_compile_options(-Wno-switch-enum) add_compile_options(-Wno-covered-switch-default) @@ -21,38 +21,38 @@ if(CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_WASI) add_compile_options(-Wno-extra-semi-stmt) add_compile_options(-Wno-unknown-warning-option) - # The mobile configurations in particular bring their own ICU, so skip - if (NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) - if (CLR_CMAKE_TARGET_OSX) - execute_process(COMMAND brew --prefix OUTPUT_VARIABLE brew_prefix OUTPUT_STRIP_TRAILING_WHITESPACE) - set(ICU_HOMEBREW_INC_PATH "${brew_prefix}/opt/icu4c/include") - endif() - - find_path(UCURR_H "unicode/ucurr.h" PATHS ${ICU_HOMEBREW_INC_PATH}) - if(UCURR_H STREQUAL UCURR_H-NOTFOUND) - message(FATAL_ERROR "Cannot find ucurr.h, try installing libicu-dev (or the appropriate package for your platform)") - return() - endif() - - if(CLR_CMAKE_TARGET_OSX) - add_definitions(-DOSX_ICU_LIBRARY_PATH="/usr/lib/libicucore.dylib") - add_definitions(-DU_DISABLE_RENAMING) - else() - find_library(ICUUC icuuc) - if(ICUUC STREQUAL ICUUC-NOTFOUND) - message(FATAL_ERROR "Cannot find libicuuc, try installing libicu-dev (or the appropriate package for your platform)") - return() - endif() - - find_library(ICUI18N icui18n) - if(ICUI18N STREQUAL ICUI18N-NOTFOUND) - message(FATAL_ERROR "Cannot find libicui18n, try installing libicu-dev (or the appropriate package for your platform)") - return() - endif() - endif() - - include_directories(${UCURR_H}) - endif() + # # The mobile configurations in particular bring their own ICU, so skip + # if (NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) + # if (CLR_CMAKE_TARGET_OSX) + # execute_process(COMMAND brew --prefix OUTPUT_VARIABLE brew_prefix OUTPUT_STRIP_TRAILING_WHITESPACE) + # set(ICU_HOMEBREW_INC_PATH "${brew_prefix}/opt/icu4c/include") + # endif() + + # find_path(UCURR_H "unicode/ucurr.h" PATHS ${ICU_HOMEBREW_INC_PATH}) + # if(UCURR_H STREQUAL UCURR_H-NOTFOUND) + # message(FATAL_ERROR "Cannot find ucurr.h, try installing libicu-dev (or the appropriate package for your platform)") + # return() + # endif() + + # if(CLR_CMAKE_TARGET_OSX) + # add_definitions(-DOSX_ICU_LIBRARY_PATH="/usr/lib/libicucore.dylib") + # add_definitions(-DU_DISABLE_RENAMING) + # else() + # find_library(ICUUC icuuc) + # if(ICUUC STREQUAL ICUUC-NOTFOUND) + # message(FATAL_ERROR "Cannot find libicuuc, try installing libicu-dev (or the appropriate package for your platform)") + # return() + # endif() + + # find_library(ICUI18N icui18n) + # if(ICUI18N STREQUAL ICUI18N-NOTFOUND) + # message(FATAL_ERROR "Cannot find libicui18n, try installing libicu-dev (or the appropriate package for your platform)") + # return() + # endif() + # endif() + + # include_directories(${UCURR_H}) + # endif() endif() include(configure.cmake) @@ -70,11 +70,11 @@ if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVO ) endif() -if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) - include_directories(${CMAKE_ICU_DIR}/include) - link_libraries(${CMAKE_ICU_DIR}/lib/libicuuc.a ${CMAKE_ICU_DIR}/lib/libicui18n.a ${CMAKE_ICU_DIR}/lib/libicudata.a) - link_libraries(stdc++) -endif() +# if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) +# include_directories(${CMAKE_ICU_DIR}/include) +# link_libraries(${CMAKE_ICU_DIR}/lib/libicuuc.a ${CMAKE_ICU_DIR}/lib/libicui18n.a ${CMAKE_ICU_DIR}/lib/libicudata.a) +# link_libraries(stdc++) +# endif() if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) link_libraries(icucore) @@ -95,7 +95,7 @@ if (LOCAL_BUILD) # For minipal files include_directories(../../) include_directories(${CMAKE_CURRENT_BINARY_DIR}) -elseif (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) +elseif (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) add_definitions(-DSTATIC_ICU) set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_icushim_static.c) else() @@ -147,23 +147,23 @@ add_library(System.HybridGlobalization.Native-Static entrypoints.c ) -if(CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_WASI) +if(CLR_CMAKE_TARGET_UNIX) set_target_properties(System.HybridGlobalization.Native-Static PROPERTIES OUTPUT_NAME System.HybridGlobalization.Native CLEAN_DIRECT_OUTPUT 1) endif() install (TARGETS System.HybridGlobalization.Native-Static DESTINATION ${STATIC_LIB_DESTINATION} COMPONENT libs) -if(NOT CLR_CMAKE_TARGET_APPLE AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_LINUX_MUSL AND NOT CLR_CMAKE_TARGET_HAIKU) - if (GEN_SHARED_LIB) - add_custom_command(TARGET System.HybridGlobalization.Native POST_BUILD - COMMENT "Verifying System.HybridGlobalization.Native.so dependencies" - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../verify-so.sh - $ - "Verification failed. System.HybridGlobalization.Native.so has undefined dependencies. These are likely ICU APIs that need to be added to icushim.h." - VERBATIM - ) - endif() -endif() +# if(NOT CLR_CMAKE_TARGET_APPLE AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_LINUX_MUSL AND NOT CLR_CMAKE_TARGET_HAIKU) +# if (GEN_SHARED_LIB) +# add_custom_command(TARGET System.HybridGlobalization.Native POST_BUILD +# COMMENT "Verifying System.HybridGlobalization.Native.so dependencies" +# COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../verify-so.sh +# $ +# "Verification failed. System.HybridGlobalization.Native.so has undefined dependencies. These are likely ICU APIs that need to be added to icushim.h." +# VERBATIM +# ) +# endif() +# endif() if(CLR_CMAKE_TARGET_WIN32) if(STATIC_LIBS_ONLY) @@ -184,3 +184,4 @@ if(CLR_CMAKE_TARGET_WIN32) install_static_library(System.HybridGlobalization.Native.Aot.GuardCF aotsdk nativeaot) endif() endif() +endif() From 23d91d97bb4a71fa3eadab740f912087f9fad946 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Tue, 30 Jan 2024 09:45:15 +0100 Subject: [PATCH 19/30] Remove unused code --- src/mono/CMakeLists.txt | 73 ----------------------------------------- 1 file changed, 73 deletions(-) diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index d5374b3bca6a8..7798a1a40836e 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -712,79 +712,6 @@ if(LLVM_PREFIX) add_definitions(-DLLVM_API_VERSION=${llvm_api_version}) endif() -###################################### -# ICU CHECKS -###################################### -if(HOST_OSX OR HOST_MACCAT OR HOST_IOS OR HOST_TVOS) - # FIXME: Handle errors - execute_process(COMMAND brew --prefix OUTPUT_VARIABLE brew_prefix OUTPUT_STRIP_TRAILING_WHITESPACE) - - if((HOST_MACCAT OR HOST_IOS OR HOST_TVOS) AND "${CMAKE_SHARED_LINKER_FLAGS}" MATCHES "${brew_prefix}/opt/icu4c/lib") - message(FATAL_ERROR "Linker flags contain the Homebrew version of ICU which conflicts with the iOS/tvOS/MacCatalyst version: ${CMAKE_SHARED_LINKER_FLAGS}") - endif() -endif() - -set(ICU_SHIM_PATH "${CLR_SRC_NATIVE_DIR}/libs/System.Globalization.Native") -if(MONO_CROSS_COMPILE) -elseif(HOST_OSX AND NOT HOST_MACCAT) - include(FindPkgConfig) - set(ENV{PKG_CONFIG_PATH} "{$PKG_CONFIG_PATH}:${brew_prefix}/lib/pkgconfig:${brew_prefix}/opt/icu4c/lib/pkgconfig") - # Defines ICU_INCLUDEDIR/ICU_LIBDIR - pkg_check_modules(ICU icu-uc) - set(OSX_ICU_LIBRARY_PATH /usr/lib/libicucore.dylib) - set(ICU_FLAGS "-DTARGET_UNIX -DU_DISABLE_RENAMING -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option -Wno-deprecated-declarations") - set(HAVE_SYS_ICU 1) -elseif(HOST_WASI) - set(ICU_FLAGS "-DPALEXPORT=\"\" -DU_DISABLE_RENAMING -DHAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS -DHAVE_SET_MAX_VARIABLE -DTARGET_UNIX -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option") - set(HAVE_SYS_ICU 1) - set(STATIC_ICU 1) - set(ICU_LIBS "icucore") -elseif(HOST_BROWSER) - set(ICU_FLAGS "-DPALEXPORT=\"\" -DU_DISABLE_RENAMING -DHAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS -DHAVE_SET_MAX_VARIABLE -DTARGET_UNIX -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option") - set(HAVE_SYS_ICU 1) - set(STATIC_ICU 1) - set(ICU_LIBS "icucore") -elseif(HOST_IOS OR HOST_TVOS OR HOST_MACCAT) - set(ICU_FLAGS "-DTARGET_UNIX -DU_DISABLE_RENAMING -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option -Wno-deprecated-declarations") - if(HOST_IOS) - string(APPEND ICU_FLAGS " -DTARGET_IOS") - elseif(HOST_TVOS) - string(APPEND ICU_FLAGS " -DTARGET_TVOS") - elseif(HOST_MACCAT) - string(APPEND ICU_FLAGS " -DTARGET_MACCATALYST") - endif() - string(APPEND ICU_FLAGS " -DAPPLE_HYBRID_GLOBALIZATION") - set(HAVE_SYS_ICU 1) - set(STATIC_ICU 1) -elseif(HOST_ANDROID) - set(ICU_FLAGS "-DPALEXPORT=\"\" -DHAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS -DHAVE_SET_MAX_VARIABLE -DTARGET_UNIX -DTARGET_ANDROID -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option") - set(HAVE_SYS_ICU 1) -elseif(HOST_LINUX) - include(FindPkgConfig) - if(CROSS_ROOTFS) - set(ENV{PKG_CONFIG_SYSROOT_DIR} "${CROSS_ROOTFS}") - endif(CROSS_ROOTFS) - pkg_check_modules(ICU icu-uc) - set(ICU_FLAGS "-DTARGET_UNIX -DU_DISABLE_RENAMING -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option -Wno-deprecated-declarations") - set(HAVE_SYS_ICU 1) -elseif(HOST_WIN32) - set(ICU_FLAGS "-DTARGET_WINDOWS -DPALEXPORT=EXTERN_C") - set(HAVE_SYS_ICU 1) -elseif(HOST_SOLARIS) - set(ICU_FLAGS "-DPALEXPORT=\"\" -DTARGET_UNIX -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option") - set(HAVE_SYS_ICU 1) -elseif(TARGET_FREEBSD) - set(ICU_FLAGS "-DTARGET_UNIX -Wno-deprecated-declarations") - set(HAVE_SYS_ICU 1) - set(ICU_INCLUDEDIR "${CROSS_ROOTFS}/usr/local/include") - set(ICU_LIBDIR "${CROSS_ROOTFS}/usr/local/lib") -elseif(HOST_HAIKU) - set(ICU_FLAGS "-DTARGET_UNIX -DU_DISABLE_RENAMING -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option -Wno-deprecated-declarations") - set(HAVE_SYS_ICU 1) -else() - message(FATAL_ERROR "Unknown host") -endif() - ###################################### # GC CHECKS ###################################### From 226399831ba2bf15a114b760a1327bcd344943a8 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Tue, 30 Jan 2024 13:08:43 +0100 Subject: [PATCH 20/30] Remove PKG_CONFIG_PATH info --- src/mono/mono.proj | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 022da2f21f010..bbb6a3ef797e2 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -299,9 +299,6 @@ <_MonoBuildEnv Condition="'$(Platform)' == 'arm64'" Include="TARGET_BUILD_ARCH=arm64" /> <_MonoBuildEnv Condition="'$(Platform)' == 'arm'" Include="TARGET_BUILD_ARCH=arm" /> <_MonoBuildEnv Condition="'$(Platform)' == 'armv6'" Include="TARGET_BUILD_ARCH=armv6" /> - <_MonoBuildEnv Condition="'$(Platform)' == 'arm64'" Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/aarch64-linux-gnu/pkgconfig" /> - <_MonoBuildEnv Condition="'$(Platform)' == 'arm'" Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/arm-linux-gnueabihf/pkgconfig" /> - <_MonoBuildEnv Condition="'$(Platform)' == 'armv6'" Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/arm-linux-gnueabihf/pkgconfig" /> <_MonoCFLAGS Condition="'$(TargetArchitecture)' == 'armv6'" Include="-march=armv6zk" /> <_MonoCFLAGS Condition="'$(TargetArchitecture)' == 'armv6'" Include="-mcpu=arm1176jzf-s" /> <_MonoCFLAGS Condition="'$(TargetArchitecture)' == 'armv6'" Include="-mfpu=vfp" /> @@ -316,49 +313,42 @@ <_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(CrossToolchainFile)" /> <_MonoBuildEnv Include="TARGET_BUILD_ARCH=x64" /> - <_MonoBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/lib/pkgconfig" /> <_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(CrossToolchainFile)" /> <_MonoBuildEnv Include="TARGET_BUILD_ARCH=x64" /> - <_MonoBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/boot/system/lib/pkgconfig" /> <_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(CrossToolchainFile)" /> <_MonoBuildEnv Include="TARGET_BUILD_ARCH=x64" /> - <_MonoBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/pkgconfig" /> <_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(CrossToolchainFile)" /> <_MonoBuildEnv Include="TARGET_BUILD_ARCH=x86" /> - <_MonoBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/pkgconfig" /> <_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(CrossToolchainFile)" /> <_MonoBuildEnv Include="TARGET_BUILD_ARCH=riscv64" /> - <_MonoBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/riscv64-linux-gnu/pkgconfig" /> <_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(CrossToolchainFile)" /> <_MonoBuildEnv Include="TARGET_BUILD_ARCH=s390x" /> - <_MonoBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/s390x-linux-gnu/pkgconfig" /> <_MonoCMakeArgs Include="-DCMAKE_TOOLCHAIN_FILE=$(CrossToolchainFile)" /> <_MonoBuildEnv Include="TARGET_BUILD_ARCH=ppc64le" /> - <_MonoBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/powerpc64le-linux-gnu/pkgconfig" /> @@ -836,21 +826,6 @@ <_MonoAotBuildEnv Include="TARGET_BUILD_ARCH=$(AotHostArchitecture)" /> - - - <_MonoAotBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/x86_64-linux-gnu/pkgconfig" /> - - - - - <_MonoAotBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/aarch64-linux-gnu/pkgconfig" /> - - - - - <_MonoAotBuildEnv Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/pkgconfig" /> - - <_MonoAOTCFLAGSOption>-DCMAKE_C_FLAGS="@(_MonoAOTCPPFLAGS, ' ') @(_MonoAOTCFLAGS, ' ')" <_MonoAOTCXXFLAGSOption>-DCMAKE_CXX_FLAGS="@(_MonoAOTCPPFLAGS, ' ') @(_MonoAOTCXXFLAGS, ' ')" From fc5d2c550063771abf89a56607e16daa462355a3 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Wed, 31 Jan 2024 09:08:08 +0100 Subject: [PATCH 21/30] Move libe code under System.Globalization.Native --- src/native/libs/CMakeLists.txt | 4 - .../CMakeLists.txt | 136 +++++ .../System.Globalization.Native/entrypoints.c | 7 +- .../entrypoints_hg.c} | 14 +- .../pal_calendarData.h | 84 +-- .../pal_calendarData.m | 3 +- .../pal_calendarData_hg.h} | 71 +-- .../System.Globalization.Native/pal_casing.h | 17 +- .../pal_casing.m | 5 +- .../pal_casing_hg.h} | 6 +- .../pal_collation.c | 1 + .../pal_collation.h | 50 +- .../pal_collation.m | 2 +- .../pal_collation_hg.h} | 8 +- .../System.Globalization.Native/pal_common.h | 185 ++++++ .../pal_hybrid.h} | 61 +- .../pal_icushim_internal.h | 2 +- .../pal_icushim_static.c | 5 +- .../System.Globalization.Native/pal_locale.h | 385 ------------ .../System.Globalization.Native/pal_locale.m | 14 +- .../pal_localeNumberData.h | 36 -- .../pal_localeStringData.h | 40 -- .../pal_locale_hg.h | 55 ++ .../pal_locale_hg.m} | 46 +- .../pal_locale_internal.h | 1 + .../pal_normalization.c | 1 + .../pal_normalization.h | 20 - .../pal_normalization.m | 6 +- .../pal_normalization_hg.h} | 12 +- .../pal_placeholders.c | 16 +- .../pal_timeZoneInfo.h | 16 - .../pal_timeZoneInfo.m | 5 +- .../pal_timeZoneInfo_hg.h} | 15 +- .../CMakeLists.txt | 187 ------ .../config.h.in | 5 - .../configure.cmake | 37 -- .../pal_common.c | 21 - .../pal_errors.h | 17 - .../pal_errors_internal.h | 30 - .../pal_icushim.c | 575 ------------------ .../pal_icushim.h | 16 - .../pal_icushim_internal.h | 386 ------------ .../pal_icushim_internal_android.h | 542 ----------------- .../pal_icushim_static.c | 253 -------- .../pal_idna.c | 99 --- .../pal_idna.h | 20 - .../pal_localeNumberData.h | 54 -- .../pal_localeStringData.h | 54 -- .../pal_locale_internal.h | 63 -- 49 files changed, 464 insertions(+), 3224 deletions(-) rename src/native/libs/{System.HybridGlobalization.Native/entrypoints.c => System.Globalization.Native/entrypoints_hg.c} (94%) rename src/native/libs/{System.HybridGlobalization.Native => System.Globalization.Native}/pal_calendarData.m (99%) rename src/native/libs/{System.HybridGlobalization.Native/pal_calendarData.h => System.Globalization.Native/pal_calendarData_hg.h} (52%) rename src/native/libs/{System.HybridGlobalization.Native => System.Globalization.Native}/pal_casing.m (98%) rename src/native/libs/{System.HybridGlobalization.Native/pal_casing.h => System.Globalization.Native/pal_casing_hg.h} (98%) rename src/native/libs/{System.HybridGlobalization.Native => System.Globalization.Native}/pal_collation.m (99%) rename src/native/libs/{System.HybridGlobalization.Native/pal_collation.h => System.Globalization.Native/pal_collation_hg.h} (97%) create mode 100644 src/native/libs/System.Globalization.Native/pal_common.h rename src/native/libs/{System.HybridGlobalization.Native/pal_locale.h => System.Globalization.Native/pal_hybrid.h} (93%) create mode 100644 src/native/libs/System.Globalization.Native/pal_locale_hg.h rename src/native/libs/{System.HybridGlobalization.Native/pal_locale.m => System.Globalization.Native/pal_locale_hg.m} (96%) rename src/native/libs/{System.HybridGlobalization.Native => System.Globalization.Native}/pal_normalization.m (97%) rename src/native/libs/{System.HybridGlobalization.Native/pal_normalization.h => System.Globalization.Native/pal_normalization_hg.h} (87%) rename src/native/libs/{System.HybridGlobalization.Native => System.Globalization.Native}/pal_placeholders.c (96%) rename src/native/libs/{System.HybridGlobalization.Native => System.Globalization.Native}/pal_timeZoneInfo.m (97%) rename src/native/libs/{System.HybridGlobalization.Native/pal_timeZoneInfo.h => System.Globalization.Native/pal_timeZoneInfo_hg.h} (69%) delete mode 100644 src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt delete mode 100644 src/native/libs/System.HybridGlobalization.Native/config.h.in delete mode 100644 src/native/libs/System.HybridGlobalization.Native/configure.cmake delete mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_common.c delete mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_errors.h delete mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_errors_internal.h delete mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_icushim.c delete mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_icushim.h delete mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_icushim_internal.h delete mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_icushim_internal_android.h delete mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_icushim_static.c delete mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_idna.c delete mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_idna.h delete mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_localeNumberData.h delete mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_localeStringData.h delete mode 100644 src/native/libs/System.HybridGlobalization.Native/pal_locale_internal.h diff --git a/src/native/libs/CMakeLists.txt b/src/native/libs/CMakeLists.txt index 893b2d89ef3b1..79b92e33da29e 100644 --- a/src/native/libs/CMakeLists.txt +++ b/src/native/libs/CMakeLists.txt @@ -101,9 +101,6 @@ else () # we only need to build System.Globalization.Native when building static libs. if (STATIC_LIBS_ONLY) add_subdirectory(System.Globalization.Native) - if (CLR_CMAKE_TARGET_APPLE) - add_subdirectory(System.HybridGlobalization.Native) - endif () endif () endif () @@ -160,6 +157,5 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) if (CLR_CMAKE_TARGET_APPLE) add_subdirectory(System.Security.Cryptography.Native.Apple) - add_subdirectory(System.HybridGlobalization.Native) endif () endif () diff --git a/src/native/libs/System.Globalization.Native/CMakeLists.txt b/src/native/libs/System.Globalization.Native/CMakeLists.txt index daaeb9d333549..4f54b04306e93 100644 --- a/src/native/libs/System.Globalization.Native/CMakeLists.txt +++ b/src/native/libs/System.Globalization.Native/CMakeLists.txt @@ -179,3 +179,139 @@ if(CLR_CMAKE_TARGET_WIN32) install_static_library(System.Globalization.Native.Aot.GuardCF aotsdk nativeaot) endif() endif() + +# System.HybridGlobalization.Native library + +project(System.HybridGlobalization.Native C) +if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) + + add_compile_options(-Wno-switch-enum) + add_compile_options(-Wno-covered-switch-default) + + # Workaround for warnings produced by ICU headers + add_compile_options(-Wno-reserved-id-macro) + add_compile_options(-Wno-documentation) + add_compile_options(-Wno-documentation-unknown-command) + add_compile_options(-Wno-reserved-identifier) + + # Workaround for https://unicode-org.atlassian.net/browse/ICU-20601 + add_compile_options(-Wno-extra-semi-stmt) + add_compile_options(-Wno-unknown-warning-option) + + include(configure.cmake) + + set(NATIVEGLOBALIZATION_SOURCES + pal_idna.c + pal_common.c + ) + + if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) + add_definitions(-DAPPLE_HYBRID_GLOBALIZATION) + set(NATIVEGLOBALIZATION_SOURCES + ${NATIVEGLOBALIZATION_SOURCES} + pal_placeholders.c + ) + endif() + + if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) + link_libraries(icucore) + endif() + + if (CMAKE_USE_PTHREADS) + add_compile_options(-pthread) + add_linker_flag(-pthread) + endif() + + if (LOCAL_BUILD) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + # set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_icushim_static_hybrid.c) + set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES}) + add_definitions(-DLOCAL_BUILD) + add_definitions(-DSTATIC_ICU) + add_definitions(-DPALEXPORT=EXTERN_C) + add_definitions(-DTARGET_UNIX) + # For minipal files + include_directories(../../) + include_directories(${CMAKE_CURRENT_BINARY_DIR}) + elseif (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) + add_definitions(-DSTATIC_ICU) + # set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_icushim_static_hybrid.c) + set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES}) + + else() + # set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_icushim.c) + set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES}) + endif() + + if (CLR_CMAKE_TARGET_APPLE) + set(NATIVEGLOBALIZATION_SOURCES_OBJC + pal_locale_hg.m + pal_locale.m + pal_collation.m + pal_casing.m + pal_calendarData.m + pal_normalization.m + pal_timeZoneInfo.m) + set_source_files_properties(${NATIVEGLOBALIZATION_SOURCES_OBJC} PROPERTIES COMPILE_FLAGS "-fobjc-arc ${CLR_CMAKE_COMMON_OBJC_FLAGS}") + set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} ${NATIVEGLOBALIZATION_SOURCES_OBJC}) + endif() + + if (MSVC) + set_source_files_properties(${NATIVEGLOBALIZATION_SOURCES} PROPERTIES LANGUAGE CXX) + endif() + + include_directories("../Common") + + if (GEN_SHARED_LIB) + if (CLR_CMAKE_TARGET_APPLE) + include(CMakeFindFrameworks) + find_library(FOUNDATION Foundation REQUIRED) + endif() + + add_library(System.HybridGlobalization.Native + SHARED + ${NATIVEGLOBALIZATION_SOURCES} + ${VERSION_FILE_PATH} + ) + + target_link_libraries(System.HybridGlobalization.Native + PRIVATE + ${CMAKE_DL_LIBS} + ${FOUNDATION} + ) + + install_with_stripped_symbols (System.HybridGlobalization.Native PROGRAMS .) + endif() + + add_library(System.HybridGlobalization.Native-Static + STATIC + ${NATIVEGLOBALIZATION_SOURCES} + entrypoints_hg.c + ) + + if(CLR_CMAKE_TARGET_UNIX) + set_target_properties(System.HybridGlobalization.Native-Static PROPERTIES OUTPUT_NAME System.HybridGlobalization.Native CLEAN_DIRECT_OUTPUT 1) + endif() + + install (TARGETS System.HybridGlobalization.Native-Static DESTINATION ${STATIC_LIB_DESTINATION} COMPONENT libs) + + if(CLR_CMAKE_TARGET_WIN32) + if(STATIC_LIBS_ONLY) + add_library(System.HybridGlobalization.Native.Aot + STATIC + ${NATIVEGLOBALIZATION_SOURCES} + ) + set_target_properties(System.HybridGlobalization.Native.Aot PROPERTIES CLR_CONTROL_FLOW_GUARD OFF) + set_target_properties(System.HybridGlobalization.Native.Aot PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) + + add_library(System.HybridGlobalization.Native.Aot.GuardCF + STATIC + ${NATIVEGLOBALIZATION_SOURCES} + ) + set_target_properties(System.HybridGlobalization.Native.Aot.GuardCF PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) + + install_static_library(System.HybridGlobalization.Native.Aot aotsdk nativeaot) + install_static_library(System.HybridGlobalization.Native.Aot.GuardCF aotsdk nativeaot) + endif() + endif() +endif() diff --git a/src/native/libs/System.Globalization.Native/entrypoints.c b/src/native/libs/System.Globalization.Native/entrypoints.c index e6009cfafbb74..f55eb17fcddbd 100644 --- a/src/native/libs/System.Globalization.Native/entrypoints.c +++ b/src/native/libs/System.Globalization.Native/entrypoints.c @@ -55,10 +55,9 @@ static const Entry s_globalizationNative[] = DllImportEntry(GlobalizationNative_NormalizeString) DllImportEntry(GlobalizationNative_StartsWith) DllImportEntry(GlobalizationNative_WindowsIdToIanaId) - - DllImportEntry(GlobalizationNative_ToAscii) - DllImportEntry(GlobalizationNative_ToUnicode) - DllImportEntry(GlobalizationNative_InitOrdinalCasingPage) + DllImportEntry(GlobalizationNative_ToAscii) + DllImportEntry(GlobalizationNative_ToUnicode) + DllImportEntry(GlobalizationNative_InitOrdinalCasingPage) }; EXTERN_C const void* GlobalizationResolveDllImport(const char* name); diff --git a/src/native/libs/System.HybridGlobalization.Native/entrypoints.c b/src/native/libs/System.Globalization.Native/entrypoints_hg.c similarity index 94% rename from src/native/libs/System.HybridGlobalization.Native/entrypoints.c rename to src/native/libs/System.Globalization.Native/entrypoints_hg.c index 7985e511ceefe..c46fdcbda436d 100644 --- a/src/native/libs/System.HybridGlobalization.Native/entrypoints.c +++ b/src/native/libs/System.Globalization.Native/entrypoints_hg.c @@ -6,16 +6,14 @@ typedef uint16_t UChar; // Include System.HybridGlobalization.Native headers -#include "pal_calendarData.h" -#include "pal_casing.h" -#include "pal_collation.h" -#include "pal_locale.h" -#include "pal_localeNumberData.h" -#include "pal_localeStringData.h" +#include "pal_calendarData_hg.h" +#include "pal_casing_hg.h" +#include "pal_collation_hg.h" +#include "pal_locale_hg.h" #include "pal_icushim.h" #include "pal_idna.h" -#include "pal_normalization.h" -#include "pal_timeZoneInfo.h" +#include "pal_normalization_hg.h" +#include "pal_timeZoneInfo_hg.h" static const Entry s_globalizationNative[] = { diff --git a/src/native/libs/System.Globalization.Native/pal_calendarData.h b/src/native/libs/System.Globalization.Native/pal_calendarData.h index 31ce76d869395..bafe3f8d0eb10 100644 --- a/src/native/libs/System.Globalization.Native/pal_calendarData.h +++ b/src/native/libs/System.Globalization.Native/pal_calendarData.h @@ -5,77 +5,11 @@ #include +#include "pal_common.h" #include "pal_locale.h" #include "pal_compiler.h" #include "pal_errors.h" -/* -* These values should be kept in sync with System.Globalization.CalendarId -*/ -enum -{ - UNINITIALIZED_VALUE = 0, - GREGORIAN = 1, // Gregorian (localized) calendar - GREGORIAN_US = 2, // Gregorian (U.S.) calendar - JAPAN = 3, // Japanese Emperor Era calendar - /* SSS_WARNINGS_OFF */ - TAIWAN = 4, // Taiwan Era calendar /* SSS_WARNINGS_ON */ - KOREA = 5, // Korean Tangun Era calendar - HIJRI = 6, // Hijri (Arabic Lunar) calendar - THAI = 7, // Thai calendar - HEBREW = 8, // Hebrew (Lunar) calendar - GREGORIAN_ME_FRENCH = 9, // Gregorian Middle East French calendar - GREGORIAN_ARABIC = 10, // Gregorian Arabic calendar - GREGORIAN_XLIT_ENGLISH = 11, // Gregorian Transliterated English calendar - GREGORIAN_XLIT_FRENCH = 12, - // Note that all calendars after this point are MANAGED ONLY for now. - JULIAN = 13, - JAPANESELUNISOLAR = 14, - CHINESELUNISOLAR = 15, - SAKA = 16, // reserved to match Office but not implemented in our code - LUNAR_ETO_CHN = 17, // reserved to match Office but not implemented in our code - LUNAR_ETO_KOR = 18, // reserved to match Office but not implemented in our code - LUNAR_ETO_ROKUYOU = 19, // reserved to match Office but not implemented in our code - KOREANLUNISOLAR = 20, - TAIWANLUNISOLAR = 21, - PERSIAN = 22, - UMALQURA = 23, - LAST_CALENDAR = 23 // Last calendar ID -}; -typedef uint16_t CalendarId; - -/* -* These values should be kept in sync with System.Globalization.CalendarDataType -*/ -typedef enum -{ - CalendarData_Uninitialized = 0, - CalendarData_NativeName = 1, - CalendarData_MonthDay = 2, - CalendarData_ShortDates = 3, - CalendarData_LongDates = 4, - CalendarData_YearMonths = 5, - CalendarData_DayNames = 6, - CalendarData_AbbrevDayNames = 7, - CalendarData_MonthNames = 8, - CalendarData_AbbrevMonthNames = 9, - CalendarData_SuperShortDayNames = 10, - CalendarData_MonthGenitiveNames = 11, - CalendarData_AbbrevMonthGenitiveNames = 12, - CalendarData_EraNames = 13, - CalendarData_AbbrevEraNames = 14, -} CalendarDataType; - -#define GREGORIAN_NAME "gregorian" -#define JAPANESE_NAME "japanese" -#define BUDDHIST_NAME "buddhist" -#define HEBREW_NAME "hebrew" -#define DANGI_NAME "dangi" -#define PERSIAN_NAME "persian" -#define ISLAMIC_NAME "islamic" -#define ISLAMIC_UMALQURA_NAME "islamic-umalqura" -#define ROC_NAME "roc" - // the function pointer definition for the callback used in EnumCalendarInfo typedef void (PAL_CALLBACK_CALLTYPE *EnumCalendarInfoCallback)(const UChar*, const void*); @@ -101,19 +35,3 @@ PALEXPORT int32_t GlobalizationNative_GetJapaneseEraStartDate(int32_t era, int32_t* startYear, int32_t* startMonth, int32_t* startDay); -#if defined(APPLE_HYBRID_GLOBALIZATION) -PALEXPORT const char* GlobalizationNative_GetCalendarInfoNative(const char* localeName, - CalendarId calendarId, - CalendarDataType dataType); - -PALEXPORT int32_t GlobalizationNative_GetCalendarsNative(const char* localeName, - CalendarId* calendars, - int32_t calendarsCapacity); - -PALEXPORT int32_t GlobalizationNative_GetLatestJapaneseEraNative(void); - -PALEXPORT int32_t GlobalizationNative_GetJapaneseEraStartDateNative(int32_t era, - int32_t* startYear, - int32_t* startMonth, - int32_t* startDay); -#endif diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_calendarData.m b/src/native/libs/System.Globalization.Native/pal_calendarData.m similarity index 99% rename from src/native/libs/System.HybridGlobalization.Native/pal_calendarData.m rename to src/native/libs/System.Globalization.Native/pal_calendarData.m index 9520e17646754..d3196350dde25 100644 --- a/src/native/libs/System.HybridGlobalization.Native/pal_calendarData.m +++ b/src/native/libs/System.Globalization.Native/pal_calendarData.m @@ -2,8 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. #include -#include "pal_icushim_internal.h" -#include "pal_calendarData.h" +#include "pal_calendarData_hg.h" #import #if !__has_feature(objc_arc) diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_calendarData.h b/src/native/libs/System.Globalization.Native/pal_calendarData_hg.h similarity index 52% rename from src/native/libs/System.HybridGlobalization.Native/pal_calendarData.h rename to src/native/libs/System.Globalization.Native/pal_calendarData_hg.h index 8b1d83e9e9d4b..e9280c18e3194 100644 --- a/src/native/libs/System.HybridGlobalization.Native/pal_calendarData.h +++ b/src/native/libs/System.Globalization.Native/pal_calendarData_hg.h @@ -5,77 +5,11 @@ #include -#include "pal_locale.h" +#include "pal_common.h" +#include "pal_locale_hg.h" #include "pal_compiler.h" #include "pal_errors.h" -/* -* These values should be kept in sync with System.Globalization.CalendarId -*/ -enum -{ - UNINITIALIZED_VALUE = 0, - GREGORIAN = 1, // Gregorian (localized) calendar - GREGORIAN_US = 2, // Gregorian (U.S.) calendar - JAPAN = 3, // Japanese Emperor Era calendar - /* SSS_WARNINGS_OFF */ - TAIWAN = 4, // Taiwan Era calendar /* SSS_WARNINGS_ON */ - KOREA = 5, // Korean Tangun Era calendar - HIJRI = 6, // Hijri (Arabic Lunar) calendar - THAI = 7, // Thai calendar - HEBREW = 8, // Hebrew (Lunar) calendar - GREGORIAN_ME_FRENCH = 9, // Gregorian Middle East French calendar - GREGORIAN_ARABIC = 10, // Gregorian Arabic calendar - GREGORIAN_XLIT_ENGLISH = 11, // Gregorian Transliterated English calendar - GREGORIAN_XLIT_FRENCH = 12, - // Note that all calendars after this point are MANAGED ONLY for now. - JULIAN = 13, - JAPANESELUNISOLAR = 14, - CHINESELUNISOLAR = 15, - SAKA = 16, // reserved to match Office but not implemented in our code - LUNAR_ETO_CHN = 17, // reserved to match Office but not implemented in our code - LUNAR_ETO_KOR = 18, // reserved to match Office but not implemented in our code - LUNAR_ETO_ROKUYOU = 19, // reserved to match Office but not implemented in our code - KOREANLUNISOLAR = 20, - TAIWANLUNISOLAR = 21, - PERSIAN = 22, - UMALQURA = 23, - LAST_CALENDAR = 23 // Last calendar ID -}; -typedef uint16_t CalendarId; - -/* -* These values should be kept in sync with System.Globalization.CalendarDataType -*/ -typedef enum -{ - CalendarData_Uninitialized = 0, - CalendarData_NativeName = 1, - CalendarData_MonthDay = 2, - CalendarData_ShortDates = 3, - CalendarData_LongDates = 4, - CalendarData_YearMonths = 5, - CalendarData_DayNames = 6, - CalendarData_AbbrevDayNames = 7, - CalendarData_MonthNames = 8, - CalendarData_AbbrevMonthNames = 9, - CalendarData_SuperShortDayNames = 10, - CalendarData_MonthGenitiveNames = 11, - CalendarData_AbbrevMonthGenitiveNames = 12, - CalendarData_EraNames = 13, - CalendarData_AbbrevEraNames = 14, -} CalendarDataType; - -#define GREGORIAN_NAME "gregorian" -#define JAPANESE_NAME "japanese" -#define BUDDHIST_NAME "buddhist" -#define HEBREW_NAME "hebrew" -#define DANGI_NAME "dangi" -#define PERSIAN_NAME "persian" -#define ISLAMIC_NAME "islamic" -#define ISLAMIC_UMALQURA_NAME "islamic-umalqura" -#define ROC_NAME "roc" - // the function pointer definition for the callback used in EnumCalendarInfo typedef void (PAL_CALLBACK_CALLTYPE *EnumCalendarInfoCallback)(const UChar*, const void*); @@ -117,4 +51,3 @@ PALEXPORT int32_t GlobalizationNative_GetJapaneseEraStartDateNative(int32_t era, int32_t* startMonth, int32_t* startDay); #endif - diff --git a/src/native/libs/System.Globalization.Native/pal_casing.h b/src/native/libs/System.Globalization.Native/pal_casing.h index 5371ba3bb0886..b49a77593e3df 100644 --- a/src/native/libs/System.Globalization.Native/pal_casing.h +++ b/src/native/libs/System.Globalization.Native/pal_casing.h @@ -4,8 +4,6 @@ #include "pal_locale.h" #include "pal_compiler.h" -PALEXPORT void GlobalizationNative_InitOrdinalCasingPage(int32_t pageNumber, UChar* pTarget); - PALEXPORT void GlobalizationNative_ChangeCase(const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, @@ -23,18 +21,5 @@ PALEXPORT void GlobalizationNative_ChangeCaseTurkish(const UChar* lpSrc, UChar* lpDst, int32_t cwDstLength, int32_t bToUpper); -#if defined(APPLE_HYBRID_GLOBALIZATION) -PALEXPORT int32_t GlobalizationNative_ChangeCaseNative(const uint16_t* localeName, - int32_t lNameLength, - const uint16_t* lpSrc, - int32_t cwSrcLength, - uint16_t* lpDst, - int32_t cwDstLength, - int32_t bToUpper); -PALEXPORT int32_t GlobalizationNative_ChangeCaseInvariantNative(const uint16_t* lpSrc, - int32_t cwSrcLength, - uint16_t* lpDst, - int32_t cwDstLength, - int32_t bToUpper); -#endif +PALEXPORT void GlobalizationNative_InitOrdinalCasingPage(int32_t pageNumber, UChar* pTarget); diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_casing.m b/src/native/libs/System.Globalization.Native/pal_casing.m similarity index 98% rename from src/native/libs/System.HybridGlobalization.Native/pal_casing.m rename to src/native/libs/System.Globalization.Native/pal_casing.m index ba5c853c0b4c6..5a665a897c3be 100644 --- a/src/native/libs/System.HybridGlobalization.Native/pal_casing.m +++ b/src/native/libs/System.Globalization.Native/pal_casing.m @@ -1,8 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#include "pal_icushim_internal.h" -#include "pal_casing.h" +#include "pal_common.h" +#include "pal_casing_hg.h" +#include "pal_hybrid.h" #include "pal_errors.h" #import diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_casing.h b/src/native/libs/System.Globalization.Native/pal_casing_hg.h similarity index 98% rename from src/native/libs/System.HybridGlobalization.Native/pal_casing.h rename to src/native/libs/System.Globalization.Native/pal_casing_hg.h index 5371ba3bb0886..e43304ca21aaf 100644 --- a/src/native/libs/System.HybridGlobalization.Native/pal_casing.h +++ b/src/native/libs/System.Globalization.Native/pal_casing_hg.h @@ -1,11 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#include "pal_locale.h" +#include "pal_locale_hg.h" #include "pal_compiler.h" -PALEXPORT void GlobalizationNative_InitOrdinalCasingPage(int32_t pageNumber, UChar* pTarget); - PALEXPORT void GlobalizationNative_ChangeCase(const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, @@ -23,6 +21,8 @@ PALEXPORT void GlobalizationNative_ChangeCaseTurkish(const UChar* lpSrc, UChar* lpDst, int32_t cwDstLength, int32_t bToUpper); +PALEXPORT void GlobalizationNative_InitOrdinalCasingPage(int32_t pageNumber, UChar* pTarget); + #if defined(APPLE_HYBRID_GLOBALIZATION) PALEXPORT int32_t GlobalizationNative_ChangeCaseNative(const uint16_t* localeName, int32_t lNameLength, diff --git a/src/native/libs/System.Globalization.Native/pal_collation.c b/src/native/libs/System.Globalization.Native/pal_collation.c index 44de265b4a196..8f5bf34daad7d 100644 --- a/src/native/libs/System.Globalization.Native/pal_collation.c +++ b/src/native/libs/System.Globalization.Native/pal_collation.c @@ -11,6 +11,7 @@ #include "pal_errors_internal.h" #include "pal_collation.h" #include "pal_atomic.h" +#include "pal_common.h" c_static_assert_msg(UCOL_EQUAL == 0, "managed side requires 0 for equal strings"); c_static_assert_msg(UCOL_LESS < 0, "managed side requires less than zero for a < b"); diff --git a/src/native/libs/System.Globalization.Native/pal_collation.h b/src/native/libs/System.Globalization.Native/pal_collation.h index b2ef6e1ed3d24..9f98cc449aa29 100644 --- a/src/native/libs/System.Globalization.Native/pal_collation.h +++ b/src/native/libs/System.Globalization.Native/pal_collation.h @@ -4,15 +4,10 @@ #pragma once #include "pal_locale.h" +#include "pal_common.h" #include "pal_compiler.h" #include "pal_errors.h" -typedef struct SortHandle SortHandle; -typedef struct _Range { - int32_t location; - int32_t length; -} Range; - PALEXPORT ResultCode GlobalizationNative_GetSortHandle(const char* lpLocaleName, SortHandle** ppSortHandle); PALEXPORT void GlobalizationNative_CloseSortHandle(SortHandle* pSortHandle); @@ -65,46 +60,3 @@ PALEXPORT int32_t GlobalizationNative_GetSortKey(SortHandle* pSortHandle, uint8_t* sortKey, int32_t cbSortKeyLength, int32_t options); -#if defined(APPLE_HYBRID_GLOBALIZATION) -PALEXPORT int32_t GlobalizationNative_CompareStringNative(const uint16_t* localeName, - int32_t lNameLength, - const uint16_t* lpTarget, - int32_t cwTargetLength, - const uint16_t* lpSource, - int32_t cwSourceLength, - int32_t options); - -PALEXPORT Range GlobalizationNative_IndexOfNative(const uint16_t* localeName, - int32_t lNameLength, - const uint16_t* lpTarget, - int32_t cwTargetLength, - const uint16_t* lpSource, - int32_t cwSourceLength, - int32_t options, - int32_t fromBeginning); - -PALEXPORT int32_t GlobalizationNative_StartsWithNative(const uint16_t* localeName, - int32_t lNameLength, - const uint16_t* lpPrefix, - int32_t cwPrefixLength, - const uint16_t* lpSource, - int32_t cwSourceLength, - int32_t options); - -PALEXPORT int32_t GlobalizationNative_EndsWithNative(const uint16_t* localeName, - int32_t lNameLength, - const uint16_t* lpSuffix, - int32_t cwSuffixLength, - const uint16_t* lpSource, - int32_t cwSourceLength, - int32_t options); - -PALEXPORT int32_t GlobalizationNative_GetSortKeyNative(const uint16_t* localeName, - int32_t lNameLength, - const UChar* lpStr, - int32_t cwStrLength, - uint8_t* sortKey, - int32_t cbSortKeyLength, - int32_t options); - -#endif diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_collation.m b/src/native/libs/System.Globalization.Native/pal_collation.m similarity index 99% rename from src/native/libs/System.HybridGlobalization.Native/pal_collation.m rename to src/native/libs/System.Globalization.Native/pal_collation.m index 9a63c11be44ab..4e4440fc56179 100644 --- a/src/native/libs/System.HybridGlobalization.Native/pal_collation.m +++ b/src/native/libs/System.Globalization.Native/pal_collation.m @@ -3,7 +3,7 @@ #include #include "pal_locale_internal.h" -#include "pal_collation.h" +#include "pal_collation_hg.h" #import diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_collation.h b/src/native/libs/System.Globalization.Native/pal_collation_hg.h similarity index 97% rename from src/native/libs/System.HybridGlobalization.Native/pal_collation.h rename to src/native/libs/System.Globalization.Native/pal_collation_hg.h index b2ef6e1ed3d24..14dd7e8fdbd27 100644 --- a/src/native/libs/System.HybridGlobalization.Native/pal_collation.h +++ b/src/native/libs/System.Globalization.Native/pal_collation_hg.h @@ -3,16 +3,10 @@ #pragma once -#include "pal_locale.h" +#include "pal_locale_hg.h" #include "pal_compiler.h" #include "pal_errors.h" -typedef struct SortHandle SortHandle; -typedef struct _Range { - int32_t location; - int32_t length; -} Range; - PALEXPORT ResultCode GlobalizationNative_GetSortHandle(const char* lpLocaleName, SortHandle** ppSortHandle); PALEXPORT void GlobalizationNative_CloseSortHandle(SortHandle* pSortHandle); diff --git a/src/native/libs/System.Globalization.Native/pal_common.h b/src/native/libs/System.Globalization.Native/pal_common.h new file mode 100644 index 0000000000000..2bb51498f44a1 --- /dev/null +++ b/src/native/libs/System.Globalization.Native/pal_common.h @@ -0,0 +1,185 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +#pragma once + +#if defined(TARGET_UNIX) + +#include "pal_compiler.h" + +// All ICU headers need to be included here so that all function prototypes are +// available before the function pointers are declared below. +#include +#include +#include +// calendarData +/* +* These values should be kept in sync with System.Globalization.CalendarId +*/ +enum +{ + UNINITIALIZED_VALUE = 0, + GREGORIAN = 1, // Gregorian (localized) calendar + GREGORIAN_US = 2, // Gregorian (U.S.) calendar + JAPAN = 3, // Japanese Emperor Era calendar + /* SSS_WARNINGS_OFF */ + TAIWAN = 4, // Taiwan Era calendar /* SSS_WARNINGS_ON */ + KOREA = 5, // Korean Tangun Era calendar + HIJRI = 6, // Hijri (Arabic Lunar) calendar + THAI = 7, // Thai calendar + HEBREW = 8, // Hebrew (Lunar) calendar + GREGORIAN_ME_FRENCH = 9, // Gregorian Middle East French calendar + GREGORIAN_ARABIC = 10, // Gregorian Arabic calendar + GREGORIAN_XLIT_ENGLISH = 11, // Gregorian Transliterated English calendar + GREGORIAN_XLIT_FRENCH = 12, + // Note that all calendars after this point are MANAGED ONLY for now. + JULIAN = 13, + JAPANESELUNISOLAR = 14, + CHINESELUNISOLAR = 15, + SAKA = 16, // reserved to match Office but not implemented in our code + LUNAR_ETO_CHN = 17, // reserved to match Office but not implemented in our code + LUNAR_ETO_KOR = 18, // reserved to match Office but not implemented in our code + LUNAR_ETO_ROKUYOU = 19, // reserved to match Office but not implemented in our code + KOREANLUNISOLAR = 20, + TAIWANLUNISOLAR = 21, + PERSIAN = 22, + UMALQURA = 23, + LAST_CALENDAR = 23 // Last calendar ID +}; +typedef uint16_t CalendarId; + +/* +* These values should be kept in sync with System.Globalization.CalendarDataType +*/ +typedef enum +{ + CalendarData_Uninitialized = 0, + CalendarData_NativeName = 1, + CalendarData_MonthDay = 2, + CalendarData_ShortDates = 3, + CalendarData_LongDates = 4, + CalendarData_YearMonths = 5, + CalendarData_DayNames = 6, + CalendarData_AbbrevDayNames = 7, + CalendarData_MonthNames = 8, + CalendarData_AbbrevMonthNames = 9, + CalendarData_SuperShortDayNames = 10, + CalendarData_MonthGenitiveNames = 11, + CalendarData_AbbrevMonthGenitiveNames = 12, + CalendarData_EraNames = 13, + CalendarData_AbbrevEraNames = 14, +} CalendarDataType; + +#define GREGORIAN_NAME "gregorian" +#define JAPANESE_NAME "japanese" +#define BUDDHIST_NAME "buddhist" +#define HEBREW_NAME "hebrew" +#define DANGI_NAME "dangi" +#define PERSIAN_NAME "persian" +#define ISLAMIC_NAME "islamic" +#define ISLAMIC_UMALQURA_NAME "islamic-umalqura" +#define ROC_NAME "roc" + + +// locale data +// Enum that corresponds to managed enum CultureData.LocaleNumberData. +// The numeric values of the enum members match their Win32 counterparts. +typedef enum +{ + LocaleNumber_LanguageId = 0x01, + LocaleNumber_MeasurementSystem = 0x0D, + LocaleNumber_FractionalDigitsCount = 0x00000011, + LocaleNumber_NegativeNumberFormat = 0x00001010, + LocaleNumber_MonetaryFractionalDigitsCount = 0x00000019, + LocaleNumber_PositiveMonetaryNumberFormat = 0x0000001B, + LocaleNumber_NegativeMonetaryNumberFormat = 0x0000001C, + LocaleNumber_FirstDayofWeek = 0x0000100C, + LocaleNumber_FirstWeekOfYear = 0x0000100D, + LocaleNumber_ReadingLayout = 0x00000070, + LocaleNumber_NegativePercentFormat = 0x00000074, + LocaleNumber_PositivePercentFormat = 0x00000075, + LocaleNumber_Digit = 0x00000010, + LocaleNumber_Monetary = 0x00000018 +} LocaleNumberData; + +// Enum that corresponds to managed enum System.Globalization.CalendarWeekRule +typedef enum +{ + WeekRule_FirstDay = 0, + WeekRule_FirstFullWeek = 1, + WeekRule_FirstFourDayWeek = 2 +} CalendarWeekRule; + +// Enum that corresponds to managed enum CultureData.LocaleStringData. +// The numeric values of the enum members match their Win32 counterparts. +typedef enum +{ + LocaleString_LocalizedDisplayName = 0x02, + LocaleString_EnglishDisplayName = 0x00000072, + LocaleString_NativeDisplayName = 0x00000073, + LocaleString_LocalizedLanguageName = 0x0000006f, + LocaleString_EnglishLanguageName = 0x00001001, + LocaleString_NativeLanguageName = 0x04, + LocaleString_EnglishCountryName = 0x00001002, + LocaleString_NativeCountryName = 0x08, + LocaleString_DecimalSeparator = 0x0E, + LocaleString_ThousandSeparator = 0x0F, + LocaleString_Digits = 0x00000013, + LocaleString_MonetarySymbol = 0x00000014, + LocaleString_CurrencyEnglishName = 0x00001007, + LocaleString_CurrencyNativeName = 0x00001008, + LocaleString_Iso4217MonetarySymbol = 0x00000015, + LocaleString_MonetaryDecimalSeparator = 0x00000016, + LocaleString_MonetaryThousandSeparator = 0x00000017, + LocaleString_AMDesignator = 0x00000028, + LocaleString_PMDesignator = 0x00000029, + LocaleString_PositiveSign = 0x00000050, + LocaleString_NegativeSign = 0x00000051, + LocaleString_Iso639LanguageTwoLetterName = 0x00000059, + LocaleString_Iso639LanguageThreeLetterName = 0x00000067, + LocaleString_Iso3166CountryName = 0x0000005A, + LocaleString_Iso3166CountryName2= 0x00000068, + LocaleString_NaNSymbol = 0x00000069, + LocaleString_PositiveInfinitySymbol = 0x0000006a, + LocaleString_NegativeInfinitySymbol = 0x0000006b, + LocaleString_ParentName = 0x0000006d, + LocaleString_PercentSymbol = 0x00000076, + LocaleString_PerMilleSymbol = 0x00000077 +} LocaleStringData; + +// normalization +/* + * These values should be kept in sync with System.Text.NormalizationForm + */ +typedef enum +{ + FormC = 0x1, + FormD = 0x2, + FormKC = 0x5, + FormKD = 0x6 +} NormalizationForm; + +// timezoneinfo +/* +These values should be kept in sync with the managed Interop.GlobalizationInterop.TimeZoneDisplayNameType enum. +*/ +typedef enum +{ + TimeZoneDisplayName_Generic = 0, + TimeZoneDisplayName_Standard = 1, + TimeZoneDisplayName_DaylightSavings = 2, + TimeZoneDisplayName_GenericLocation = 3, + TimeZoneDisplayName_ExemplarCity = 4, + TimeZoneDisplayName_TimeZoneName = 5, +} TimeZoneDisplayNameType; + +// collation + +typedef struct SortHandle SortHandle; +typedef struct _Range { + int32_t location; + int32_t length; +} Range; + +#endif diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_locale.h b/src/native/libs/System.Globalization.Native/pal_hybrid.h similarity index 93% rename from src/native/libs/System.HybridGlobalization.Native/pal_locale.h rename to src/native/libs/System.Globalization.Native/pal_hybrid.h index 8ded749d3c11c..ad4b2d078dd4a 100644 --- a/src/native/libs/System.HybridGlobalization.Native/pal_locale.h +++ b/src/native/libs/System.Globalization.Native/pal_hybrid.h @@ -1,33 +1,3 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#pragma once - -#include "pal_compiler.h" - -PALEXPORT int32_t GlobalizationNative_GetLocales(UChar *value, int32_t valueLength); - -PALEXPORT int32_t GlobalizationNative_GetLocaleName(const UChar* localeName, UChar* value, int32_t valueLength); - -PALEXPORT int32_t GlobalizationNative_GetDefaultLocaleName(UChar* value, int32_t valueLength); - -PALEXPORT int32_t GlobalizationNative_IsPredefinedLocale(const UChar* localeName); - -PALEXPORT int32_t GlobalizationNative_GetLocaleTimeFormat(const UChar* localeName, - int shortFormat, UChar* value, - int32_t valueLength); -#if defined(APPLE_HYBRID_GLOBALIZATION) - -PALEXPORT const char* GlobalizationNative_GetDefaultLocaleNameNative(void); - -PALEXPORT const char* GlobalizationNative_GetLocaleNameNative(const char* localeName); - -PALEXPORT const char* GlobalizationNative_GetLocaleTimeFormatNative(const char* localeName, int shortFormat); - -PALEXPORT int32_t GlobalizationNative_GetLocalesNative(UChar* locales, int32_t length); - -PALEXPORT int32_t GlobalizationNative_IsPredefinedLocaleNative(const char* localeName); - /* ### Data tables **************************************************/ /** @@ -401,4 +371,33 @@ NULL, NULL }; -#endif +/** + * Append a code point to a string, overwriting 1 or 2 code units. + * The offset points to the current end of the string contents + * and is advanced (post-increment). + * "Safe" macro, checks for a valid code point. + * Converts code points outside of Basic Multilingual Plane into + * corresponding surrogate pairs if sufficient space in the string. + * High surrogate range: 0xD800 - 0xDBFF + * Low surrogate range: 0xDC00 - 0xDFFF + * If the code point is not valid or a trail surrogate does not fit, + * then isError is set to true. + * + * @param buffer const uint16_t * string buffer + * @param offset string offset, must be offset= (capacity)) /* insufficiently sized destination buffer */ { \ + (isError) = InsufficientBuffer; \ + } else if ((uint32_t)(codePoint) > 0x10ffff) /* invalid code point */ { \ + (isError) = InvalidCodePoint; \ + } else if ((uint32_t)(codePoint) <= 0xffff) { \ + (buffer)[(offset)++] = (uint16_t)(codePoint); \ + } else { \ + (buffer)[(offset)++] = (uint16_t)(((codePoint) >> 10) + 0xd7c0); \ + (buffer)[(offset)++] = (uint16_t)(((codePoint)&0x3ff) | 0xdc00); \ + } \ +} diff --git a/src/native/libs/System.Globalization.Native/pal_icushim_internal.h b/src/native/libs/System.Globalization.Native/pal_icushim_internal.h index e62ced1015f4e..a3290688efb7b 100644 --- a/src/native/libs/System.Globalization.Native/pal_icushim_internal.h +++ b/src/native/libs/System.Globalization.Native/pal_icushim_internal.h @@ -16,7 +16,7 @@ #else #if !defined(LOCAL_BUILD) -#define U_DISABLE_RENAMING 1 +#define U_DISABLE_RENAMING 1 // this #endif // All ICU headers need to be included here so that all function prototypes are diff --git a/src/native/libs/System.Globalization.Native/pal_icushim_static.c b/src/native/libs/System.Globalization.Native/pal_icushim_static.c index 0283be2f5f1ae..c848202405402 100644 --- a/src/native/libs/System.Globalization.Native/pal_icushim_static.c +++ b/src/native/libs/System.Globalization.Native/pal_icushim_static.c @@ -10,6 +10,7 @@ #include #include #include + #include #if defined(TARGET_UNIX) @@ -18,7 +19,7 @@ #define strcasecmp _stricmp #define strncasecmp _strnicmp #endif - +// #if !defined(TARGET_MACCATALYST) && !defined(TARGET_IOS) && !defined(TARGET_TVOS) static int32_t isLoaded = 0; static int32_t isDataSet = 0; @@ -247,5 +248,5 @@ int32_t GlobalizationNative_GetICUVersion(void) return (versionInfo[0] << 24) + (versionInfo[1] << 16) + (versionInfo[2] << 8) + versionInfo[3]; } - +// #endif diff --git a/src/native/libs/System.Globalization.Native/pal_locale.h b/src/native/libs/System.Globalization.Native/pal_locale.h index 8ded749d3c11c..0c6e1e6933bf3 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.h +++ b/src/native/libs/System.Globalization.Native/pal_locale.h @@ -16,389 +16,4 @@ PALEXPORT int32_t GlobalizationNative_IsPredefinedLocale(const UChar* localeName PALEXPORT int32_t GlobalizationNative_GetLocaleTimeFormat(const UChar* localeName, int shortFormat, UChar* value, int32_t valueLength); -#if defined(APPLE_HYBRID_GLOBALIZATION) -PALEXPORT const char* GlobalizationNative_GetDefaultLocaleNameNative(void); - -PALEXPORT const char* GlobalizationNative_GetLocaleNameNative(const char* localeName); - -PALEXPORT const char* GlobalizationNative_GetLocaleTimeFormatNative(const char* localeName, int shortFormat); - -PALEXPORT int32_t GlobalizationNative_GetLocalesNative(UChar* locales, int32_t length); - -PALEXPORT int32_t GlobalizationNative_IsPredefinedLocaleNative(const char* localeName); - -/* ### Data tables **************************************************/ - -/** - * Table of language codes, both 2- and 3-letter, with preference - * given to 2-letter codes where possible. Includes 3-letter codes - * that lack a 2-letter equivalent. - * - * This list must be in sorted order. This list is returned directly - * to the user by some API. - * - * This list must be kept in sync with LANGUAGES_3, with corresponding - * entries matched. - * - * This table should be terminated with a NULL entry, followed by a - * second list, and another NULL entry. The first list is visible to - * user code when this array is returned by API. The second list - * contains codes we support, but do not expose through user API. - * - * Notes - * - * Tables updated per http://lcweb.loc.gov/standards/iso639-2/ to - * include the revisions up to 2001/7/27 *CWB* - * - * The 3 character codes are the terminology codes like RFC 3066. - * - * "in" "iw" "ji" "jw" & "sh" have been withdrawn but are still in the - * table but now at the end of the table because 3 character codes are - * duplicates. This avoids bad searches going from 3 to 2 character - * codes. - * - * The range qaa-qtz is reserved for local use - */ -/* Subsequent hand addition of selected languages */ -static const char * const LANGUAGES[] = { - "aa", "ab", "ace", "ach", "ada", "ady", "ae", "aeb", - "af", "afh", "agq", "ain", "ak", "akk", "akz", "ale", - "aln", "alt", "am", "an", "ang", "anp", "ar", "arc", - "arn", "aro", "arp", "arq", "ars", "arw", "ary", "arz", "as", - "asa", "ase", "ast", "av", "avk", "awa", "ay", "az", - "ba", "bal", "ban", "bar", "bas", "bax", "bbc", "bbj", - "be", "bej", "bem", "bew", "bez", "bfd", "bfq", "bg", - "bgn", "bho", "bi", "bik", "bin", "bjn", "bkm", "bla", - "bm", "bn", "bo", "bpy", "bqi", "br", "bra", "brh", - "brx", "bs", "bss", "bua", "bug", "bum", "byn", "byv", - "ca", "cad", "car", "cay", "cch", "ccp", "ce", "ceb", "cgg", - "ch", "chb", "chg", "chk", "chm", "chn", "cho", "chp", - "chr", "chy", "ckb", "co", "cop", "cps", "cr", "crh", - "cs", "csb", "cu", "cv", "cy", - "da", "dak", "dar", "dav", "de", "del", "den", "dgr", - "din", "dje", "doi", "dsb", "dtp", "dua", "dum", "dv", - "dyo", "dyu", "dz", "dzg", - "ebu", "ee", "efi", "egl", "egy", "eka", "el", "elx", - "en", "enm", "eo", "es", "esu", "et", "eu", "ewo", - "ext", - "fa", "fan", "fat", "ff", "fi", "fil", "fit", "fj", - "fo", "fon", "fr", "frc", "frm", "fro", "frp", "frr", - "frs", "fur", "fy", - "ga", "gaa", "gag", "gan", "gay", "gba", "gbz", "gd", - "gez", "gil", "gl", "glk", "gmh", "gn", "goh", "gom", - "gon", "gor", "got", "grb", "grc", "gsw", "gu", "guc", - "gur", "guz", "gv", "gwi", - "ha", "hai", "hak", "haw", "he", "hi", "hif", "hil", - "hit", "hmn", "ho", "hr", "hsb", "hsn", "ht", "hu", - "hup", "hy", "hz", - "ia", "iba", "ibb", "id", "ie", "ig", "ii", "ik", - "ilo", "inh", "io", "is", "it", "iu", "izh", - "ja", "jam", "jbo", "jgo", "jmc", "jpr", "jrb", "jut", - "jv", - "ka", "kaa", "kab", "kac", "kaj", "kam", "kaw", "kbd", - "kbl", "kcg", "kde", "kea", "ken", "kfo", "kg", "kgp", - "kha", "kho", "khq", "khw", "ki", "kiu", "kj", "kk", - "kkj", "kl", "kln", "km", "kmb", "kn", "ko", "koi", - "kok", "kos", "kpe", "kr", "krc", "kri", "krj", "krl", - "kru", "ks", "ksb", "ksf", "ksh", "ku", "kum", "kut", - "kv", "kw", "ky", - "la", "lad", "lag", "lah", "lam", "lb", "lez", "lfn", - "lg", "li", "lij", "liv", "lkt", "lmo", "ln", "lo", - "lol", "loz", "lrc", "lt", "ltg", "lu", "lua", "lui", - "lun", "luo", "lus", "luy", "lv", "lzh", "lzz", - "mad", "maf", "mag", "mai", "mak", "man", "mas", "mde", - "mdf", "mdh", "mdr", "men", "mer", "mfe", "mg", "mga", - "mgh", "mgo", "mh", "mi", "mic", "min", "mis", "mk", - "ml", "mn", "mnc", "mni", "mo", - "moh", "mos", "mr", "mrj", - "ms", "mt", "mua", "mul", "mus", "mwl", "mwr", "mwv", - "my", "mye", "myv", "mzn", - "na", "nan", "nap", "naq", "nb", "nd", "nds", "ne", - "new", "ng", "nia", "niu", "njo", "nl", "nmg", "nn", - "nnh", "no", "nog", "non", "nov", "nqo", "nr", "nso", - "nus", "nv", "nwc", "ny", "nym", "nyn", "nyo", "nzi", - "oc", "oj", "om", "or", "os", "osa", "ota", - "pa", "pag", "pal", "pam", "pap", "pau", "pcd", "pcm", "pdc", - "pdt", "peo", "pfl", "phn", "pi", "pl", "pms", "pnt", - "pon", "prg", "pro", "ps", "pt", - "qu", "quc", "qug", - "raj", "rap", "rar", "rgn", "rif", "rm", "rn", "ro", - "rof", "rom", "rtm", "ru", "rue", "rug", "rup", - "rw", "rwk", - "sa", "sad", "sah", "sam", "saq", "sas", "sat", "saz", - "sba", "sbp", "sc", "scn", "sco", "sd", "sdc", "sdh", - "se", "see", "seh", "sei", "sel", "ses", "sg", "sga", - "sgs", "shi", "shn", "shu", "si", "sid", "sk", - "sl", "sli", "sly", "sm", "sma", "smj", "smn", "sms", - "sn", "snk", "so", "sog", "sq", "sr", "srn", "srr", - "ss", "ssy", "st", "stq", "su", "suk", "sus", "sux", - "sv", "sw", "swb", "swc", "syc", "syr", "szl", - "ta", "tcy", "te", "tem", "teo", "ter", "tet", "tg", - "th", "ti", "tig", "tiv", "tk", "tkl", "tkr", "tl", - "tlh", "tli", "tly", "tmh", "tn", "to", "tog", "tpi", - "tr", "tru", "trv", "ts", "tsd", "tsi", "tt", "ttt", - "tum", "tvl", "tw", "twq", "ty", "tyv", "tzm", - "udm", "ug", "uga", "uk", "umb", "und", "ur", "uz", - "vai", "ve", "vec", "vep", "vi", "vls", "vmf", "vo", - "vot", "vro", "vun", - "wa", "wae", "wal", "war", "was", "wbp", "wo", "wuu", - "xal", "xh", "xmf", "xog", - "yao", "yap", "yav", "ybb", "yi", "yo", "yrl", "yue", - "za", "zap", "zbl", "zea", "zen", "zgh", "zh", "zu", - "zun", "zxx", "zza", -NULL, - "in", "iw", "ji", "jw", "sh", /* obsolete language codes */ -NULL -}; - -/** - * Table of 3-letter language codes. - * - * This is a lookup table used to convert 3-letter language codes to - * their 2-letter equivalent, where possible. It must be kept in sync - * with LANGUAGES. For all valid i, LANGUAGES[i] must refer to the - * same language as LANGUAGES_3[i]. The commented-out lines are - * copied from LANGUAGES to make eyeballing this baby easier. - * - * Where a 3-letter language code has no 2-letter equivalent, the - * 3-letter code occupies both LANGUAGES[i] and LANGUAGES_3[i]. - * - * This table should be terminated with a NULL entry, followed by a - * second list, and another NULL entry. The two lists correspond to - * the two lists in LANGUAGES. - */ -/* Subsequent hand addition of selected languages */ -static const char * const LANGUAGES_3[] = { - "aar", "abk", "ace", "ach", "ada", "ady", "ave", "aeb", - "afr", "afh", "agq", "ain", "aka", "akk", "akz", "ale", - "aln", "alt", "amh", "arg", "ang", "anp", "ara", "arc", - "arn", "aro", "arp", "arq", "ars", "arw", "ary", "arz", "asm", - "asa", "ase", "ast", "ava", "avk", "awa", "aym", "aze", - "bak", "bal", "ban", "bar", "bas", "bax", "bbc", "bbj", - "bel", "bej", "bem", "bew", "bez", "bfd", "bfq", "bul", - "bgn", "bho", "bis", "bik", "bin", "bjn", "bkm", "bla", - "bam", "ben", "bod", "bpy", "bqi", "bre", "bra", "brh", - "brx", "bos", "bss", "bua", "bug", "bum", "byn", "byv", - "cat", "cad", "car", "cay", "cch", "ccp", "che", "ceb", "cgg", - "cha", "chb", "chg", "chk", "chm", "chn", "cho", "chp", - "chr", "chy", "ckb", "cos", "cop", "cps", "cre", "crh", - "ces", "csb", "chu", "chv", "cym", - "dan", "dak", "dar", "dav", "deu", "del", "den", "dgr", - "din", "dje", "doi", "dsb", "dtp", "dua", "dum", "div", - "dyo", "dyu", "dzo", "dzg", - "ebu", "ewe", "efi", "egl", "egy", "eka", "ell", "elx", - "eng", "enm", "epo", "spa", "esu", "est", "eus", "ewo", - "ext", - "fas", "fan", "fat", "ful", "fin", "fil", "fit", "fij", - "fao", "fon", "fra", "frc", "frm", "fro", "frp", "frr", - "frs", "fur", "fry", - "gle", "gaa", "gag", "gan", "gay", "gba", "gbz", "gla", - "gez", "gil", "glg", "glk", "gmh", "grn", "goh", "gom", - "gon", "gor", "got", "grb", "grc", "gsw", "guj", "guc", - "gur", "guz", "glv", "gwi", - "hau", "hai", "hak", "haw", "heb", "hin", "hif", "hil", - "hit", "hmn", "hmo", "hrv", "hsb", "hsn", "hat", "hun", - "hup", "hye", "her", - "ina", "iba", "ibb", "ind", "ile", "ibo", "iii", "ipk", - "ilo", "inh", "ido", "isl", "ita", "iku", "izh", - "jpn", "jam", "jbo", "jgo", "jmc", "jpr", "jrb", "jut", - "jav", - "kat", "kaa", "kab", "kac", "kaj", "kam", "kaw", "kbd", - "kbl", "kcg", "kde", "kea", "ken", "kfo", "kon", "kgp", - "kha", "kho", "khq", "khw", "kik", "kiu", "kua", "kaz", - "kkj", "kal", "kln", "khm", "kmb", "kan", "kor", "koi", - "kok", "kos", "kpe", "kau", "krc", "kri", "krj", "krl", - "kru", "kas", "ksb", "ksf", "ksh", "kur", "kum", "kut", - "kom", "cor", "kir", - "lat", "lad", "lag", "lah", "lam", "ltz", "lez", "lfn", - "lug", "lim", "lij", "liv", "lkt", "lmo", "lin", "lao", - "lol", "loz", "lrc", "lit", "ltg", "lub", "lua", "lui", - "lun", "luo", "lus", "luy", "lav", "lzh", "lzz", - "mad", "maf", "mag", "mai", "mak", "man", "mas", "mde", - "mdf", "mdh", "mdr", "men", "mer", "mfe", "mlg", "mga", - "mgh", "mgo", "mah", "mri", "mic", "min", "mis", "mkd", - "mal", "mon", "mnc", "mni", "mol", - "moh", "mos", "mar", "mrj", - "msa", "mlt", "mua", "mul", "mus", "mwl", "mwr", "mwv", - "mya", "mye", "myv", "mzn", - "nau", "nan", "nap", "naq", "nob", "nde", "nds", "nep", - "new", "ndo", "nia", "niu", "njo", "nld", "nmg", "nno", - "nnh", "nor", "nog", "non", "nov", "nqo", "nbl", "nso", - "nus", "nav", "nwc", "nya", "nym", "nyn", "nyo", "nzi", - "oci", "oji", "orm", "ori", "oss", "osa", "ota", - "pan", "pag", "pal", "pam", "pap", "pau", "pcd", "pcm", "pdc", - "pdt", "peo", "pfl", "phn", "pli", "pol", "pms", "pnt", - "pon", "prg", "pro", "pus", "por", - "que", "quc", "qug", - "raj", "rap", "rar", "rgn", "rif", "roh", "run", "ron", - "rof", "rom", "rtm", "rus", "rue", "rug", "rup", - "kin", "rwk", - "san", "sad", "sah", "sam", "saq", "sas", "sat", "saz", - "sba", "sbp", "srd", "scn", "sco", "snd", "sdc", "sdh", - "sme", "see", "seh", "sei", "sel", "ses", "sag", "sga", - "sgs", "shi", "shn", "shu", "sin", "sid", "slk", - "slv", "sli", "sly", "smo", "sma", "smj", "smn", "sms", - "sna", "snk", "som", "sog", "sqi", "srp", "srn", "srr", - "ssw", "ssy", "sot", "stq", "sun", "suk", "sus", "sux", - "swe", "swa", "swb", "swc", "syc", "syr", "szl", - "tam", "tcy", "tel", "tem", "teo", "ter", "tet", "tgk", - "tha", "tir", "tig", "tiv", "tuk", "tkl", "tkr", "tgl", - "tlh", "tli", "tly", "tmh", "tsn", "ton", "tog", "tpi", - "tur", "tru", "trv", "tso", "tsd", "tsi", "tat", "ttt", - "tum", "tvl", "twi", "twq", "tah", "tyv", "tzm", - "udm", "uig", "uga", "ukr", "umb", "und", "urd", "uzb", - "vai", "ven", "vec", "vep", "vie", "vls", "vmf", "vol", - "vot", "vro", "vun", - "wln", "wae", "wal", "war", "was", "wbp", "wol", "wuu", - "xal", "xho", "xmf", "xog", - "yao", "yap", "yav", "ybb", "yid", "yor", "yrl", "yue", - "zha", "zap", "zbl", "zea", "zen", "zgh", "zho", "zul", - "zun", "zxx", "zza", -NULL, -/* "in", "iw", "ji", "jw", "sh", */ - "ind", "heb", "yid", "jaw", "srp", -NULL -}; - -/** - * Table of 2-letter country codes. - * - * This list must be in sorted order. This list is returned directly - * to the user by some API. - * - * This list must be kept in sync with COUNTRIES_3, with corresponding - * entries matched. - * - * This table should be terminated with a NULL entry, followed by a - * second list, and another NULL entry. The first list is visible to - * user code when this array is returned by API. The second list - * contains codes we support, but do not expose through user API. - * - * Notes: - * - * ZR(ZAR) is now CD(COD) and FX(FXX) is PS(PSE) as per - * http://www.evertype.com/standards/iso3166/iso3166-1-en.html added - * new codes keeping the old ones for compatibility updated to include - * 1999/12/03 revisions *CWB* - * - * RO(ROM) is now RO(ROU) according to - * http://www.iso.org/iso/en/prods-services/iso3166ma/03updates-on-iso-3166/nlv3e-rou.html - */ -static const char * const COUNTRIES[] = { - "AD", "AE", "AF", "AG", "AI", "AL", "AM", - "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", - "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", - "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", - "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", - "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", - "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", - "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", - "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", - "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", - "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", - "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", - "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", - "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", - "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", - "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", - "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", - "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", - "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", - "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", - "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", - "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", - "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", - "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", - "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", - "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", - "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", - "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", - "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", - "WS", "YE", "YT", "ZA", "ZM", "ZW", -NULL, - "AN", "BU", "CS", "FX", "RO", "SU", "TP", "YD", "YU", "ZR", /* obsolete country codes */ -NULL -}; - -/** - * Table of 3-letter country codes. - * - * This is a lookup table used to convert 3-letter country codes to - * their 2-letter equivalent. It must be kept in sync with COUNTRIES. - * For all valid i, COUNTRIES[i] must refer to the same country as - * COUNTRIES_3[i]. The commented-out lines are copied from COUNTRIES - * to make eyeballing this baby easier. - * - * This table should be terminated with a NULL entry, followed by a - * second list, and another NULL entry. The two lists correspond to - * the two lists in COUNTRIES. - */ -static const char * const COUNTRIES_3[] = { -/* "AD", "AE", "AF", "AG", "AI", "AL", "AM", */ - "AND", "ARE", "AFG", "ATG", "AIA", "ALB", "ARM", -/* "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", */ - "AGO", "ATA", "ARG", "ASM", "AUT", "AUS", "ABW", "ALA", "AZE", -/* "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", */ - "BIH", "BRB", "BGD", "BEL", "BFA", "BGR", "BHR", "BDI", -/* "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", */ - "BEN", "BLM", "BMU", "BRN", "BOL", "BES", "BRA", "BHS", "BTN", "BVT", -/* "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", */ - "BWA", "BLR", "BLZ", "CAN", "CCK", "COD", "CAF", "COG", -/* "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", */ - "CHE", "CIV", "COK", "CHL", "CMR", "CHN", "COL", "CRI", -/* "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", */ - "CUB", "CPV", "CUW", "CXR", "CYP", "CZE", "DEU", "DJI", "DNK", -/* "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", */ - "DMA", "DOM", "DZA", "ECU", "EST", "EGY", "ESH", "ERI", -/* "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", */ - "ESP", "ETH", "FIN", "FJI", "FLK", "FSM", "FRO", "FRA", -/* "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", */ - "GAB", "GBR", "GRD", "GEO", "GUF", "GGY", "GHA", "GIB", "GRL", -/* "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", */ - "GMB", "GIN", "GLP", "GNQ", "GRC", "SGS", "GTM", "GUM", -/* "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", */ - "GNB", "GUY", "HKG", "HMD", "HND", "HRV", "HTI", "HUN", -/* "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS" */ - "IDN", "IRL", "ISR", "IMN", "IND", "IOT", "IRQ", "IRN", "ISL", -/* "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", */ - "ITA", "JEY", "JAM", "JOR", "JPN", "KEN", "KGZ", "KHM", "KIR", -/* "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", */ - "COM", "KNA", "PRK", "KOR", "KWT", "CYM", "KAZ", "LAO", -/* "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", */ - "LBN", "LCA", "LIE", "LKA", "LBR", "LSO", "LTU", "LUX", -/* "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", */ - "LVA", "LBY", "MAR", "MCO", "MDA", "MNE", "MAF", "MDG", "MHL", "MKD", -/* "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", */ - "MLI", "MMR", "MNG", "MAC", "MNP", "MTQ", "MRT", "MSR", -/* "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", */ - "MLT", "MUS", "MDV", "MWI", "MEX", "MYS", "MOZ", "NAM", -/* "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", */ - "NCL", "NER", "NFK", "NGA", "NIC", "NLD", "NOR", "NPL", -/* "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", */ - "NRU", "NIU", "NZL", "OMN", "PAN", "PER", "PYF", "PNG", -/* "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", */ - "PHL", "PAK", "POL", "SPM", "PCN", "PRI", "PSE", "PRT", -/* "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", */ - "PLW", "PRY", "QAT", "REU", "ROU", "SRB", "RUS", "RWA", "SAU", -/* "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", */ - "SLB", "SYC", "SDN", "SWE", "SGP", "SHN", "SVN", "SJM", -/* "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", */ - "SVK", "SLE", "SMR", "SEN", "SOM", "SUR", "SSD", "STP", "SLV", -/* "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", */ - "SXM", "SYR", "SWZ", "TCA", "TCD", "ATF", "TGO", "THA", "TJK", -/* "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", */ - "TKL", "TLS", "TKM", "TUN", "TON", "TUR", "TTO", "TUV", -/* "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", */ - "TWN", "TZA", "UKR", "UGA", "UMI", "USA", "URY", "UZB", -/* "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", */ - "VAT", "VCT", "VEN", "VGB", "VIR", "VNM", "VUT", "WLF", -/* "WS", "YE", "YT", "ZA", "ZM", "ZW", */ - "WSM", "YEM", "MYT", "ZAF", "ZMB", "ZWE", -NULL, -/* "AN", "BU", "CS", "FX", "RO", "SU", "TP", "YD", "YU", "ZR" */ - "ANT", "BUR", "SCG", "FXX", "ROM", "SUN", "TMP", "YMD", "YUG", "ZAR", -NULL -}; - -#endif diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index 5390509dd7287..5767273c9a3af 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -3,11 +3,15 @@ #include #include -#include "pal_locale_internal.h" -#include "pal_localeStringData.h" -#include "pal_localeNumberData.h" +#include "pal_hybrid.h" +#include "pal_common.h" +// #include "pal_locale_hybrid.h" +// #include "pal_locale_internal.h" +// #include "pal_localeStringData.h" +// #include "pal_localeNumberData.h" #import +#import #if !__has_feature(objc_arc) #error This file relies on ARC for memory management, but ARC is not enabled. @@ -35,6 +39,7 @@ return strdup([localeName UTF8String]); } + const char* GlobalizationNative_GetICUDataPathRelativeToAppBundleRoot(const char* path) { @autoreleasepool @@ -55,6 +60,3 @@ } } - - - diff --git a/src/native/libs/System.Globalization.Native/pal_localeNumberData.h b/src/native/libs/System.Globalization.Native/pal_localeNumberData.h index f609c654e1292..1de613b1b6706 100644 --- a/src/native/libs/System.Globalization.Native/pal_localeNumberData.h +++ b/src/native/libs/System.Globalization.Native/pal_localeNumberData.h @@ -7,33 +7,6 @@ #include "pal_locale.h" #include "pal_compiler.h" -// Enum that corresponds to managed enum CultureData.LocaleNumberData. -// The numeric values of the enum members match their Win32 counterparts. -typedef enum -{ - LocaleNumber_LanguageId = 0x01, - LocaleNumber_MeasurementSystem = 0x0D, - LocaleNumber_FractionalDigitsCount = 0x00000011, - LocaleNumber_NegativeNumberFormat = 0x00001010, - LocaleNumber_MonetaryFractionalDigitsCount = 0x00000019, - LocaleNumber_PositiveMonetaryNumberFormat = 0x0000001B, - LocaleNumber_NegativeMonetaryNumberFormat = 0x0000001C, - LocaleNumber_FirstDayofWeek = 0x0000100C, - LocaleNumber_FirstWeekOfYear = 0x0000100D, - LocaleNumber_ReadingLayout = 0x00000070, - LocaleNumber_NegativePercentFormat = 0x00000074, - LocaleNumber_PositivePercentFormat = 0x00000075, - LocaleNumber_Digit = 0x00000010, - LocaleNumber_Monetary = 0x00000018 -} LocaleNumberData; - -// Enum that corresponds to managed enum System.Globalization.CalendarWeekRule -typedef enum -{ - WeekRule_FirstDay = 0, - WeekRule_FirstFullWeek = 1, - WeekRule_FirstFourDayWeek = 2 -} CalendarWeekRule; PALEXPORT int32_t GlobalizationNative_GetLocaleInfoInt(const UChar* localeName, LocaleNumberData localeNumberData, int32_t* value); @@ -42,13 +15,4 @@ PALEXPORT int32_t GlobalizationNative_GetLocaleInfoGroupingSizes(const UChar* lo LocaleNumberData localeGroupingData, int32_t* primaryGroupSize, int32_t* secondaryGroupSize); -#if defined(APPLE_HYBRID_GLOBALIZATION) -PALEXPORT int32_t GlobalizationNative_GetLocaleInfoIntNative(const char* localeName, - LocaleNumberData localeNumberData); - -PALEXPORT int32_t GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative(const char* localeName, - LocaleNumberData localeGroupingData); -PALEXPORT int32_t GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative(const char* localeName, - LocaleNumberData localeGroupingData); -#endif diff --git a/src/native/libs/System.Globalization.Native/pal_localeStringData.h b/src/native/libs/System.Globalization.Native/pal_localeStringData.h index 957021dffa697..3652254663ca8 100644 --- a/src/native/libs/System.Globalization.Native/pal_localeStringData.h +++ b/src/native/libs/System.Globalization.Native/pal_localeStringData.h @@ -7,48 +7,8 @@ #include "pal_locale.h" #include "pal_compiler.h" -// Enum that corresponds to managed enum CultureData.LocaleStringData. -// The numeric values of the enum members match their Win32 counterparts. -typedef enum -{ - LocaleString_LocalizedDisplayName = 0x02, - LocaleString_EnglishDisplayName = 0x00000072, - LocaleString_NativeDisplayName = 0x00000073, - LocaleString_LocalizedLanguageName = 0x0000006f, - LocaleString_EnglishLanguageName = 0x00001001, - LocaleString_NativeLanguageName = 0x04, - LocaleString_EnglishCountryName = 0x00001002, - LocaleString_NativeCountryName = 0x08, - LocaleString_DecimalSeparator = 0x0E, - LocaleString_ThousandSeparator = 0x0F, - LocaleString_Digits = 0x00000013, - LocaleString_MonetarySymbol = 0x00000014, - LocaleString_CurrencyEnglishName = 0x00001007, - LocaleString_CurrencyNativeName = 0x00001008, - LocaleString_Iso4217MonetarySymbol = 0x00000015, - LocaleString_MonetaryDecimalSeparator = 0x00000016, - LocaleString_MonetaryThousandSeparator = 0x00000017, - LocaleString_AMDesignator = 0x00000028, - LocaleString_PMDesignator = 0x00000029, - LocaleString_PositiveSign = 0x00000050, - LocaleString_NegativeSign = 0x00000051, - LocaleString_Iso639LanguageTwoLetterName = 0x00000059, - LocaleString_Iso639LanguageThreeLetterName = 0x00000067, - LocaleString_Iso3166CountryName = 0x0000005A, - LocaleString_Iso3166CountryName2= 0x00000068, - LocaleString_NaNSymbol = 0x00000069, - LocaleString_PositiveInfinitySymbol = 0x0000006a, - LocaleString_NegativeInfinitySymbol = 0x0000006b, - LocaleString_ParentName = 0x0000006d, - LocaleString_PercentSymbol = 0x00000076, - LocaleString_PerMilleSymbol = 0x00000077 -} LocaleStringData; PALEXPORT int32_t GlobalizationNative_GetLocaleInfoString(const UChar* localeName, LocaleStringData localeStringData, UChar* value, int32_t valueLength, const UChar* uiLocaleName); -#if defined(APPLE_HYBRID_GLOBALIZATION) -PALEXPORT const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData, const char* currentUILocaleName); -#endif - diff --git a/src/native/libs/System.Globalization.Native/pal_locale_hg.h b/src/native/libs/System.Globalization.Native/pal_locale_hg.h new file mode 100644 index 0000000000000..99f35f9da244f --- /dev/null +++ b/src/native/libs/System.Globalization.Native/pal_locale_hg.h @@ -0,0 +1,55 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#pragma once + +#include "pal_compiler.h" +#include "pal_common.h" + +PALEXPORT int32_t GlobalizationNative_GetLocales(UChar *value, int32_t valueLength); + +PALEXPORT int32_t GlobalizationNative_GetLocaleName(const UChar* localeName, UChar* value, int32_t valueLength); + +PALEXPORT int32_t GlobalizationNative_GetDefaultLocaleName(UChar* value, int32_t valueLength); + +PALEXPORT int32_t GlobalizationNative_IsPredefinedLocale(const UChar* localeName); + +PALEXPORT int32_t GlobalizationNative_GetLocaleTimeFormat(const UChar* localeName, + int shortFormat, UChar* value, + int32_t valueLength); +PALEXPORT int32_t GlobalizationNative_GetLocaleInfoInt(const UChar* localeName, + LocaleNumberData localeNumberData, + int32_t* value); + +PALEXPORT int32_t GlobalizationNative_GetLocaleInfoGroupingSizes(const UChar* localeName, + LocaleNumberData localeGroupingData, + int32_t* primaryGroupSize, + int32_t* secondaryGroupSize); +PALEXPORT int32_t GlobalizationNative_GetLocaleInfoString(const UChar* localeName, + LocaleStringData localeStringData, + UChar* value, + int32_t valueLength, + const UChar* uiLocaleName); +#if defined(APPLE_HYBRID_GLOBALIZATION) +PALEXPORT const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData, const char* currentUILocaleName); + +PALEXPORT int32_t GlobalizationNative_GetLocaleInfoIntNative(const char* localeName, + LocaleNumberData localeNumberData); + +PALEXPORT int32_t GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative(const char* localeName, + LocaleNumberData localeGroupingData); + +PALEXPORT int32_t GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative(const char* localeName, + LocaleNumberData localeGroupingData); + +PALEXPORT const char* GlobalizationNative_GetDefaultLocaleNameNative(void); + +PALEXPORT const char* GlobalizationNative_GetLocaleNameNative(const char* localeName); + +PALEXPORT const char* GlobalizationNative_GetLocaleTimeFormatNative(const char* localeName, int shortFormat); + +PALEXPORT int32_t GlobalizationNative_GetLocalesNative(UChar* locales, int32_t length); + +PALEXPORT int32_t GlobalizationNative_IsPredefinedLocaleNative(const char* localeName); + +#endif diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale_hg.m similarity index 96% rename from src/native/libs/System.HybridGlobalization.Native/pal_locale.m rename to src/native/libs/System.Globalization.Native/pal_locale_hg.m index a1f63b99acb5c..181bd95b93d83 100644 --- a/src/native/libs/System.HybridGlobalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale_hg.m @@ -3,7 +3,9 @@ #include #include -#include "pal_locale_internal.h" +#include "pal_hybrid.h" +#include "pal_locale_hg.h" +// #include "pal_locale_internal.h" #include "pal_localeStringData.h" #include "pal_localeNumberData.h" @@ -14,28 +16,6 @@ #error This file relies on ARC for memory management, but ARC is not enabled. #endif -char* DetectDefaultAppleLocaleName(void) -{ - NSLocale *currentLocale = [NSLocale currentLocale]; - NSString *localeName = @""; - - if (!currentLocale) - { - return strdup([localeName UTF8String]); - } - - if ([currentLocale.languageCode length] > 0 && [currentLocale.countryCode length] > 0) - { - localeName = [NSString stringWithFormat:@"%@-%@", currentLocale.languageCode, currentLocale.countryCode]; - } - else - { - localeName = currentLocale.localeIdentifier; - } - - return strdup([localeName UTF8String]); -} - #if defined(APPLE_HYBRID_GLOBALIZATION) const char* GlobalizationNative_GetLocaleNameNative(const char* localeName) { @@ -765,26 +745,6 @@ int32_t GlobalizationNative_GetLocalesNative(UChar* value, int32_t length) } } -const char* GlobalizationNative_GetICUDataPathRelativeToAppBundleRoot(const char* path) -{ - @autoreleasepool - { - NSString *bundlePath = [[NSBundle mainBundle] bundlePath]; - NSString *dataPath = [bundlePath stringByAppendingPathComponent: [NSString stringWithFormat:@"%s", path]]; - - return strdup([dataPath UTF8String]); - } -} - -const char* GlobalizationNative_GetICUDataPathFallback(void) -{ - @autoreleasepool - { - NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"icudt" ofType:@"dat"]; - return strdup([dataPath UTF8String]); - } -} - const char* GlobalizationNative_GetDefaultLocaleNameNative(void) { @autoreleasepool diff --git a/src/native/libs/System.Globalization.Native/pal_locale_internal.h b/src/native/libs/System.Globalization.Native/pal_locale_internal.h index c754554bbfdd5..ddc0031a3ea19 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale_internal.h +++ b/src/native/libs/System.Globalization.Native/pal_locale_internal.h @@ -4,6 +4,7 @@ #pragma once #include "pal_icushim_internal.h" +#include "pal_common.h" /* Function: diff --git a/src/native/libs/System.Globalization.Native/pal_normalization.c b/src/native/libs/System.Globalization.Native/pal_normalization.c index f421e39809bd8..d5a5078139f9e 100644 --- a/src/native/libs/System.Globalization.Native/pal_normalization.c +++ b/src/native/libs/System.Globalization.Native/pal_normalization.c @@ -6,6 +6,7 @@ #include #include "pal_icushim_internal.h" +#include "pal_common.h" #include "pal_normalization.h" static const UNormalizer2* GetNormalizerForForm(NormalizationForm normalizationForm, UErrorCode* pErrorCode) diff --git a/src/native/libs/System.Globalization.Native/pal_normalization.h b/src/native/libs/System.Globalization.Native/pal_normalization.h index a05ac2005543e..fbaa1e7334297 100644 --- a/src/native/libs/System.Globalization.Native/pal_normalization.h +++ b/src/native/libs/System.Globalization.Native/pal_normalization.h @@ -7,16 +7,6 @@ #include "pal_locale.h" #include "pal_compiler.h" -/* - * These values should be kept in sync with System.Text.NormalizationForm - */ -typedef enum -{ - FormC = 0x1, - FormD = 0x2, - FormKC = 0x5, - FormKD = 0x6 -} NormalizationForm; PALEXPORT int32_t GlobalizationNative_IsNormalized(NormalizationForm normalizationForm, const UChar* lpStr, int32_t cwStrLength); @@ -26,14 +16,4 @@ PALEXPORT int32_t GlobalizationNative_NormalizeString(NormalizationForm normaliz int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength); -#if defined(APPLE_HYBRID_GLOBALIZATION) -PALEXPORT int32_t GlobalizationNative_IsNormalizedNative(NormalizationForm normalizationForm, - const uint16_t* lpStr, - int32_t cwStrLength); -PALEXPORT int32_t GlobalizationNative_NormalizeStringNative(NormalizationForm normalizationForm, - const uint16_t* lpSource, - int32_t cwSourceLength, - uint16_t* lpDst, - int32_t cwDstLength); -#endif diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_normalization.m b/src/native/libs/System.Globalization.Native/pal_normalization.m similarity index 97% rename from src/native/libs/System.HybridGlobalization.Native/pal_normalization.m rename to src/native/libs/System.Globalization.Native/pal_normalization.m index 35aa9fc63e618..b764debc5c103 100644 --- a/src/native/libs/System.HybridGlobalization.Native/pal_normalization.m +++ b/src/native/libs/System.Globalization.Native/pal_normalization.m @@ -3,8 +3,9 @@ // #include "pal_errors.h" -#include "pal_icushim_internal.h" -#include "pal_normalization.h" +#include "pal_common.h" +#include "pal_hybrid.h" +#include "pal_normalization_hg.h" #import #if !__has_feature(objc_arc) @@ -88,3 +89,4 @@ int32_t GlobalizationNative_NormalizeStringNative(NormalizationForm normalizatio } } #endif + diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_normalization.h b/src/native/libs/System.Globalization.Native/pal_normalization_hg.h similarity index 87% rename from src/native/libs/System.HybridGlobalization.Native/pal_normalization.h rename to src/native/libs/System.Globalization.Native/pal_normalization_hg.h index a05ac2005543e..2ecd338b11cb8 100644 --- a/src/native/libs/System.HybridGlobalization.Native/pal_normalization.h +++ b/src/native/libs/System.Globalization.Native/pal_normalization_hg.h @@ -4,19 +4,9 @@ #pragma once -#include "pal_locale.h" +#include "pal_locale_hg.h" #include "pal_compiler.h" -/* - * These values should be kept in sync with System.Text.NormalizationForm - */ -typedef enum -{ - FormC = 0x1, - FormD = 0x2, - FormKC = 0x5, - FormKD = 0x6 -} NormalizationForm; PALEXPORT int32_t GlobalizationNative_IsNormalized(NormalizationForm normalizationForm, const UChar* lpStr, int32_t cwStrLength); diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_placeholders.c b/src/native/libs/System.Globalization.Native/pal_placeholders.c similarity index 96% rename from src/native/libs/System.HybridGlobalization.Native/pal_placeholders.c rename to src/native/libs/System.Globalization.Native/pal_placeholders.c index 7d0f9624e082b..55afa062dbc9b 100644 --- a/src/native/libs/System.HybridGlobalization.Native/pal_placeholders.c +++ b/src/native/libs/System.Globalization.Native/pal_placeholders.c @@ -4,16 +4,14 @@ #include #include -#include "pal_icushim_internal.h" +#include "pal_common.h" #include "pal_icushim.h" -#include "pal_calendarData.h" -#include "pal_casing.h" -#include "pal_collation.h" -#include "pal_locale.h" -#include "pal_localeNumberData.h" -#include "pal_localeStringData.h" -#include "pal_normalization.h" -#include "pal_timeZoneInfo.h" +#include "pal_calendarData_hg.h" +#include "pal_casing_hg.h" +#include "pal_collation_hg.h" +#include "pal_locale_hg.h" +#include "pal_normalization_hg.h" +#include "pal_timeZoneInfo_hg.h" #ifdef DEBUG #define assert_err(cond, msg, err) do \ diff --git a/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.h b/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.h index bb32c41d43db9..79fd3c0b5487a 100644 --- a/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.h +++ b/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.h @@ -8,22 +8,6 @@ #include "pal_compiler.h" #include "pal_errors.h" -/* -These values should be kept in sync with the managed Interop.GlobalizationInterop.TimeZoneDisplayNameType enum. -*/ -typedef enum -{ - TimeZoneDisplayName_Generic = 0, - TimeZoneDisplayName_Standard = 1, - TimeZoneDisplayName_DaylightSavings = 2, - TimeZoneDisplayName_GenericLocation = 3, - TimeZoneDisplayName_ExemplarCity = 4, - TimeZoneDisplayName_TimeZoneName = 5, -} TimeZoneDisplayNameType; PALEXPORT int32_t GlobalizationNative_WindowsIdToIanaId(const UChar* windowsId, const char* region, UChar* ianaId, int32_t ianaIdLength); PALEXPORT int32_t GlobalizationNative_IanaIdToWindowsId(const UChar* ianaId, UChar* windowsId, int32_t windowsIdLength); PALEXPORT ResultCode GlobalizationNative_GetTimeZoneDisplayName(const UChar* localeName, const UChar* timeZoneId, TimeZoneDisplayNameType type, UChar* result, int32_t resultLength); -#if defined(APPLE_HYBRID_GLOBALIZATION) -PALEXPORT int32_t GlobalizationNative_GetTimeZoneDisplayNameNative(const uint16_t* localeName, int32_t lNameLength, const uint16_t* timeZoneId, int32_t timeZoneIdLength, - TimeZoneDisplayNameType type, uint16_t* result, int32_t resultLength); -#endif diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_timeZoneInfo.m b/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.m similarity index 97% rename from src/native/libs/System.HybridGlobalization.Native/pal_timeZoneInfo.m rename to src/native/libs/System.Globalization.Native/pal_timeZoneInfo.m index e5404e5cb0d4c..e0ccac384d35a 100644 --- a/src/native/libs/System.HybridGlobalization.Native/pal_timeZoneInfo.m +++ b/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.m @@ -3,8 +3,9 @@ // #include "pal_errors_internal.h" -#include "pal_icushim_internal.h" -#include "pal_timeZoneInfo.h" +#include "pal_common.h" +#include "pal_hybrid.h" +#include "pal_timeZoneInfo_hg.h" #import #if !__has_feature(objc_arc) diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_timeZoneInfo.h b/src/native/libs/System.Globalization.Native/pal_timeZoneInfo_hg.h similarity index 69% rename from src/native/libs/System.HybridGlobalization.Native/pal_timeZoneInfo.h rename to src/native/libs/System.Globalization.Native/pal_timeZoneInfo_hg.h index bb32c41d43db9..11490da482940 100644 --- a/src/native/libs/System.HybridGlobalization.Native/pal_timeZoneInfo.h +++ b/src/native/libs/System.Globalization.Native/pal_timeZoneInfo_hg.h @@ -4,22 +4,10 @@ #pragma once -#include "pal_locale.h" +#include "pal_locale_hg.h" #include "pal_compiler.h" #include "pal_errors.h" -/* -These values should be kept in sync with the managed Interop.GlobalizationInterop.TimeZoneDisplayNameType enum. -*/ -typedef enum -{ - TimeZoneDisplayName_Generic = 0, - TimeZoneDisplayName_Standard = 1, - TimeZoneDisplayName_DaylightSavings = 2, - TimeZoneDisplayName_GenericLocation = 3, - TimeZoneDisplayName_ExemplarCity = 4, - TimeZoneDisplayName_TimeZoneName = 5, -} TimeZoneDisplayNameType; PALEXPORT int32_t GlobalizationNative_WindowsIdToIanaId(const UChar* windowsId, const char* region, UChar* ianaId, int32_t ianaIdLength); PALEXPORT int32_t GlobalizationNative_IanaIdToWindowsId(const UChar* ianaId, UChar* windowsId, int32_t windowsIdLength); PALEXPORT ResultCode GlobalizationNative_GetTimeZoneDisplayName(const UChar* localeName, const UChar* timeZoneId, TimeZoneDisplayNameType type, UChar* result, int32_t resultLength); @@ -27,3 +15,4 @@ PALEXPORT ResultCode GlobalizationNative_GetTimeZoneDisplayName(const UChar* loc PALEXPORT int32_t GlobalizationNative_GetTimeZoneDisplayNameNative(const uint16_t* localeName, int32_t lNameLength, const uint16_t* timeZoneId, int32_t timeZoneIdLength, TimeZoneDisplayNameType type, uint16_t* result, int32_t resultLength); #endif + diff --git a/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt b/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt deleted file mode 100644 index 6e120902d9d82..0000000000000 --- a/src/native/libs/System.HybridGlobalization.Native/CMakeLists.txt +++ /dev/null @@ -1,187 +0,0 @@ -# Required for StaticICULinking -cmake_minimum_required(VERSION 3.10..3.20) - -project(System.HybridGlobalization.Native C) -if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) -if(CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_WASI) - # if (ANDROID_FORCE_ICU_DATA_DIR) - # add_definitions(-DANDROID_FORCE_ICU_DATA_DIR) - # endif() - - add_compile_options(-Wno-switch-enum) - add_compile_options(-Wno-covered-switch-default) - - # Workaround for warnings produced by ICU headers - add_compile_options(-Wno-reserved-id-macro) - add_compile_options(-Wno-documentation) - add_compile_options(-Wno-documentation-unknown-command) - add_compile_options(-Wno-reserved-identifier) - - # Workaround for https://unicode-org.atlassian.net/browse/ICU-20601 - add_compile_options(-Wno-extra-semi-stmt) - add_compile_options(-Wno-unknown-warning-option) - - # # The mobile configurations in particular bring their own ICU, so skip - # if (NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) - # if (CLR_CMAKE_TARGET_OSX) - # execute_process(COMMAND brew --prefix OUTPUT_VARIABLE brew_prefix OUTPUT_STRIP_TRAILING_WHITESPACE) - # set(ICU_HOMEBREW_INC_PATH "${brew_prefix}/opt/icu4c/include") - # endif() - - # find_path(UCURR_H "unicode/ucurr.h" PATHS ${ICU_HOMEBREW_INC_PATH}) - # if(UCURR_H STREQUAL UCURR_H-NOTFOUND) - # message(FATAL_ERROR "Cannot find ucurr.h, try installing libicu-dev (or the appropriate package for your platform)") - # return() - # endif() - - # if(CLR_CMAKE_TARGET_OSX) - # add_definitions(-DOSX_ICU_LIBRARY_PATH="/usr/lib/libicucore.dylib") - # add_definitions(-DU_DISABLE_RENAMING) - # else() - # find_library(ICUUC icuuc) - # if(ICUUC STREQUAL ICUUC-NOTFOUND) - # message(FATAL_ERROR "Cannot find libicuuc, try installing libicu-dev (or the appropriate package for your platform)") - # return() - # endif() - - # find_library(ICUI18N icui18n) - # if(ICUI18N STREQUAL ICUI18N-NOTFOUND) - # message(FATAL_ERROR "Cannot find libicui18n, try installing libicu-dev (or the appropriate package for your platform)") - # return() - # endif() - # endif() - - # include_directories(${UCURR_H}) - # endif() -endif() - -include(configure.cmake) - -set(NATIVEGLOBALIZATION_SOURCES - pal_idna.c - pal_common.c -) - -if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) - add_definitions(-DAPPLE_HYBRID_GLOBALIZATION) - set(NATIVEGLOBALIZATION_SOURCES - ${NATIVEGLOBALIZATION_SOURCES} - pal_placeholders.c - ) -endif() - -# if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) -# include_directories(${CMAKE_ICU_DIR}/include) -# link_libraries(${CMAKE_ICU_DIR}/lib/libicuuc.a ${CMAKE_ICU_DIR}/lib/libicui18n.a ${CMAKE_ICU_DIR}/lib/libicudata.a) -# link_libraries(stdc++) -# endif() - -if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) - link_libraries(icucore) -endif() - -if (CMAKE_USE_PTHREADS) - add_compile_options(-pthread) - add_linker_flag(-pthread) -endif() - -if (LOCAL_BUILD) - set(CMAKE_POSITION_INDEPENDENT_CODE ON) - set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_icushim_static.c) - add_definitions(-DLOCAL_BUILD) - add_definitions(-DSTATIC_ICU) - add_definitions(-DPALEXPORT=EXTERN_C) - add_definitions(-DTARGET_UNIX) - # For minipal files - include_directories(../../) - include_directories(${CMAKE_CURRENT_BINARY_DIR}) -elseif (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) - add_definitions(-DSTATIC_ICU) - set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_icushim_static.c) -else() - set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_icushim.c) -endif() - -if (CLR_CMAKE_TARGET_APPLE) - set(NATIVEGLOBALIZATION_SOURCES_OBJC - pal_locale.m - pal_collation.m - pal_casing.m - pal_calendarData.m - pal_normalization.m - pal_timeZoneInfo.m) - set_source_files_properties(${NATIVEGLOBALIZATION_SOURCES_OBJC} PROPERTIES COMPILE_FLAGS "-fobjc-arc ${CLR_CMAKE_COMMON_OBJC_FLAGS}") - set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} ${NATIVEGLOBALIZATION_SOURCES_OBJC}) -endif() - -if (MSVC) - set_source_files_properties(${NATIVEGLOBALIZATION_SOURCES} PROPERTIES LANGUAGE CXX) -endif() - -include_directories("../Common") - -if (GEN_SHARED_LIB) - if (CLR_CMAKE_TARGET_APPLE) - include(CMakeFindFrameworks) - find_library(FOUNDATION Foundation REQUIRED) - endif() - - add_library(System.HybridGlobalization.Native - SHARED - ${NATIVEGLOBALIZATION_SOURCES} - ${VERSION_FILE_PATH} - ) - - target_link_libraries(System.HybridGlobalization.Native - PRIVATE - ${CMAKE_DL_LIBS} - ${FOUNDATION} - ) - - install_with_stripped_symbols (System.HybridGlobalization.Native PROGRAMS .) -endif() - -add_library(System.HybridGlobalization.Native-Static - STATIC - ${NATIVEGLOBALIZATION_SOURCES} - entrypoints.c -) - -if(CLR_CMAKE_TARGET_UNIX) - set_target_properties(System.HybridGlobalization.Native-Static PROPERTIES OUTPUT_NAME System.HybridGlobalization.Native CLEAN_DIRECT_OUTPUT 1) -endif() - -install (TARGETS System.HybridGlobalization.Native-Static DESTINATION ${STATIC_LIB_DESTINATION} COMPONENT libs) - -# if(NOT CLR_CMAKE_TARGET_APPLE AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_LINUX_MUSL AND NOT CLR_CMAKE_TARGET_HAIKU) -# if (GEN_SHARED_LIB) -# add_custom_command(TARGET System.HybridGlobalization.Native POST_BUILD -# COMMENT "Verifying System.HybridGlobalization.Native.so dependencies" -# COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../verify-so.sh -# $ -# "Verification failed. System.HybridGlobalization.Native.so has undefined dependencies. These are likely ICU APIs that need to be added to icushim.h." -# VERBATIM -# ) -# endif() -# endif() - -if(CLR_CMAKE_TARGET_WIN32) - if(STATIC_LIBS_ONLY) - add_library(System.HybridGlobalization.Native.Aot - STATIC - ${NATIVEGLOBALIZATION_SOURCES} - ) - set_target_properties(System.HybridGlobalization.Native.Aot PROPERTIES CLR_CONTROL_FLOW_GUARD OFF) - set_target_properties(System.HybridGlobalization.Native.Aot PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) - - add_library(System.HybridGlobalization.Native.Aot.GuardCF - STATIC - ${NATIVEGLOBALIZATION_SOURCES} - ) - set_target_properties(System.HybridGlobalization.Native.Aot.GuardCF PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) - - install_static_library(System.HybridGlobalization.Native.Aot aotsdk nativeaot) - install_static_library(System.HybridGlobalization.Native.Aot.GuardCF aotsdk nativeaot) - endif() -endif() -endif() diff --git a/src/native/libs/System.HybridGlobalization.Native/config.h.in b/src/native/libs/System.HybridGlobalization.Native/config.h.in deleted file mode 100644 index 8f4e659b5aa5d..0000000000000 --- a/src/native/libs/System.HybridGlobalization.Native/config.h.in +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#cmakedefine01 HAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS -#cmakedefine01 HAVE_SET_MAX_VARIABLE -#cmakedefine01 HAVE_UCOL_CLONE diff --git a/src/native/libs/System.HybridGlobalization.Native/configure.cmake b/src/native/libs/System.HybridGlobalization.Native/configure.cmake deleted file mode 100644 index 0042d275003c2..0000000000000 --- a/src/native/libs/System.HybridGlobalization.Native/configure.cmake +++ /dev/null @@ -1,37 +0,0 @@ -if(CLR_CMAKE_TARGET_ANDROID OR CLR_CMAKE_TARGET_APPLE OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) - set(HAVE_SET_MAX_VARIABLE 1) - set(HAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS 1) - set(HAVE_UCOL_CLONE 0) -else() - include(CheckCSourceCompiles) - include(CheckSymbolExists) - - if (CLR_CMAKE_TARGET_UNIX) - set(CMAKE_REQUIRED_INCLUDES ${UCURR_H} ${ICU_HOMEBREW_INC_PATH}) - - CHECK_C_SOURCE_COMPILES(" - #include - int main(void) { enum UDateFormatSymbolType e = UDAT_STANDALONE_SHORTER_WEEKDAYS; } - " HAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS) - - set(CMAKE_REQUIRED_LIBRARIES ${ICUUC} ${ICUI18N}) - - check_symbol_exists( - ucol_setMaxVariable - "unicode/ucol.h" - HAVE_SET_MAX_VARIABLE) - - check_symbol_exists( - ucol_clone - "unicode/ucol.h" - HAVE_UCOL_CLONE) - - unset(CMAKE_REQUIRED_LIBRARIES) - unset(CMAKE_REQUIRED_INCLUDES) - endif() -endif() - -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in - ${CMAKE_CURRENT_BINARY_DIR}/config.h) - diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_common.c b/src/native/libs/System.HybridGlobalization.Native/pal_common.c deleted file mode 100644 index 5904a1c3bdbe2..0000000000000 --- a/src/native/libs/System.HybridGlobalization.Native/pal_common.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include "pal_icushim_internal.h" -#include "pal_casing.h" - -void GlobalizationNative_InitOrdinalCasingPage(int32_t pageNumber, UChar* pTarget) -{ - pageNumber <<= 8; - for (int i = 0; i < 256; i++) - { - // Unfortunately, to ensure one-to-one simple mapping we have to call u_toupper on every character. - // Using string casing ICU APIs cannot give such results even when using NULL locale to force root behavior. - pTarget[i] = (UChar) u_toupper((UChar32)(pageNumber + i)); - } - - if (pageNumber == 0x0100) - { - // Disable Turkish I behavior on Ordinal operations - pTarget[0x31] = (UChar)0x0131; // Turkish lowercase i - pTarget[0x7F] = (UChar)0x017F; // // 017F;LATIN SMALL LETTER LONG S - } -} diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_errors.h b/src/native/libs/System.HybridGlobalization.Native/pal_errors.h deleted file mode 100644 index 84fe004902ee4..0000000000000 --- a/src/native/libs/System.HybridGlobalization.Native/pal_errors.h +++ /dev/null @@ -1,17 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#pragma once - -/* -* These values should be kept in sync with -* Interop.GlobalizationInterop.ResultCode -*/ -typedef enum -{ - Success = 0, - UnknownError = 1, - InsufficientBuffer = 2, - OutOfMemory = 3, - InvalidCodePoint = 4 -} ResultCode; diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_errors_internal.h b/src/native/libs/System.HybridGlobalization.Native/pal_errors_internal.h deleted file mode 100644 index 1680335834736..0000000000000 --- a/src/native/libs/System.HybridGlobalization.Native/pal_errors_internal.h +++ /dev/null @@ -1,30 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#pragma once - -#include "pal_icushim_internal.h" -#include "pal_errors.h" - -/* -Converts a UErrorCode to a ResultCode. -*/ -static ResultCode GetResultCode(UErrorCode err) -{ - if (err == U_BUFFER_OVERFLOW_ERROR || err == U_STRING_NOT_TERMINATED_WARNING) - { - return InsufficientBuffer; - } - - if (err == U_MEMORY_ALLOCATION_ERROR) - { - return OutOfMemory; - } - - if (U_SUCCESS(err)) - { - return Success; - } - - return UnknownError; -} diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_icushim.c b/src/native/libs/System.HybridGlobalization.Native/pal_icushim.c deleted file mode 100644 index 11b4ea6b748b3..0000000000000 --- a/src/native/libs/System.HybridGlobalization.Native/pal_icushim.c +++ /dev/null @@ -1,575 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// - -#include -#include -#include "pal_icushim_internal.h" - -#if defined(TARGET_UNIX) -#include -#elif defined(TARGET_WINDOWS) -#include -#include -#include -#endif -#include -#include -#include - -#include "pal_icushim.h" - -// Define pointers to all the used ICU functions -#define PER_FUNCTION_BLOCK(fn, lib, required) TYPEOF(fn)* fn##_ptr; -FOR_ALL_ICU_FUNCTIONS -#undef PER_FUNCTION_BLOCK - -// 35 for the actual suffix, 1 for _ and 1 for '\0' -#define SYMBOL_CUSTOM_SUFFIX_SIZE 37 -#define SYMBOL_NAME_SIZE (128 + SYMBOL_CUSTOM_SUFFIX_SIZE) -#define MaxICUVersionStringWithSuffixLength (MaxICUVersionStringLength + SYMBOL_CUSTOM_SUFFIX_SIZE) - -#if defined(TARGET_WINDOWS) || defined(TARGET_OSX) || defined(TARGET_ANDROID) - -#define MaxICUVersionStringLength 33 - -#else - -#define VERSION_PREFIX_NONE "" -#define VERSION_PREFIX_SUSE "suse" - -// .[suse]x.x.x, considering the max number of decimal digits for each component -#define MaxICUVersionStringLength (sizeof(VERSION_PREFIX_SUSE) + 33) - -#endif - -static void* libicuuc = NULL; -static void* libicui18n = NULL; -ucol_setVariableTop_func ucol_setVariableTop_ptr = NULL; -ucol_safeClone_func ucol_safeClone_ptr = NULL; - -#if defined (TARGET_UNIX) - -#define PER_FUNCTION_BLOCK(fn, lib, required) \ - c_static_assert_msg((sizeof(#fn) + MaxICUVersionStringWithSuffixLength + 1) <= sizeof(symbolName), "The symbolName is too small for symbol " #fn); \ - snprintf(symbolName, SYMBOL_NAME_SIZE, #fn "%s", symbolVersion); \ - fn##_ptr = (TYPEOF(fn)*)dlsym(lib, symbolName); \ - if (fn##_ptr == NULL && required) { fprintf(stderr, "Cannot get symbol %s from " #lib "\nError: %s\n", symbolName, dlerror()); abort(); } - -static int FindSymbolVersion(int majorVer, int minorVer, int subVer, char* symbolName, char* symbolVersion, size_t symbolVersionLen, char* suffix) -{ - // Find out the format of the version string added to each symbol - // First try just the unversioned symbol - if (dlsym(libicuuc, "u_strlen") == NULL) - { - // Now try just the _majorVer added - snprintf(symbolVersion, symbolVersionLen, "_%d%s", majorVer, suffix); - snprintf(symbolName, SYMBOL_NAME_SIZE, "u_strlen%s", symbolVersion); - if (dlsym(libicuuc, symbolName) == NULL) - { - if (minorVer == -1) - return false; - - // Now try the _majorVer_minorVer added - snprintf(symbolVersion, symbolVersionLen, "_%d_%d%s", majorVer, minorVer, suffix); - snprintf(symbolName, SYMBOL_NAME_SIZE, "u_strlen%s", symbolVersion); - if (dlsym(libicuuc, symbolName) == NULL) - { - if (subVer == -1) - return false; - - // Finally, try the _majorVer_minorVer_subVer added - snprintf(symbolVersion, symbolVersionLen, "_%d_%d_%d%s", majorVer, minorVer, subVer, suffix); - snprintf(symbolName, SYMBOL_NAME_SIZE, "u_strlen%s", symbolVersion); - if (dlsym(libicuuc, symbolName) == NULL) - { - return false; - } - } - } - } - - return true; -} - -#endif // TARGET_UNIX - -#if defined(TARGET_WINDOWS) - -#define sscanf sscanf_s - -#define PER_FUNCTION_BLOCK(fn, lib, required) \ - sprintf_s(symbolName, SYMBOL_NAME_SIZE, #fn "%s", symbolVersion); \ - fn##_ptr = (TYPEOF(fn)*)GetProcAddress((HMODULE)lib, symbolName); \ - if (fn##_ptr == NULL && required) { fprintf(stderr, "Cannot get symbol %s from " #lib "\nError: %u\n", symbolName, GetLastError()); abort(); } - -static int FindICULibs(void) -{ - libicuuc = LoadLibraryExW(L"icu.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); - if (libicuuc == NULL) - { - // On Windows Server 2019, the ICU library is installed as icuuc.dll and icuin.dll. Try to load these. - libicuuc = LoadLibraryExW(L"icuuc.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); - if (libicuuc != NULL) - { - libicui18n = LoadLibraryExW(L"icuin.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); - if (libicui18n != NULL) - { - return true; - } - } - - return false; - } - - // Windows has a single dll for icu. - libicui18n = libicuuc; - return true; -} - -static int FindSymbolVersion(int majorVer, int minorVer, int subVer, char* symbolName, char* symbolVersion, size_t symbolVersionLen, char* suffix) -{ - HMODULE lib = (HMODULE)libicuuc; - // Find out the format of the version string added to each symbol - // First try just the unversioned symbol - if (GetProcAddress(lib, "u_strlen") == NULL) - { - // Now try just the _majorVer added - sprintf_s(symbolVersion, symbolVersionLen,"_%d%s", majorVer, suffix); - sprintf_s(symbolName, SYMBOL_NAME_SIZE, "u_strlen%s", symbolVersion); - if (GetProcAddress(lib, symbolName) == NULL) - { - if (minorVer == -1) - return false; - - // Now try the _majorVer_minorVer added - sprintf_s(symbolVersion, symbolVersionLen, "_%d_%d%s", majorVer, minorVer, suffix); - sprintf_s(symbolName, SYMBOL_NAME_SIZE, "u_strlen%s", symbolVersion); - if (GetProcAddress(lib, symbolName) == NULL) - { - if (subVer == -1) - return false; - // Finally, try the _majorVer_minorVer_subVer added - sprintf_s(symbolVersion, symbolVersionLen, "_%d_%d_%d%s", majorVer, minorVer, subVer, suffix); - sprintf_s(symbolName, SYMBOL_NAME_SIZE, "u_strlen%s", symbolVersion); - if (GetProcAddress(lib, symbolName) == NULL) - { - return false; - } - } - } - } - - return true; -} - -#elif defined(TARGET_OSX) - -static int FindICULibs(void) -{ -#ifndef OSX_ICU_LIBRARY_PATH - c_static_assert_msg(false, "The ICU Library path is not defined"); -#endif // OSX_ICU_LIBRARY_PATH - - // Usually OSX_ICU_LIBRARY_PATH is "/usr/lib/libicucore.dylib" - libicuuc = dlopen(OSX_ICU_LIBRARY_PATH, RTLD_LAZY); - - if (libicuuc == NULL) - { - return false; - } - - // in OSX all ICU APIs exist in the same library libicucore.A.dylib - libicui18n = libicuuc; - - return true; -} - -#elif defined(TARGET_ANDROID) - -// support ICU versions from 50-255 -#define MinICUVersion 50 -#define MaxICUVersion 255 - -static int FindICULibs(char* symbolName, char* symbolVersion) -{ - libicui18n = dlopen("libicui18n.so", RTLD_LAZY); - - if (libicui18n == NULL) - { - return false; - } - - libicuuc = dlopen("libicuuc.so", RTLD_LAZY); - - if (libicuuc == NULL) - { - return false; - } - - char symbolSuffix[SYMBOL_CUSTOM_SUFFIX_SIZE]=""; - for (int i = MinICUVersion; i <= MaxICUVersion; i++) - { - if (FindSymbolVersion(i, -1, -1, symbolName, symbolVersion, MaxICUVersionStringLength, symbolSuffix)) - { - return true; - } - } - - fprintf(stderr, "Cannot determine ICU version."); - return false; -} - -#else // !TARGET_WINDOWS && !TARGET_OSX && !TARGET_ANDROID - -// Version ranges to search for each of the three version components -// The rationale for major version range is that we support versions higher or -// equal to the version we are built against and less or equal to that version -// plus 30 to give us enough headspace. The ICU seems to version about twice -// a year. -// On some platforms (mainly Alpine Linux) we want to make our minimum version -// an earlier version than what we build that we know we support. -#define MinICUVersion 50 -#define MaxICUVersion (U_ICU_VERSION_MAJOR_NUM + 30) -#define MinMinorICUVersion 1 -#define MaxMinorICUVersion 5 -#define MinSubICUVersion 1 -#define MaxSubICUVersion 5 - -#define VERSIONED_LIB_NAME_LEN 64 - -// Get filename of an ICU library with the requested version in the name -// There are three possible cases of the version components values: -// 1. Only majorVer is not equal to -1 => result is baseFileName.majorver -// 2. Only majorVer and minorVer are not equal to -1 => result is baseFileName.majorver.minorVer -// 3. All components are not equal to -1 => result is baseFileName.majorver.minorVer.subver -static void GetVersionedLibFileName(const char* baseFileName, int majorVer, int minorVer, int subVer, const char* versionPrefix, char* result) -{ - assert(majorVer != -1); - - int nameLen = snprintf(result, VERSIONED_LIB_NAME_LEN, "%s.%s%d", baseFileName, versionPrefix, majorVer); - - if (minorVer != -1) - { - assert(nameLen <= VERSIONED_LIB_NAME_LEN); - nameLen += snprintf(result + nameLen, (size_t)(VERSIONED_LIB_NAME_LEN - nameLen), ".%d", minorVer); - if (subVer != -1) - { - assert(nameLen <= VERSIONED_LIB_NAME_LEN); - snprintf(result + nameLen, (size_t)(VERSIONED_LIB_NAME_LEN - nameLen), ".%d", subVer); - } - } -} - -// Try to open the necessary ICU libraries -static int OpenICULibraries(int majorVer, int minorVer, int subVer, const char* versionPrefix, char* symbolName, char* symbolVersion) -{ - char libicuucName[VERSIONED_LIB_NAME_LEN]; - char libicui18nName[VERSIONED_LIB_NAME_LEN]; - - c_static_assert_msg(sizeof("libicuuc.so") + MaxICUVersionStringLength <= sizeof(libicuucName), "The libicuucName is too small"); - GetVersionedLibFileName("libicuuc.so", majorVer, minorVer, subVer, versionPrefix, libicuucName); - - c_static_assert_msg(sizeof("libicui18n.so") + MaxICUVersionStringLength <= sizeof(libicui18nName), "The libicui18nName is too small"); - GetVersionedLibFileName("libicui18n.so", majorVer, minorVer, subVer, versionPrefix, libicui18nName); - - libicuuc = dlopen(libicuucName, RTLD_LAZY); - if (libicuuc != NULL) - { - char symbolSuffix[SYMBOL_CUSTOM_SUFFIX_SIZE]=""; - if (FindSymbolVersion(majorVer, minorVer, subVer, symbolName, symbolVersion, MaxICUVersionStringLength, symbolSuffix)) - { - libicui18n = dlopen(libicui18nName, RTLD_LAZY); - } - if (libicui18n == NULL) - { - dlclose(libicuuc); - libicuuc = NULL; - } - } - - return libicuuc != NULL; -} - -// Select libraries using the version override specified by the CLR_ICU_VERSION_OVERRIDE -// environment variable. -// The format of the string in this variable is majorVer[.minorVer[.subVer]] (the brackets -// indicate optional parts). -static int FindLibUsingOverride(const char* versionPrefix, char* symbolName, char* symbolVersion) -{ - char* versionOverride = getenv("CLR_ICU_VERSION_OVERRIDE"); - if (versionOverride != NULL) - { - if (strcmp(versionOverride, "build") == 0) - { - if (OpenICULibraries(U_ICU_VERSION_MAJOR_NUM, -1, -1, versionPrefix, symbolName, symbolVersion)) - { - return true; - } - } - else - { - int first = -1; - int second = -1; - int third = -1; - - int matches = sscanf(versionOverride, "%d.%d.%d", &first, &second, &third); - if (matches > 0) - { - if (OpenICULibraries(first, second, third, versionPrefix, symbolName, symbolVersion)) - { - return true; - } - } - } - } - - return false; -} - -// Search for library files with names including the major version. -static int FindLibWithMajorVersion(const char* versionPrefix, char* symbolName, char* symbolVersion) -{ - // ICU packaging documentation (http://userguide.icu-project.org/packaging) - // describes applications link against the major (e.g. libicuuc.so.54). - - // Select the highest supported version of ICU present on the local machine - for (int i = MaxICUVersion; i >= MinICUVersion; i--) - { - if (OpenICULibraries(i, -1, -1, versionPrefix, symbolName, symbolVersion)) - { - return true; - } - } - - return false; -} - -// Select the highest supported version of ICU present on the local machine -// Search for library files with names including the major and minor version. -static int FindLibWithMajorMinorVersion(const char* versionPrefix, char* symbolName, char* symbolVersion) -{ - for (int i = MaxICUVersion; i >= MinICUVersion; i--) - { - for (int j = MaxMinorICUVersion; j >= MinMinorICUVersion; j--) - { - if (OpenICULibraries(i, j, -1, versionPrefix, symbolName, symbolVersion)) - { - return true; - } - } - } - - return false; -} - -// Select the highest supported version of ICU present on the local machine -// Search for library files with names including the major, minor and sub version. -static int FindLibWithMajorMinorSubVersion(const char* versionPrefix, char* symbolName, char* symbolVersion) -{ - for (int i = MaxICUVersion; i >= MinICUVersion; i--) - { - for (int j = MaxMinorICUVersion; j >= MinMinorICUVersion; j--) - { - for (int k = MaxSubICUVersion; k >= MinSubICUVersion; k--) - { - if (OpenICULibraries(i, j, k, versionPrefix, symbolName, symbolVersion)) - { - return true; - } - } - } - } - - return false; -} - - -static int FindICULibs(const char* versionPrefix, char* symbolName, char* symbolVersion) -{ - return FindLibUsingOverride(versionPrefix, symbolName, symbolVersion) || - FindLibWithMajorVersion(versionPrefix, symbolName, symbolVersion) || - FindLibWithMajorMinorVersion(versionPrefix, symbolName, symbolVersion) || - FindLibWithMajorMinorSubVersion(versionPrefix, symbolName, symbolVersion); -} - -#endif - -static void ValidateICUDataCanLoad(void) -{ - UVersionInfo version; - UErrorCode err = U_ZERO_ERROR; - ulocdata_getCLDRVersion(version, &err); - - if (U_FAILURE(err)) - { - fprintf(stderr, "Could not load ICU data. UErrorCode: %d\n", err); - abort(); - } -} - -static void InitializeUColClonePointers(char* symbolVersion) -{ - if (ucol_clone_ptr != NULL) - { - return; - } - -#if defined(TARGET_WINDOWS) - char symbolName[SYMBOL_NAME_SIZE]; - sprintf_s(symbolName, SYMBOL_NAME_SIZE, "ucol_safeClone%s", symbolVersion); - ucol_safeClone_ptr = (ucol_safeClone_func)GetProcAddress((HMODULE)libicui18n, symbolName); -#else - char symbolName[SYMBOL_NAME_SIZE]; - snprintf(symbolName, SYMBOL_NAME_SIZE, "ucol_safeClone%s", symbolVersion); - ucol_safeClone_ptr = (ucol_safeClone_func)dlsym(libicui18n, symbolName); -#endif // defined(TARGET_WINDOWS) - - if (ucol_safeClone_ptr == NULL) - { - fprintf(stderr, "Cannot get the symbols of ICU APIs ucol_safeClone or ucol_clone.\n"); - abort(); - } -} - -static void InitializeVariableMaxAndTopPointers(char* symbolVersion) -{ - if (ucol_setMaxVariable_ptr != NULL) - { - return; - } - -#if defined(TARGET_OSX) || defined(TARGET_ANDROID) - // OSX and Android always run against ICU version which has ucol_setMaxVariable. - // We shouldn't come here. - (void)symbolVersion; - assert(false); -#elif defined(TARGET_WINDOWS) - char symbolName[SYMBOL_NAME_SIZE]; - sprintf_s(symbolName, SYMBOL_NAME_SIZE, "ucol_setVariableTop%s", symbolVersion); - ucol_setVariableTop_ptr = (ucol_setVariableTop_func)GetProcAddress((HMODULE)libicui18n, symbolName); -#else - char symbolName[SYMBOL_NAME_SIZE]; - snprintf(symbolName, SYMBOL_NAME_SIZE, "ucol_setVariableTop%s", symbolVersion); - ucol_setVariableTop_ptr = (ucol_setVariableTop_func)dlsym(libicui18n, symbolName); -#endif // defined(TARGET_OSX) || defined(TARGET_ANDROID) - - if (ucol_setVariableTop_ptr == NULL) - { - fprintf(stderr, "Cannot get the symbols of ICU APIs ucol_setMaxVariable or ucol_setVariableTop.\n"); - abort(); - } -} - -// GlobalizationNative_LoadICU -// This method get called from the managed side during the globalization initialization. -// This method shouldn't get called at all if we are running in globalization invariant mode -// return 0 if failed to load ICU and 1 otherwise -int32_t GlobalizationNative_LoadICU(void) -{ - char symbolName[SYMBOL_NAME_SIZE]; - char symbolVersion[MaxICUVersionStringLength + 1]=""; - -#if defined(TARGET_WINDOWS) || defined(TARGET_OSX) - - if (!FindICULibs()) - { - return false; - } - -#elif defined(TARGET_ANDROID) - if (!FindICULibs(symbolName, symbolVersion)) - { - return false; - } -#else - if (!FindICULibs(VERSION_PREFIX_NONE, symbolName, symbolVersion)) - { - if (!FindICULibs(VERSION_PREFIX_SUSE, symbolName, symbolVersion)) - { - return false; - } - } -#endif // TARGET_WINDOWS || TARGET_OSX - -#if defined(ANDROID_FORCE_ICU_DATA_DIR) - setenv ("ICU_DATA", "/system/usr/icu/", 0); -#endif - FOR_ALL_ICU_FUNCTIONS - ValidateICUDataCanLoad(); - - InitializeVariableMaxAndTopPointers(symbolVersion); - InitializeUColClonePointers(symbolVersion); - - return true; -} - -void GlobalizationNative_InitICUFunctions(void* icuuc, void* icuin, const char* version, const char* suffix) -{ - assert(icuuc != NULL); - assert(icuin != NULL); - assert(version != NULL); - - libicuuc = icuuc; - libicui18n = icuin; - int major = -1; - int minor = -1; - int build = -1; - - char symbolName[SYMBOL_NAME_SIZE]; - char symbolVersion[MaxICUVersionStringWithSuffixLength + 1]=""; - char symbolSuffix[SYMBOL_CUSTOM_SUFFIX_SIZE]=""; - - if (strlen(version) > (size_t)MaxICUVersionStringLength) - { - fprintf(stderr, "The resolved version \"%s\" from System.Globalization.AppLocalIcu switch has to be < %zu chars long.\n", version, (size_t)MaxICUVersionStringLength); - abort(); - } - - sscanf(version, "%d.%d.%d", &major, &minor, &build); - - if (suffix != NULL) - { - size_t suffixAllowedSize = SYMBOL_CUSTOM_SUFFIX_SIZE - 2; // SYMBOL_CUSTOM_SUFFIX_SIZE considers `_` and `\0`. - if (strlen(suffix) > suffixAllowedSize) - { - fprintf(stderr, "The resolved suffix \"%s\" from System.Globalization.AppLocalIcu switch has to be < %zu chars long.\n", suffix, suffixAllowedSize); - abort(); - } - - assert(strlen(suffix) + 1 <= SYMBOL_CUSTOM_SUFFIX_SIZE); - -#if defined(TARGET_WINDOWS) - sprintf_s(symbolSuffix, SYMBOL_CUSTOM_SUFFIX_SIZE, "_%s", suffix); -#else - snprintf(symbolSuffix, SYMBOL_CUSTOM_SUFFIX_SIZE, "_%s", suffix); -#endif - } - - if(!FindSymbolVersion(major, minor, build, symbolName, symbolVersion, MaxICUVersionStringWithSuffixLength, symbolSuffix)) - { - fprintf(stderr, "Could not find symbol: %s from libicuuc\n", symbolName); - abort(); - } - - FOR_ALL_ICU_FUNCTIONS - ValidateICUDataCanLoad(); - - InitializeVariableMaxAndTopPointers(symbolVersion); - InitializeUColClonePointers(symbolVersion); -} - -#undef PER_FUNCTION_BLOCK - -// GlobalizationNative_GetICUVersion -// return the current loaded ICU version -int32_t GlobalizationNative_GetICUVersion(void) -{ - if (u_getVersion_ptr == NULL) - return 0; - - UVersionInfo versionInfo; - u_getVersion(versionInfo); - - return (versionInfo[0] << 24) + (versionInfo[1] << 16) + (versionInfo[2] << 8) + versionInfo[3]; -} diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_icushim.h b/src/native/libs/System.HybridGlobalization.Native/pal_icushim.h deleted file mode 100644 index ec4dea95dc119..0000000000000 --- a/src/native/libs/System.HybridGlobalization.Native/pal_icushim.h +++ /dev/null @@ -1,16 +0,0 @@ - -#pragma once - -#include "pal_compiler.h" - -PALEXPORT int32_t GlobalizationNative_LoadICU(void); - -PALEXPORT void GlobalizationNative_InitICUFunctions(void* icuuc, void* icuin, const char* version, const char* suffix); - -PALEXPORT int32_t GlobalizationNative_GetICUVersion(void); - -#if defined(STATIC_ICU) - -PALEXPORT int32_t GlobalizationNative_LoadICUData(const char* path); - -#endif diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_icushim_internal.h b/src/native/libs/System.HybridGlobalization.Native/pal_icushim_internal.h deleted file mode 100644 index a7bad69cef319..0000000000000 --- a/src/native/libs/System.HybridGlobalization.Native/pal_icushim_internal.h +++ /dev/null @@ -1,386 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// - -// Enable calling ICU functions through shims to enable support for -// multiple versions of ICU. - -#pragma once - -#if defined(TARGET_UNIX) || defined(TARGET_WASI) - -#include "config.h" - -#if defined(TARGET_ANDROID) -#include "pal_icushim_internal_android.h" -#else - -#if !defined(LOCAL_BUILD) -#define U_DISABLE_RENAMING 1 -#endif - -// All ICU headers need to be included here so that all function prototypes are -// available before the function pointers are declared below. -#if defined(APPLE_HYBRID_GLOBALIZATION) -#include -#include -#include -#else -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif -#endif - -#elif defined(TARGET_WINDOWS) - -#include "icu.h" - -#define HAVE_SET_MAX_VARIABLE 1 -#define UDAT_STANDALONE_SHORTER_WEEKDAYS 1 - -#endif - -#include "pal_compiler.h" - -#if !defined(STATIC_ICU) - -#if !defined(TARGET_ANDROID) -// (U_ICU_VERSION_MAJOR_NUM < 52) -// The following APIs are not supported in the ICU versions less than 52. We need to define them manually. -// We have to do runtime check before using the pointers to these APIs. That is why these are listed in the FOR_ALL_OPTIONAL_ICU_FUNCTIONS list. -U_CAPI void U_EXPORT2 ucol_setMaxVariable(UCollator* coll, UColReorderCode group, UErrorCode* pErrorCode); -U_CAPI int32_t U_EXPORT2 ucal_getTimeZoneIDForWindowsID(const UChar* winid, int32_t len, const char* region, UChar* id, int32_t idCapacity, UErrorCode* status); -U_CAPI int32_t U_EXPORT2 ucal_getWindowsTimeZoneID(const UChar* id, int32_t len, UChar* winid, int32_t winidCapacity, UErrorCode* status); - -// (U_ICU_VERSION_MAJOR_NUM < 71) -// The following API is not supported in the ICU versions less than 71. We need to define it manually. -// We have to do runtime check before using the pointers to this API. That is why these are listed in the FOR_ALL_OPTIONAL_ICU_FUNCTIONS list. -U_CAPI UCollator* U_EXPORT2 ucol_clone(const UCollator* coll, UErrorCode* status); - -// ucol_setVariableTop is a deprecated function on the newer ICU versions and ucol_setMaxVariable should be used instead. -// As we can run against ICU versions which do not support ucol_setMaxVariable, we will dynamically try to get the pointer -// to ucol_setVariableTop when we could not get a pointer to ucol_setMaxVariable. -typedef uint32_t (U_EXPORT2 *ucol_setVariableTop_func)(UCollator* coll, const UChar* varTop, int32_t len, UErrorCode* status); - -// ucol_safeClone is deprecated in ICU version 71. We have to handle it manually to avoid getting a build break when referencing it in the code. -typedef UCollator* (U_EXPORT2 *ucol_safeClone_func)(const UCollator* coll, void* stackBuffer, int32_t* pBufferSize, UErrorCode* status); - -#else // !defined(TARGET_ANDROID) - -typedef uint32_t (*ucol_setVariableTop_func)(UCollator* coll, const UChar* varTop, int32_t len, UErrorCode* status); -typedef UCollator* (*ucol_safeClone_func)(const UCollator* coll, void* stackBuffer, int32_t* pBufferSize, UErrorCode* status); - -#endif // !defined(TARGET_ANDROID) - -extern ucol_setVariableTop_func ucol_setVariableTop_ptr; -extern ucol_safeClone_func ucol_safeClone_ptr; - -// List of all functions from the ICU libraries that are used in the System.Globalization.Native.so -#define FOR_ALL_UNCONDITIONAL_ICU_FUNCTIONS \ - PER_FUNCTION_BLOCK(u_charsToUChars, libicuuc, true) \ - PER_FUNCTION_BLOCK(u_getVersion, libicuuc, true) \ - PER_FUNCTION_BLOCK(u_strcmp, libicuuc, true) \ - PER_FUNCTION_BLOCK(u_strcpy, libicuuc, true) \ - PER_FUNCTION_BLOCK(u_strlen, libicuuc, true) \ - PER_FUNCTION_BLOCK(u_strncpy, libicuuc, true) \ - PER_FUNCTION_BLOCK(u_tolower, libicuuc, true) \ - PER_FUNCTION_BLOCK(u_toupper, libicuuc, true) \ - PER_FUNCTION_BLOCK(u_uastrncpy, libicuuc, true) \ - PER_FUNCTION_BLOCK(ubrk_close, libicuuc, true) \ - PER_FUNCTION_BLOCK(ubrk_openRules, libicuuc, true) \ - PER_FUNCTION_BLOCK(ucal_add, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucal_close, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucal_get, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucal_getAttribute, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucal_getKeywordValuesForLocale, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucal_getLimit, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucal_getNow, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucal_getTimeZoneDisplayName, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucal_open, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucal_openTimeZoneIDEnumeration, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucal_set, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucal_setMillis, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucol_close, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucol_closeElements, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucol_getOffset, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucol_getRules, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucol_getSortKey, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucol_getStrength, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucol_getVersion, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucol_next, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucol_previous, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucol_open, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucol_openElements, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucol_openRules, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucol_setAttribute, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucol_strcoll, libicui18n, true) \ - PER_FUNCTION_BLOCK(udat_close, libicui18n, true) \ - PER_FUNCTION_BLOCK(udat_countSymbols, libicui18n, true) \ - PER_FUNCTION_BLOCK(udat_format, libicui18n, true) \ - PER_FUNCTION_BLOCK(udat_getSymbols, libicui18n, true) \ - PER_FUNCTION_BLOCK(udat_open, libicui18n, true) \ - PER_FUNCTION_BLOCK(udat_setCalendar, libicui18n, true) \ - PER_FUNCTION_BLOCK(udat_toPattern, libicui18n, true) \ - PER_FUNCTION_BLOCK(udatpg_close, libicui18n, true) \ - PER_FUNCTION_BLOCK(udatpg_getBestPattern, libicui18n, true) \ - PER_FUNCTION_BLOCK(udatpg_open, libicui18n, true) \ - PER_FUNCTION_BLOCK(uenum_close, libicuuc, true) \ - PER_FUNCTION_BLOCK(uenum_count, libicuuc, true) \ - PER_FUNCTION_BLOCK(uenum_next, libicuuc, true) \ - PER_FUNCTION_BLOCK(uidna_close, libicuuc, true) \ - PER_FUNCTION_BLOCK(uidna_nameToASCII, libicuuc, true) \ - PER_FUNCTION_BLOCK(uidna_nameToUnicode, libicuuc, true) \ - PER_FUNCTION_BLOCK(uidna_openUTS46, libicuuc, true) \ - PER_FUNCTION_BLOCK(uloc_canonicalize, libicuuc, true) \ - PER_FUNCTION_BLOCK(uloc_countAvailable, libicuuc, true) \ - PER_FUNCTION_BLOCK(uloc_getAvailable, libicuuc, true) \ - PER_FUNCTION_BLOCK(uloc_getBaseName, libicuuc, true) \ - PER_FUNCTION_BLOCK(uloc_getCharacterOrientation, libicuuc, true) \ - PER_FUNCTION_BLOCK(uloc_getCountry, libicuuc, true) \ - PER_FUNCTION_BLOCK(uloc_getDefault, libicuuc, true) \ - PER_FUNCTION_BLOCK(uloc_getDisplayCountry, libicuuc, true) \ - PER_FUNCTION_BLOCK(uloc_getDisplayLanguage, libicuuc, true) \ - PER_FUNCTION_BLOCK(uloc_getDisplayName, libicuuc, true) \ - PER_FUNCTION_BLOCK(uloc_getISO3Country, libicuuc, true) \ - PER_FUNCTION_BLOCK(uloc_getISO3Language, libicuuc, true) \ - PER_FUNCTION_BLOCK(uloc_getKeywordValue, libicuuc, true) \ - PER_FUNCTION_BLOCK(uloc_getLanguage, libicuuc, true) \ - PER_FUNCTION_BLOCK(uloc_getLCID, libicuuc, true) \ - PER_FUNCTION_BLOCK(uloc_getName, libicuuc, true) \ - PER_FUNCTION_BLOCK(uloc_getParent, libicuuc, true) \ - PER_FUNCTION_BLOCK(uloc_setKeywordValue, libicuuc, true) \ - PER_FUNCTION_BLOCK(ulocdata_getCLDRVersion, libicui18n, true) \ - PER_FUNCTION_BLOCK(ulocdata_getMeasurementSystem, libicui18n, true) \ - PER_FUNCTION_BLOCK(unorm2_getNFCInstance, libicuuc, true) \ - PER_FUNCTION_BLOCK(unorm2_getNFDInstance, libicuuc, true) \ - PER_FUNCTION_BLOCK(unorm2_getNFKCInstance, libicuuc, true) \ - PER_FUNCTION_BLOCK(unorm2_getNFKDInstance, libicuuc, true) \ - PER_FUNCTION_BLOCK(unorm2_isNormalized, libicuuc, true) \ - PER_FUNCTION_BLOCK(unorm2_normalize, libicuuc, true) \ - PER_FUNCTION_BLOCK(unum_close, libicui18n, true) \ - PER_FUNCTION_BLOCK(unum_getAttribute, libicui18n, true) \ - PER_FUNCTION_BLOCK(unum_getSymbol, libicui18n, true) \ - PER_FUNCTION_BLOCK(unum_open, libicui18n, true) \ - PER_FUNCTION_BLOCK(unum_toPattern, libicui18n, true) \ - PER_FUNCTION_BLOCK(ures_close, libicuuc, true) \ - PER_FUNCTION_BLOCK(ures_getByKey, libicuuc, true) \ - PER_FUNCTION_BLOCK(ures_getSize, libicuuc, true) \ - PER_FUNCTION_BLOCK(ures_getStringByIndex, libicuuc, true) \ - PER_FUNCTION_BLOCK(ures_open, libicuuc, true) \ - PER_FUNCTION_BLOCK(usearch_close, libicui18n, true) \ - PER_FUNCTION_BLOCK(usearch_first, libicui18n, true) \ - PER_FUNCTION_BLOCK(usearch_getBreakIterator, libicui18n, true) \ - PER_FUNCTION_BLOCK(usearch_getMatchedLength, libicui18n, true) \ - PER_FUNCTION_BLOCK(usearch_last, libicui18n, true) \ - PER_FUNCTION_BLOCK(usearch_openFromCollator, libicui18n, true) \ - PER_FUNCTION_BLOCK(usearch_setPattern, libicui18n, true) \ - PER_FUNCTION_BLOCK(usearch_setText, libicui18n, true) - -#if defined(TARGET_WINDOWS) -#define FOR_ALL_OS_CONDITIONAL_ICU_FUNCTIONS \ - PER_FUNCTION_BLOCK(ucurr_forLocale, libicuuc, true) \ - PER_FUNCTION_BLOCK(ucurr_getName, libicuuc, true) \ - PER_FUNCTION_BLOCK(uldn_close, libicuuc, true) \ - PER_FUNCTION_BLOCK(uldn_keyValueDisplayName, libicuuc, true) \ - PER_FUNCTION_BLOCK(uldn_open, libicuuc, true) -#else - // Unix ICU is dynamically resolved at runtime and these APIs in old versions - // of ICU were in libicui18n -#define FOR_ALL_OS_CONDITIONAL_ICU_FUNCTIONS \ - PER_FUNCTION_BLOCK(ucurr_forLocale, libicui18n, true) \ - PER_FUNCTION_BLOCK(ucurr_getName, libicui18n, true) \ - PER_FUNCTION_BLOCK(uldn_close, libicui18n, true) \ - PER_FUNCTION_BLOCK(uldn_keyValueDisplayName, libicui18n, true) \ - PER_FUNCTION_BLOCK(uldn_open, libicui18n, true) -#endif - -// The following are the list of the ICU APIs which are optional. If these APIs exist in the ICU version we load at runtime, then we'll use it. -// Otherwise, we'll just not provide the functionality to users which needed these APIs. -#define FOR_ALL_OPTIONAL_ICU_FUNCTIONS \ - PER_FUNCTION_BLOCK(ucal_getWindowsTimeZoneID, libicui18n, false) \ - PER_FUNCTION_BLOCK(ucal_getTimeZoneIDForWindowsID, libicui18n, false) \ - PER_FUNCTION_BLOCK(ucol_setMaxVariable, libicui18n, false) \ - PER_FUNCTION_BLOCK(ucol_clone, libicui18n, false) - -#define FOR_ALL_ICU_FUNCTIONS \ - FOR_ALL_UNCONDITIONAL_ICU_FUNCTIONS \ - FOR_ALL_OPTIONAL_ICU_FUNCTIONS \ - FOR_ALL_OS_CONDITIONAL_ICU_FUNCTIONS - -// Declare pointers to all the used ICU functions -#define PER_FUNCTION_BLOCK(fn, lib, required) EXTERN_C TYPEOF(fn)* fn##_ptr; -FOR_ALL_ICU_FUNCTIONS -#undef PER_FUNCTION_BLOCK - -// Redefine all calls to ICU functions as calls through pointers that are set -// to the functions of the selected version of ICU in the initialization. -#define u_charsToUChars(...) u_charsToUChars_ptr(__VA_ARGS__) -#define u_getVersion(...) u_getVersion_ptr(__VA_ARGS__) -#define u_strcmp(...) u_strcmp_ptr(__VA_ARGS__) -#define u_strcpy(...) u_strcpy_ptr(__VA_ARGS__) -#define u_strlen(...) u_strlen_ptr(__VA_ARGS__) -#define u_strncpy(...) u_strncpy_ptr(__VA_ARGS__) -#define u_tolower(...) u_tolower_ptr(__VA_ARGS__) -#define u_toupper(...) u_toupper_ptr(__VA_ARGS__) -#define u_uastrncpy(...) u_uastrncpy_ptr(__VA_ARGS__) -#define ubrk_close(...) ubrk_close_ptr(__VA_ARGS__) -#define ubrk_openRules(...) ubrk_openRules_ptr(__VA_ARGS__) -#define ucal_add(...) ucal_add_ptr(__VA_ARGS__) -#define ucal_close(...) ucal_close_ptr(__VA_ARGS__) -#define ucal_get(...) ucal_get_ptr(__VA_ARGS__) -#define ucal_getAttribute(...) ucal_getAttribute_ptr(__VA_ARGS__) -#define ucal_getKeywordValuesForLocale(...) ucal_getKeywordValuesForLocale_ptr(__VA_ARGS__) -#define ucal_getLimit(...) ucal_getLimit_ptr(__VA_ARGS__) -#define ucal_getNow(...) ucal_getNow_ptr(__VA_ARGS__) -#define ucal_getTimeZoneDisplayName(...) ucal_getTimeZoneDisplayName_ptr(__VA_ARGS__) -#define ucal_getTimeZoneIDForWindowsID(...) ucal_getTimeZoneIDForWindowsID_ptr(__VA_ARGS__) -#define ucal_getWindowsTimeZoneID(...) ucal_getWindowsTimeZoneID_ptr(__VA_ARGS__) -#define ucal_open(...) ucal_open_ptr(__VA_ARGS__) -#define ucal_openTimeZoneIDEnumeration(...) ucal_openTimeZoneIDEnumeration_ptr(__VA_ARGS__) -#define ucal_set(...) ucal_set_ptr(__VA_ARGS__) -#define ucal_setMillis(...) ucal_setMillis_ptr(__VA_ARGS__) -#define ucol_clone(...) ucol_clone_ptr(__VA_ARGS__) -#define ucol_close(...) ucol_close_ptr(__VA_ARGS__) -#define ucol_closeElements(...) ucol_closeElements_ptr(__VA_ARGS__) -#define ucol_getOffset(...) ucol_getOffset_ptr(__VA_ARGS__) -#define ucol_getRules(...) ucol_getRules_ptr(__VA_ARGS__) -#define ucol_getSortKey(...) ucol_getSortKey_ptr(__VA_ARGS__) -#define ucol_getStrength(...) ucol_getStrength_ptr(__VA_ARGS__) -#define ucol_getVersion(...) ucol_getVersion_ptr(__VA_ARGS__) -#define ucol_next(...) ucol_next_ptr(__VA_ARGS__) -#define ucol_previous(...) ucol_previous_ptr(__VA_ARGS__) -#define ucol_open(...) ucol_open_ptr(__VA_ARGS__) -#define ucol_openElements(...) ucol_openElements_ptr(__VA_ARGS__) -#define ucol_openRules(...) ucol_openRules_ptr(__VA_ARGS__) -#define ucol_setAttribute(...) ucol_setAttribute_ptr(__VA_ARGS__) -#define ucol_setMaxVariable(...) ucol_setMaxVariable_ptr(__VA_ARGS__) -#define ucol_strcoll(...) ucol_strcoll_ptr(__VA_ARGS__) -#define ucurr_forLocale(...) ucurr_forLocale_ptr(__VA_ARGS__) -#define ucurr_getName(...) ucurr_getName_ptr(__VA_ARGS__) -#define udat_close(...) udat_close_ptr(__VA_ARGS__) -#define udat_countSymbols(...) udat_countSymbols_ptr(__VA_ARGS__) -#define udat_format(...) udat_format_ptr(__VA_ARGS__) -#define udat_getSymbols(...) udat_getSymbols_ptr(__VA_ARGS__) -#define udat_open(...) udat_open_ptr(__VA_ARGS__) -#define udat_setCalendar(...) udat_setCalendar_ptr(__VA_ARGS__) -#define udat_toPattern(...) udat_toPattern_ptr(__VA_ARGS__) -#define udatpg_close(...) udatpg_close_ptr(__VA_ARGS__) -#define udatpg_getBestPattern(...) udatpg_getBestPattern_ptr(__VA_ARGS__) -#define udatpg_open(...) udatpg_open_ptr(__VA_ARGS__) -#define uenum_close(...) uenum_close_ptr(__VA_ARGS__) -#define uenum_count(...) uenum_count_ptr(__VA_ARGS__) -#define uenum_next(...) uenum_next_ptr(__VA_ARGS__) -#define uidna_close(...) uidna_close_ptr(__VA_ARGS__) -#define uidna_nameToASCII(...) uidna_nameToASCII_ptr(__VA_ARGS__) -#define uidna_nameToUnicode(...) uidna_nameToUnicode_ptr(__VA_ARGS__) -#define uidna_openUTS46(...) uidna_openUTS46_ptr(__VA_ARGS__) -#define uldn_close(...) uldn_close_ptr(__VA_ARGS__) -#define uldn_keyValueDisplayName(...) uldn_keyValueDisplayName_ptr(__VA_ARGS__) -#define uldn_open(...) uldn_open_ptr(__VA_ARGS__) -#define uloc_canonicalize(...) uloc_canonicalize_ptr(__VA_ARGS__) -#define uloc_countAvailable(...) uloc_countAvailable_ptr(__VA_ARGS__) -#define uloc_getAvailable(...) uloc_getAvailable_ptr(__VA_ARGS__) -#define uloc_getBaseName(...) uloc_getBaseName_ptr(__VA_ARGS__) -#define uloc_getCharacterOrientation(...) uloc_getCharacterOrientation_ptr(__VA_ARGS__) -#define uloc_getCountry(...) uloc_getCountry_ptr(__VA_ARGS__) -#define uloc_getDefault(...) uloc_getDefault_ptr(__VA_ARGS__) -#define uloc_getDisplayCountry(...) uloc_getDisplayCountry_ptr(__VA_ARGS__) -#define uloc_getDisplayLanguage(...) uloc_getDisplayLanguage_ptr(__VA_ARGS__) -#define uloc_getDisplayName(...) uloc_getDisplayName_ptr(__VA_ARGS__) -#define uloc_getISO3Country(...) uloc_getISO3Country_ptr(__VA_ARGS__) -#define uloc_getISO3Language(...) uloc_getISO3Language_ptr(__VA_ARGS__) -#define uloc_getKeywordValue(...) uloc_getKeywordValue_ptr(__VA_ARGS__) -#define uloc_getLanguage(...) uloc_getLanguage_ptr(__VA_ARGS__) -#define uloc_getLCID(...) uloc_getLCID_ptr(__VA_ARGS__) -#define uloc_getName(...) uloc_getName_ptr(__VA_ARGS__) -#define uloc_getParent(...) uloc_getParent_ptr(__VA_ARGS__) -#define uloc_setKeywordValue(...) uloc_setKeywordValue_ptr(__VA_ARGS__) -#define ulocdata_getCLDRVersion(...) ulocdata_getCLDRVersion_ptr(__VA_ARGS__) -#define ulocdata_getMeasurementSystem(...) ulocdata_getMeasurementSystem_ptr(__VA_ARGS__) -#define unorm2_getNFCInstance(...) unorm2_getNFCInstance_ptr(__VA_ARGS__) -#define unorm2_getNFDInstance(...) unorm2_getNFDInstance_ptr(__VA_ARGS__) -#define unorm2_getNFKCInstance(...) unorm2_getNFKCInstance_ptr(__VA_ARGS__) -#define unorm2_getNFKDInstance(...) unorm2_getNFKDInstance_ptr(__VA_ARGS__) -#define unorm2_isNormalized(...) unorm2_isNormalized_ptr(__VA_ARGS__) -#define unorm2_normalize(...) unorm2_normalize_ptr(__VA_ARGS__) -#define unum_close(...) unum_close_ptr(__VA_ARGS__) -#define unum_getAttribute(...) unum_getAttribute_ptr(__VA_ARGS__) -#define unum_getSymbol(...) unum_getSymbol_ptr(__VA_ARGS__) -#define unum_open(...) unum_open_ptr(__VA_ARGS__) -#define unum_toPattern(...) unum_toPattern_ptr(__VA_ARGS__) -#define ures_close(...) ures_close_ptr(__VA_ARGS__) -#define ures_getByKey(...) ures_getByKey_ptr(__VA_ARGS__) -#define ures_getSize(...) ures_getSize_ptr(__VA_ARGS__) -#define ures_getStringByIndex(...) ures_getStringByIndex_ptr(__VA_ARGS__) -#define ures_open(...) ures_open_ptr(__VA_ARGS__) -#define usearch_close(...) usearch_close_ptr(__VA_ARGS__) -#define usearch_first(...) usearch_first_ptr(__VA_ARGS__) -#define usearch_getBreakIterator(...) usearch_getBreakIterator_ptr(__VA_ARGS__) -#define usearch_getMatchedLength(...) usearch_getMatchedLength_ptr(__VA_ARGS__) -#define usearch_last(...) usearch_last_ptr(__VA_ARGS__) -#define usearch_openFromCollator(...) usearch_openFromCollator_ptr(__VA_ARGS__) -#define usearch_reset(...) usearch_reset_ptr(__VA_ARGS__) -#define usearch_setPattern(...) usearch_setPattern_ptr(__VA_ARGS__) -#define usearch_setText(...) usearch_setText_ptr(__VA_ARGS__) - -#else // !defined(STATIC_ICU) - -#define ucal_getWindowsTimeZoneID_ptr ucal_getWindowsTimeZoneID -#define ucal_getTimeZoneIDForWindowsID_ptr ucal_getTimeZoneIDForWindowsID - -#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) -const char* GlobalizationNative_GetICUDataPathRelativeToAppBundleRoot(const char* path); -const char* GlobalizationNative_GetICUDataPathFallback(void); -#endif - -#endif // !defined(STATIC_ICU) -#if defined(APPLE_HYBRID_GLOBALIZATION) -/** - * Append a code point to a string, overwriting 1 or 2 code units. - * The offset points to the current end of the string contents - * and is advanced (post-increment). - * "Safe" macro, checks for a valid code point. - * Converts code points outside of Basic Multilingual Plane into - * corresponding surrogate pairs if sufficient space in the string. - * High surrogate range: 0xD800 - 0xDBFF - * Low surrogate range: 0xDC00 - 0xDFFF - * If the code point is not valid or a trail surrogate does not fit, - * then isError is set to true. - * - * @param buffer const uint16_t * string buffer - * @param offset string offset, must be offset= (capacity)) /* insufficiently sized destination buffer */ { \ - (isError) = InsufficientBuffer; \ - } else if ((uint32_t)(codePoint) > 0x10ffff) /* invalid code point */ { \ - (isError) = InvalidCodePoint; \ - } else if ((uint32_t)(codePoint) <= 0xffff) { \ - (buffer)[(offset)++] = (uint16_t)(codePoint); \ - } else { \ - (buffer)[(offset)++] = (uint16_t)(((codePoint) >> 10) + 0xd7c0); \ - (buffer)[(offset)++] = (uint16_t)(((codePoint)&0x3ff) | 0xdc00); \ - } \ -} -#endif diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_icushim_internal_android.h b/src/native/libs/System.HybridGlobalization.Native/pal_icushim_internal_android.h deleted file mode 100644 index 424f72597dc7d..0000000000000 --- a/src/native/libs/System.HybridGlobalization.Native/pal_icushim_internal_android.h +++ /dev/null @@ -1,542 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// - -// definitions for ICU types and functions available in Android, -// extracted from ICU header files - -#pragma once - -#define U_MAX_VERSION_LENGTH 4 - -#define U_SUCCESS(x) ((x)<=U_ZERO_ERROR) -#define U_FAILURE(x) ((x)>U_ZERO_ERROR) - -typedef struct UCollator UCollator; -typedef struct UCollationElements UCollationElements; -typedef struct UEnumeration UEnumeration; -typedef struct UIDNA UIDNA; -typedef struct UNormalizer2 UNormalizer2; -typedef struct ULocaleDisplayNames ULocaleDisplayNames; -typedef struct UResourceBundle UResourceBundle; -typedef struct UStringSearch UStringSearch; -typedef struct UBreakIterator UBreakIterator; - -typedef int8_t UBool; -typedef uint16_t UChar; -typedef int32_t UChar32; -typedef double UDate; -typedef uint8_t UVersionInfo[U_MAX_VERSION_LENGTH]; - -typedef void* UNumberFormat; -typedef void* UDateFormat; -typedef void* UDateTimePatternGenerator; -typedef void* UCalendar; - -#ifndef TRUE -# define TRUE 1 -#endif -#ifndef FALSE -# define FALSE 0 -#endif - -#define USEARCH_DONE -1 - -#define UCOL_NULLORDER ((int32_t)0xFFFFFFFF) -#define UCOL_BUILDER_VERSION 9 -#define UCOL_RUNTIME_VERSION 9 - -#define ULOC_FULLNAME_CAPACITY 157 -#define ULOC_LANG_CAPACITY 12 -#define ULOC_KEYWORDS_CAPACITY 96 -#define ULOC_ENGLISH "en" -#define ULOC_US "en_US" - -#define U16_IS_LEAD(c) (((c)&0xfffffc00)==0xd800) -#define U16_IS_TRAIL(c) (((c)&0xfffffc00)==0xdc00) -#define U16_SURROGATE_OFFSET ((0xd800<<10UL)+0xdc00-0x10000) - -#define U16_GET_SUPPLEMENTARY(lead, trail) \ - (((UChar32)(lead)<<10UL)+(UChar32)(trail)-U16_SURROGATE_OFFSET) - -#define U16_APPEND(s, i, capacity, c, isError) { \ - if((uint32_t)(c)<=0xffff) { \ - (s)[(i)++]=(uint16_t)(c); \ - } else if((uint32_t)(c)<=0x10ffff && (i)+1<(capacity)) { \ - (s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \ - (s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \ - } else { \ - (isError)=TRUE; \ - } \ -} - -#define U16_NEXT(s, i, length, c) { \ - (c)=(s)[(i)++]; \ - if(U16_IS_LEAD(c)) { \ - uint16_t __c2; \ - if((i)!=(length) && U16_IS_TRAIL(__c2=(s)[(i)])) { \ - ++(i); \ - (c)=U16_GET_SUPPLEMENTARY((c), __c2); \ - } \ - } \ -} - -#define U16_FWD_1(s, i, length) { \ - if(U16_IS_LEAD((s)[(i)++]) && (i)!=(length) && U16_IS_TRAIL((s)[i])) { \ - ++(i); \ - } \ -} - -#define UIDNA_INFO_INITIALIZER { \ - (int16_t)sizeof(UIDNAInfo), \ - FALSE, FALSE, \ - 0, 0, 0 } - -typedef enum UErrorCode { - U_STRING_NOT_TERMINATED_WARNING = -124, - U_USING_DEFAULT_WARNING = -127, - U_ZERO_ERROR = 0, - U_ILLEGAL_ARGUMENT_ERROR = 1, - U_INTERNAL_PROGRAM_ERROR = 5, - U_MEMORY_ALLOCATION_ERROR = 7, - U_BUFFER_OVERFLOW_ERROR = 15, - U_UNSUPPORTED_ERROR = 16, -} UErrorCode; - -typedef enum UCalendarDateFields { - UCAL_ERA, - UCAL_YEAR, - UCAL_MONTH, - UCAL_WEEK_OF_YEAR, - UCAL_WEEK_OF_MONTH, - UCAL_DATE, - UCAL_DAY_OF_YEAR, - UCAL_DAY_OF_WEEK, - UCAL_DAY_OF_WEEK_IN_MONTH, - UCAL_AM_PM, - UCAL_HOUR, - UCAL_HOUR_OF_DAY, - UCAL_MINUTE, - UCAL_SECOND, - UCAL_MILLISECOND, - UCAL_ZONE_OFFSET, - UCAL_DST_OFFSET, - UCAL_YEAR_WOY, - UCAL_DOW_LOCAL, - UCAL_EXTENDED_YEAR, - UCAL_JULIAN_DAY, - UCAL_MILLISECONDS_IN_DAY, - UCAL_IS_LEAP_MONTH, - UCAL_FIELD_COUNT, - UCAL_DAY_OF_MONTH = UCAL_DATE -} UCalendarDateFields; - -typedef enum UColAttribute { - UCOL_FRENCH_COLLATION, - UCOL_ALTERNATE_HANDLING, - UCOL_CASE_FIRST, - UCOL_CASE_LEVEL, - UCOL_NORMALIZATION_MODE, - UCOL_DECOMPOSITION_MODE = UCOL_NORMALIZATION_MODE, - UCOL_STRENGTH, - UCOL_NUMERIC_COLLATION = UCOL_STRENGTH + 2, - UCOL_ATTRIBUTE_COUNT -} UColAttribute; - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wduplicate-enum" -typedef enum UColAttributeValue { - UCOL_DEFAULT = -1, - UCOL_PRIMARY = 0, - UCOL_SECONDARY = 1, - UCOL_TERTIARY = 2, - UCOL_DEFAULT_STRENGTH = UCOL_TERTIARY, - UCOL_CE_STRENGTH_LIMIT, - UCOL_QUATERNARY=3, - UCOL_IDENTICAL=15, - UCOL_STRENGTH_LIMIT, - UCOL_OFF = 16, - UCOL_ON = 17, - UCOL_SHIFTED = 20, - UCOL_NON_IGNORABLE = 21, - UCOL_LOWER_FIRST = 24, - UCOL_UPPER_FIRST = 25, -} UColAttributeValue; -#pragma clang diagnostic pop - -typedef UColAttributeValue UCollationStrength; - -typedef enum UCalendarAttribute { - UCAL_LENIENT, - UCAL_FIRST_DAY_OF_WEEK, - UCAL_MINIMAL_DAYS_IN_FIRST_WEEK, - UCAL_REPEATED_WALL_TIME, - UCAL_SKIPPED_WALL_TIME -} UCalendarAttribute; - -typedef enum UCalendarLimitType { - UCAL_MINIMUM, - UCAL_MAXIMUM, - UCAL_GREATEST_MINIMUM, - UCAL_LEAST_MAXIMUM, - UCAL_ACTUAL_MINIMUM, - UCAL_ACTUAL_MAXIMUM -} UCalendarLimitType; - -typedef enum UCalendarDisplayNameType { - UCAL_STANDARD, - UCAL_SHORT_STANDARD, - UCAL_DST, - UCAL_SHORT_DST -} UCalendarDisplayNameType; - -typedef enum ULayoutType { - ULOC_LAYOUT_LTR = 0, - ULOC_LAYOUT_RTL = 1, - ULOC_LAYOUT_TTB = 2, - ULOC_LAYOUT_BTT = 3, - ULOC_LAYOUT_UNKNOWN -} ULayoutType; - -typedef enum UDialectHandling { - ULDN_STANDARD_NAMES = 0, - ULDN_DIALECT_NAMES -} UDialectHandling; - -typedef enum UMeasurementSystem { - UMS_SI, - UMS_US, - UMS_UK, -} UMeasurementSystem; - -typedef enum UNumberFormatSymbol { - UNUM_DECIMAL_SEPARATOR_SYMBOL = 0, - UNUM_GROUPING_SEPARATOR_SYMBOL = 1, - UNUM_PATTERN_SEPARATOR_SYMBOL = 2, - UNUM_PERCENT_SYMBOL = 3, - UNUM_ZERO_DIGIT_SYMBOL = 4, - UNUM_DIGIT_SYMBOL = 5, - UNUM_MINUS_SIGN_SYMBOL = 6, - UNUM_PLUS_SIGN_SYMBOL = 7, - UNUM_CURRENCY_SYMBOL = 8, - UNUM_INTL_CURRENCY_SYMBOL = 9, - UNUM_MONETARY_SEPARATOR_SYMBOL = 10, - UNUM_EXPONENTIAL_SYMBOL = 11, - UNUM_PERMILL_SYMBOL = 12, - UNUM_PAD_ESCAPE_SYMBOL = 13, - UNUM_INFINITY_SYMBOL = 14, - UNUM_NAN_SYMBOL = 15, - UNUM_SIGNIFICANT_DIGIT_SYMBOL = 16, - UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL = 17, - UNUM_ONE_DIGIT_SYMBOL = 18, - UNUM_TWO_DIGIT_SYMBOL = 19, - UNUM_THREE_DIGIT_SYMBOL = 20, - UNUM_FOUR_DIGIT_SYMBOL = 21, - UNUM_FIVE_DIGIT_SYMBOL = 22, - UNUM_SIX_DIGIT_SYMBOL = 23, - UNUM_SEVEN_DIGIT_SYMBOL = 24, - UNUM_EIGHT_DIGIT_SYMBOL = 25, - UNUM_NINE_DIGIT_SYMBOL = 26, - UNUM_EXPONENT_MULTIPLICATION_SYMBOL = 27, -} UNumberFormatSymbol; - -typedef enum UNumberFormatAttribute { - UNUM_PARSE_INT_ONLY, - UNUM_GROUPING_USED, - UNUM_DECIMAL_ALWAYS_SHOWN, - UNUM_MAX_INTEGER_DIGITS, - UNUM_MIN_INTEGER_DIGITS, - UNUM_INTEGER_DIGITS, - UNUM_MAX_FRACTION_DIGITS, - UNUM_MIN_FRACTION_DIGITS, - UNUM_FRACTION_DIGITS, - UNUM_MULTIPLIER, - UNUM_GROUPING_SIZE, - UNUM_ROUNDING_MODE, - UNUM_ROUNDING_INCREMENT, - UNUM_FORMAT_WIDTH, - UNUM_PADDING_POSITION, - UNUM_SECONDARY_GROUPING_SIZE, - UNUM_SIGNIFICANT_DIGITS_USED, - UNUM_MIN_SIGNIFICANT_DIGITS, - UNUM_MAX_SIGNIFICANT_DIGITS, - UNUM_LENIENT_PARSE, - UNUM_SCALE = 21, - UNUM_CURRENCY_USAGE = 23, - UNUM_MAX_NONBOOLEAN_ATTRIBUTE = 0x0FFF, - UNUM_FORMAT_FAIL_IF_MORE_THAN_MAX_DIGITS = 0x1000, - UNUM_PARSE_NO_EXPONENT, - UNUM_PARSE_DECIMAL_MARK_REQUIRED = 0x1002, - UNUM_LIMIT_BOOLEAN_ATTRIBUTE = 0x1003 -} UNumberFormatAttribute; - -typedef enum UNumberFormatStyle { - UNUM_PATTERN_DECIMAL = 0, - UNUM_DECIMAL = 1, - UNUM_CURRENCY = 2, - UNUM_PERCENT = 3, - UNUM_SCIENTIFIC = 4, - UNUM_SPELLOUT = 5, - UNUM_ORDINAL = 6, - UNUM_DURATION = 7, - UNUM_NUMBERING_SYSTEM = 8, - UNUM_PATTERN_RULEBASED = 9, - UNUM_CURRENCY_ISO = 10, - UNUM_CURRENCY_PLURAL = 11, - UNUM_CURRENCY_ACCOUNTING = 12, - UNUM_CASH_CURRENCY = 13, - UNUM_DECIMAL_COMPACT_SHORT = 14, - UNUM_DECIMAL_COMPACT_LONG = 15, - UNUM_CURRENCY_STANDARD = 16, - UNUM_DEFAULT = UNUM_DECIMAL, - UNUM_IGNORE = UNUM_PATTERN_DECIMAL -} UNumberFormatStyle; - -typedef enum UScriptCode { - USCRIPT_UNKNOWN = 103, -} UScriptCode; - -typedef enum UColReorderCode { - UCOL_REORDER_CODE_DEFAULT = -1, - UCOL_REORDER_CODE_NONE = USCRIPT_UNKNOWN, - UCOL_REORDER_CODE_OTHERS = USCRIPT_UNKNOWN, - UCOL_REORDER_CODE_SPACE = 0x1000, - UCOL_REORDER_CODE_FIRST = UCOL_REORDER_CODE_SPACE, - UCOL_REORDER_CODE_PUNCTUATION = 0x1001, - UCOL_REORDER_CODE_SYMBOL = 0x1002, - UCOL_REORDER_CODE_CURRENCY = 0x1003, - UCOL_REORDER_CODE_DIGIT = 0x1004, -} UColReorderCode; - -typedef enum UDateFormatStyle { - UDAT_FULL, - UDAT_LONG, - UDAT_MEDIUM, - UDAT_SHORT, - UDAT_DEFAULT = UDAT_MEDIUM, - UDAT_RELATIVE = (1 << 7), - UDAT_FULL_RELATIVE = UDAT_FULL | UDAT_RELATIVE, - UDAT_LONG_RELATIVE = UDAT_LONG | UDAT_RELATIVE, - UDAT_MEDIUM_RELATIVE = UDAT_MEDIUM | UDAT_RELATIVE, - UDAT_SHORT_RELATIVE = UDAT_SHORT | UDAT_RELATIVE, - UDAT_NONE = -1, - UDAT_PATTERN = -2, -} UDateFormatStyle; - -typedef enum UDateFormatSymbolType { - UDAT_ERAS, - UDAT_MONTHS, - UDAT_SHORT_MONTHS, - UDAT_WEEKDAYS, - UDAT_SHORT_WEEKDAYS, - UDAT_AM_PMS, - UDAT_LOCALIZED_CHARS, - UDAT_ERA_NAMES, - UDAT_NARROW_MONTHS, - UDAT_NARROW_WEEKDAYS, - UDAT_STANDALONE_MONTHS, - UDAT_STANDALONE_SHORT_MONTHS, - UDAT_STANDALONE_NARROW_MONTHS, - UDAT_STANDALONE_WEEKDAYS, - UDAT_STANDALONE_SHORT_WEEKDAYS, - UDAT_STANDALONE_NARROW_WEEKDAYS, - UDAT_QUARTERS, - UDAT_SHORT_QUARTERS, - UDAT_STANDALONE_QUARTERS, - UDAT_STANDALONE_SHORT_QUARTERS, - UDAT_SHORTER_WEEKDAYS, - UDAT_STANDALONE_SHORTER_WEEKDAYS, - UDAT_CYCLIC_YEARS_WIDE, - UDAT_CYCLIC_YEARS_ABBREVIATED, - UDAT_CYCLIC_YEARS_NARROW, - UDAT_ZODIAC_NAMES_WIDE, - UDAT_ZODIAC_NAMES_ABBREVIATED, - UDAT_ZODIAC_NAMES_NARROW -} UDateFormatSymbolType; - -typedef enum UCurrNameStyle { - UCURR_SYMBOL_NAME, - UCURR_LONG_NAME -} UCurrNameStyle; - -typedef enum UCalendarType { - UCAL_TRADITIONAL, - UCAL_DEFAULT = UCAL_TRADITIONAL, - UCAL_GREGORIAN -} UCalendarType; - -typedef enum UCollationResult { - UCOL_EQUAL = 0, - UCOL_GREATER = 1, - UCOL_LESS = -1 -} UCollationResult; - -typedef enum USystemTimeZoneType { - UCAL_ZONE_TYPE_ANY, - UCAL_ZONE_TYPE_CANONICAL, - UCAL_ZONE_TYPE_CANONICAL_LOCATION -} USystemTimeZoneType; - -enum { - UIDNA_ERROR_EMPTY_LABEL = 1, - UIDNA_ERROR_LABEL_TOO_LONG = 2, - UIDNA_ERROR_DOMAIN_NAME_TOO_LONG = 4, - UIDNA_ERROR_LEADING_HYPHEN = 8, - UIDNA_ERROR_TRAILING_HYPHEN = 0x10, - UIDNA_ERROR_HYPHEN_3_4 = 0x20, - UIDNA_ERROR_LEADING_COMBINING_MARK = 0x40, - UIDNA_ERROR_DISALLOWED = 0x80, - UIDNA_ERROR_PUNYCODE = 0x100, - UIDNA_ERROR_LABEL_HAS_DOT = 0x200, - UIDNA_ERROR_INVALID_ACE_LABEL = 0x400, - UIDNA_ERROR_BIDI = 0x800, - UIDNA_ERROR_CONTEXTJ = 0x1000, - UIDNA_ERROR_CONTEXTO_PUNCTUATION = 0x2000, - UIDNA_ERROR_CONTEXTO_DIGITS = 0x4000 -}; - -enum { - UIDNA_DEFAULT = 0, - UIDNA_ALLOW_UNASSIGNED = 1, - UIDNA_USE_STD3_RULES = 2, - UIDNA_CHECK_BIDI = 4, - UIDNA_CHECK_CONTEXTJ = 8, - UIDNA_NONTRANSITIONAL_TO_ASCII = 0x10, - UIDNA_NONTRANSITIONAL_TO_UNICODE = 0x20, - UIDNA_CHECK_CONTEXTO = 0x40 -}; - -enum { - U_PARSE_CONTEXT_LEN = 16 -}; - -typedef struct UParseError { - int32_t line; - int32_t offset; - UChar preContext[U_PARSE_CONTEXT_LEN]; - UChar postContext[U_PARSE_CONTEXT_LEN]; - -} UParseError; - -typedef struct UIDNAInfo { - int16_t size; - UBool isTransitionalDifferent; - UBool reservedB3; - uint32_t errors; - int32_t reservedI2; - int32_t reservedI3; -} UIDNAInfo; - -typedef struct UFieldPosition { - int32_t field; - int32_t beginIndex; - int32_t endIndex; -} UFieldPosition; - -void u_charsToUChars(const char * cs, UChar * us, int32_t length); -void u_getVersion(UVersionInfo versionArray); -int32_t u_strlen(const UChar * s); -int32_t u_strcmp(const UChar * s1, const UChar * s2); -UChar * u_strcpy(UChar * dst, const UChar * src); -UChar * u_strncpy(UChar * dst, const UChar * src, int32_t n); -UChar32 u_tolower(UChar32 c); -UChar32 u_toupper(UChar32 c); -UChar* u_uastrncpy(UChar * dst, const char * src, int32_t n); -void ubrk_close(UBreakIterator * bi); -UBreakIterator* ubrk_openRules(const UChar * rules, int32_t rulesLength, const UChar * text, int32_t textLength, UParseError * parseErr, UErrorCode * status); -void ucal_add(UCalendar * cal, UCalendarDateFields field, int32_t amount, UErrorCode * status); -void ucal_close(UCalendar * cal); -int32_t ucal_get(const UCalendar * cal, UCalendarDateFields field, UErrorCode * status); -int32_t ucal_getAttribute(const UCalendar * cal, UCalendarAttribute attr); -UEnumeration * ucal_getKeywordValuesForLocale(const char * key, const char * locale, UBool commonlyUsed, UErrorCode * status); -int32_t ucal_getLimit(const UCalendar * cal, UCalendarDateFields field, UCalendarLimitType type, UErrorCode * status); -UDate ucal_getNow(void); -int32_t ucal_getTimeZoneDisplayName(const UCalendar * cal, UCalendarDisplayNameType type, const char * locale, UChar * result, int32_t resultLength, UErrorCode * status); -int32_t ucal_getTimeZoneIDForWindowsID(const UChar * winid, int32_t len, const char * region, UChar * id, int32_t idCapacity, UErrorCode * status); -int32_t ucal_getWindowsTimeZoneID(const UChar * id, int32_t len, UChar * winid, int32_t winidCapacity, UErrorCode * status); -UCalendar * ucal_open(const UChar * zoneID, int32_t len, const char * locale, UCalendarType type, UErrorCode * status); -UEnumeration * ucal_openTimeZoneIDEnumeration(USystemTimeZoneType zoneType, const char * region, const int32_t * rawOffset, UErrorCode * ec); -void ucal_set(UCalendar * cal, UCalendarDateFields field, int32_t value); -void ucal_setMillis(UCalendar * cal, UDate dateTime, UErrorCode * status); -void ucol_close(UCollator * coll); -void ucol_closeElements(UCollationElements * elems); -int32_t ucol_getOffset(const UCollationElements *elems); -const UChar * ucol_getRules(const UCollator * coll, int32_t * length); -int32_t ucol_getSortKey(const UCollator * coll, const UChar * source, int32_t sourceLength, uint8_t * result, int32_t resultLength); -UCollationStrength ucol_getStrength(const UCollator * coll); -void ucol_getVersion(const UCollator * coll, UVersionInfo info); -int32_t ucol_next(UCollationElements * elems, UErrorCode * status); -int32_t ucol_previous(UCollationElements * elems, UErrorCode * status); -UCollator * ucol_open(const char * loc, UErrorCode * status); -UCollationElements * ucol_openElements(const UCollator * coll, const UChar * text, int32_t textLength, UErrorCode * status); -UCollator * ucol_openRules(const UChar * rules, int32_t rulesLength, UColAttributeValue normalizationMode, UCollationStrength strength, UParseError * parseError, UErrorCode * status); -UCollator * ucol_clone(const UCollator * coll, UErrorCode * status); -void ucol_setAttribute(UCollator * coll, UColAttribute attr, UColAttributeValue value, UErrorCode * status); -UCollationResult ucol_strcoll(const UCollator * coll, const UChar * source, int32_t sourceLength, const UChar * target, int32_t targetLength); -int32_t ucurr_forLocale(const char * locale, UChar * buff, int32_t buffCapacity, UErrorCode * ec); -const UChar * ucurr_getName(const UChar * currency, const char * locale, UCurrNameStyle nameStyle, UBool * isChoiceFormat, int32_t * len, UErrorCode * ec); -void udat_close(UDateFormat * format); -int32_t udat_countSymbols(const UDateFormat * fmt, UDateFormatSymbolType type); -int32_t udat_format(const UDateFormat * format, UDate dateToFormat, UChar * result, int32_t resultLength, UFieldPosition * position, UErrorCode * status); -int32_t udat_getSymbols(const UDateFormat * fmt, UDateFormatSymbolType type, int32_t symbolIndex, UChar * result, int32_t resultLength, UErrorCode * status); -UDateFormat * udat_open(UDateFormatStyle timeStyle, UDateFormatStyle dateStyle, const char * locale, const UChar * tzID, int32_t tzIDLength, const UChar * pattern, int32_t patternLength, UErrorCode * status); -void udat_setCalendar(UDateFormat * fmt, const UCalendar * calendarToSet); -int32_t udat_toPattern(const UDateFormat * fmt, UBool localized, UChar * result, int32_t resultLength, UErrorCode * status); -void udatpg_close(UDateTimePatternGenerator * dtpg); -int32_t udatpg_getBestPattern(UDateTimePatternGenerator * dtpg, const UChar * skeleton, int32_t length, UChar * bestPattern, int32_t capacity, UErrorCode * pErrorCode); -UDateTimePatternGenerator * udatpg_open(const char * locale, UErrorCode * pErrorCode); -void uenum_close(UEnumeration * en); -int32_t uenum_count(UEnumeration * en, UErrorCode * status); -const char * uenum_next(UEnumeration * en, int32_t * resultLength, UErrorCode * status); -void uidna_close(UIDNA * idna); -int32_t uidna_nameToASCII(const UIDNA * idna, const UChar * name, int32_t length, UChar * dest, int32_t capacity, UIDNAInfo * pInfo, UErrorCode * pErrorCode); -int32_t uidna_nameToUnicode(const UIDNA * idna, const UChar * name, int32_t length, UChar * dest, int32_t capacity, UIDNAInfo * pInfo, UErrorCode * pErrorCode); -UIDNA * uidna_openUTS46(uint32_t options, UErrorCode * pErrorCode); -void uldn_close(ULocaleDisplayNames * ldn); -int32_t uldn_keyValueDisplayName(const ULocaleDisplayNames * ldn, const char * key, const char * value, UChar * result, int32_t maxResultSize, UErrorCode * pErrorCode); -ULocaleDisplayNames * uldn_open(const char * locale, UDialectHandling dialectHandling, UErrorCode * pErrorCode); -int32_t uloc_canonicalize(const char * localeID, char * name, int32_t nameCapacity, UErrorCode * err); -int32_t uloc_countAvailable(void); -const char * uloc_getAvailable(int32_t n); -int32_t uloc_getBaseName(const char * localeID, char * name, int32_t nameCapacity, UErrorCode * err); -ULayoutType uloc_getCharacterOrientation(const char * localeId, UErrorCode * status); -int32_t uloc_getCountry(const char * localeID, char * country, int32_t countryCapacity, UErrorCode * err); -const char * uloc_getDefault(void); -int32_t uloc_getDisplayCountry(const char * locale, const char * displayLocale, UChar * country, int32_t countryCapacity, UErrorCode * status); -int32_t uloc_getDisplayLanguage(const char * locale, const char * displayLocale, UChar * language, int32_t languageCapacity, UErrorCode * status); -int32_t uloc_getDisplayName(const char * localeID, const char * inLocaleID, UChar * result, int32_t maxResultSize, UErrorCode * err); -const char * uloc_getISO3Country(const char * localeID); -const char * uloc_getISO3Language(const char * localeID); -int32_t uloc_getKeywordValue(const char * localeID, const char * keywordName, char * buffer, int32_t bufferCapacity, UErrorCode * status); -int32_t uloc_getLanguage(const char * localeID, char * language, int32_t languageCapacity, UErrorCode * err); -uint32_t uloc_getLCID(const char * localeID); -int32_t uloc_getName(const char * localeID, char * name, int32_t nameCapacity, UErrorCode * err); -int32_t uloc_getParent(const char * localeID, char * parent, int32_t parentCapacity, UErrorCode * err); -int32_t uloc_setKeywordValue(const char * keywordName, const char * keywordValue, char * buffer, int32_t bufferCapacity, UErrorCode * status); -void ulocdata_getCLDRVersion(UVersionInfo versionArray, UErrorCode * status); -UMeasurementSystem ulocdata_getMeasurementSystem(const char * localeID, UErrorCode * status); -const UNormalizer2 * unorm2_getNFCInstance(UErrorCode * pErrorCode); -const UNormalizer2 * unorm2_getNFDInstance(UErrorCode * pErrorCode); -const UNormalizer2 * unorm2_getNFKCInstance(UErrorCode * pErrorCode); -const UNormalizer2 * unorm2_getNFKDInstance(UErrorCode * pErrorCode); -UBool unorm2_isNormalized(const UNormalizer2 * norm2, const UChar * s, int32_t length, UErrorCode * pErrorCode); -int32_t unorm2_normalize(const UNormalizer2 * norm2, const UChar * src, int32_t length, UChar * dest, int32_t capacity, UErrorCode * pErrorCode); -void unum_close(UNumberFormat * fmt); -int32_t unum_getAttribute(const UNumberFormat * fmt, UNumberFormatAttribute attr); -int32_t unum_getSymbol(const UNumberFormat * fmt, UNumberFormatSymbol symbol, UChar * buffer, int32_t size, UErrorCode * status); -UNumberFormat * unum_open(UNumberFormatStyle style, const UChar * pattern, int32_t patternLength, const char * locale, UParseError * parseErr, UErrorCode * status); -int32_t unum_toPattern(const UNumberFormat * fmt, UBool isPatternLocalized, UChar * result, int32_t resultLength, UErrorCode * status); -void ures_close(UResourceBundle * resourceBundle); -UResourceBundle * ures_getByKey(const UResourceBundle * resourceBundle, const char * key, UResourceBundle * fillIn, UErrorCode * status); -int32_t ures_getSize(const UResourceBundle * resourceBundle); -const UChar * ures_getStringByIndex(const UResourceBundle * resourceBundle, int32_t indexS, int32_t * len, UErrorCode * status); -UResourceBundle * ures_open(const char * packageName, const char * locale, UErrorCode * status); -void usearch_close(UStringSearch * searchiter); -int32_t usearch_first(UStringSearch * strsrch, UErrorCode * status); -const UBreakIterator* usearch_getBreakIterator(const UStringSearch * strsrch); -int32_t usearch_getMatchedLength(const UStringSearch * strsrch); -int32_t usearch_last(UStringSearch * strsrch, UErrorCode * status); -UStringSearch * usearch_openFromCollator(const UChar * pattern, int32_t patternlength, const UChar * text, int32_t textlength, const UCollator * collator, UBreakIterator * breakiter, UErrorCode * status); -void usearch_setPattern(UStringSearch * strsrch, const UChar * pattern, int32_t patternlength, UErrorCode * status); -void usearch_setText(UStringSearch * strsrch, const UChar * text, int32_t textlength, UErrorCode * status); -void ucol_setMaxVariable(UCollator * coll, UColReorderCode group, UErrorCode * pErrorCode); diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_icushim_static.c b/src/native/libs/System.HybridGlobalization.Native/pal_icushim_static.c deleted file mode 100644 index ad6013d42e026..0000000000000 --- a/src/native/libs/System.HybridGlobalization.Native/pal_icushim_static.c +++ /dev/null @@ -1,253 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// - -#include -#include -#include -#include "pal_icushim_internal.h" -#include "pal_icushim.h" -#include -#include -#include - -#if !defined(APPLE_HYBRID_GLOBALIZATION) -#include -#endif - -#if defined(TARGET_UNIX) -#include -#elif defined(TARGET_WINDOWS) -#define strcasecmp _stricmp -#define strncasecmp _strnicmp -#endif -#if !defined(TARGET_MACCATALYST) && !defined(TARGET_IOS) && !defined(TARGET_TVOS) -static int32_t isLoaded = 0; -static int32_t isDataSet = 0; - -static void log_shim_error(const char* format, ...) -{ - va_list args; - - va_start(args, format); - vfprintf(stderr, format, args); - fputc('\n', stderr); - va_end(args); -} - -static void log_icu_error(const char* name, UErrorCode status) -{ - const char * statusText = u_errorName(status); - log_shim_error("ICU call %s failed with error #%d '%s'.", name, status, statusText); -} - -#if defined(ICU_TRACING) -static void U_CALLCONV icu_trace_data(const void* context, int32_t fnNumber, int32_t level, const char* fmt, va_list args) -{ - char buf[1000]; - utrace_vformat(buf, sizeof(buf), 0, fmt, args); - printf("[ICUDT] %s: %s\n", utrace_functionName(fnNumber), buf); -} -#endif - -static int32_t load_icu_data(const void* pData); - -#ifdef __EMSCRIPTEN__ -#include - -EMSCRIPTEN_KEEPALIVE int32_t mono_wasm_load_icu_data(const void* pData); - -EMSCRIPTEN_KEEPALIVE int32_t mono_wasm_load_icu_data(const void* pData) -{ - return load_icu_data(pData); -} - -/* - * driver.c calls this to make sure this file is linked, otherwise - * its not, meaning the EMSCRIPTEN_KEEPALIVE functions above - * are not kept. - */ -void mono_wasm_link_icu_shim(void); - -void mono_wasm_link_icu_shim(void) -{ -} - -#endif - -int32_t mono_wasi_load_icu_data(const void* pData); - -int32_t mono_wasi_load_icu_data(const void* pData) -{ - return load_icu_data(pData); -} - -static int32_t load_icu_data(const void* pData) -{ - - UErrorCode status = 0; - udata_setCommonData(pData, &status); - - if (U_FAILURE(status)) - { - log_icu_error("udata_setCommonData", status); - return 0; - } - else - { - -#if defined(ICU_TRACING) - // see https://github.com/unicode-org/icu/blob/master/docs/userguide/icu_data/tracing.md - utrace_setFunctions(0, 0, 0, icu_trace_data); - utrace_setLevel(UTRACE_VERBOSE); -#endif - isDataSet = 1; - return 1; - } -} - -static const char * -cstdlib_load_icu_data(const char *path) -{ - char *file_buf = NULL; - FILE *fp = fopen(path, "rb"); - - if (fp == NULL) - { - log_shim_error("Unable to load ICU dat file '%s'.", path); - goto error; - } - - if (fseek(fp, 0L, SEEK_END) != 0) - { - log_shim_error("Unable to determine size of the dat file"); - goto error; - } - - long file_buf_size = ftell(fp); - - if (file_buf_size == -1) - { - log_shim_error("Unable to determine size of the ICU dat file."); - goto error; - } - - file_buf = malloc(sizeof(char) * (unsigned long)(file_buf_size + 1)); - - if (file_buf == NULL) - { - log_shim_error("Unable to allocate enough to read the ICU dat file"); - goto error; - } - - if (fseek(fp, 0L, SEEK_SET) != 0) - { - log_shim_error("Unable to seek ICU dat file."); - goto error; - } - - fread(file_buf, sizeof(char), (unsigned long)file_buf_size, fp); - if (ferror( fp ) != 0) - { - log_shim_error("Unable to read ICU dat file"); - goto error; - } - - fclose(fp); - fp = NULL; - - return file_buf; - -error: - if (fp != NULL) - { - fclose(fp); - } - if (file_buf != NULL) - { - free(file_buf); - } - return NULL; -} - -int32_t -GlobalizationNative_LoadICUData(const char* path) -{ -#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) - if (path && path[0] != '/') - { - // if the path is relative, prepend the app bundle root - path = GlobalizationNative_GetICUDataPathRelativeToAppBundleRoot(path); - } - if (!path) - { - // fallback to icudt.dat in the app bundle resources in case the path isn't set - path = GlobalizationNative_GetICUDataPathFallback(); - } -#endif - - const char *icu_data = cstdlib_load_icu_data(path); - - if (icu_data == NULL) - { - log_shim_error("Failed to load ICU data."); - return 0; - } - - if (load_icu_data(icu_data) == 0) - { - log_shim_error("ICU BAD EXIT."); - return 0; - } - - return GlobalizationNative_LoadICU(); -} - -int32_t GlobalizationNative_LoadICU(void) -{ -#if !defined(LOCAL_BUILD) -// Static NativeAOT compilation does not have -// GlobalizationNative_LoadICUData() as entrypoint - if (!isDataSet) - { - // don't try to locate icudt.dat automatically if mono_wasm_load_icu_data wasn't called - // and fallback to invariant mode - return 0; - } -#endif - - UErrorCode status = 0; - UVersionInfo version; - // Request the CLDR version to perform basic ICU initialization and find out - // whether it worked. - ulocdata_getCLDRVersion(version, &status); - - if (U_FAILURE(status)) - { - log_icu_error("ulocdata_getCLDRVersion", status); - return 0; - } - - isLoaded = 1; - return 1; -} - -void GlobalizationNative_InitICUFunctions(void* icuuc, void* icuin, const char* version, const char* suffix) -{ - // no-op for static -} - -int32_t GlobalizationNative_GetICUVersion(void) -{ - // this method is only used from our tests - // this way we ensure we're testing on the right mode - // even though we can call u_getVersion without loading since it is statically linked. - if (!isLoaded) - return 0; - - UVersionInfo versionInfo; - u_getVersion(versionInfo); - - return (versionInfo[0] << 24) + (versionInfo[1] << 16) + (versionInfo[2] << 8) + versionInfo[3]; -} -#endif diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_idna.c b/src/native/libs/System.HybridGlobalization.Native/pal_idna.c deleted file mode 100644 index ac2b0bbaf2a4b..0000000000000 --- a/src/native/libs/System.HybridGlobalization.Native/pal_idna.c +++ /dev/null @@ -1,99 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// - -#include - -#include "pal_icushim_internal.h" -#include "pal_idna.h" - -#if defined(TARGET_WINDOWS) -// Windows icu headers doesn't define this member as it is marked as deprecated as of ICU 55. -enum { - UIDNA_ALLOW_UNASSIGNED=1 -}; -#endif - -static const uint32_t AllowUnassigned = 0x1; -static const uint32_t UseStd3AsciiRules = 0x2; - -static uint32_t GetOptions(uint32_t flags, uint32_t useToAsciiFlags) -{ - uint32_t options = UIDNA_CHECK_CONTEXTJ; - - if ((flags & AllowUnassigned) == AllowUnassigned) - { - options |= UIDNA_ALLOW_UNASSIGNED; - } - - if ((flags & UseStd3AsciiRules) == UseStd3AsciiRules) - { - options |= UIDNA_USE_STD3_RULES; - } - - if (useToAsciiFlags) - { - options |= UIDNA_NONTRANSITIONAL_TO_ASCII; - } - else - { - options |= UIDNA_NONTRANSITIONAL_TO_UNICODE; - } - - return options; -} - -/* -Function: -ToASCII - -Used by System.Globalization.IdnMapping.GetAsciiCore to convert an Unicode -domain name to ASCII - -Return values: -0: internal error during conversion. ->0: the length of the converted string (not including the null terminator). -*/ -int32_t GlobalizationNative_ToAscii( - uint32_t flags, const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength) -{ - UErrorCode err = U_ZERO_ERROR; - UIDNAInfo info = UIDNA_INFO_INITIALIZER; - - UIDNA* pIdna = uidna_openUTS46(GetOptions(flags, /* useToAsciiFlags */ 1), &err); - - int32_t asciiStrLen = uidna_nameToASCII(pIdna, lpSrc, cwSrcLength, lpDst, cwDstLength, &info, &err); - - // To have a consistent behavior with Windows, we mask out the error when having 2 hyphens in the third and fourth place. - info.errors &= (uint32_t)~UIDNA_ERROR_HYPHEN_3_4; - - uidna_close(pIdna); - - return ((U_SUCCESS(err) || (err == U_BUFFER_OVERFLOW_ERROR)) && (info.errors == 0)) ? asciiStrLen : 0; -} - -/* -Function: -ToUnicode - -Used by System.Globalization.IdnMapping.GetUnicodeCore to convert an ASCII name -to Unicode - -Return values: -0: internal error during conversion. ->0: the length of the converted string (not including the null terminator). -*/ -int32_t GlobalizationNative_ToUnicode( - uint32_t flags, const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength) -{ - UErrorCode err = U_ZERO_ERROR; - UIDNAInfo info = UIDNA_INFO_INITIALIZER; - - UIDNA* pIdna = uidna_openUTS46(GetOptions(flags, /* useToAsciiFlags */ 0), &err); - - int32_t unicodeStrLen = uidna_nameToUnicode(pIdna, lpSrc, cwSrcLength, lpDst, cwDstLength, &info, &err); - - uidna_close(pIdna); - - return ((U_SUCCESS(err) || (err == U_BUFFER_OVERFLOW_ERROR)) && (info.errors == 0)) ? unicodeStrLen : 0; -} diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_idna.h b/src/native/libs/System.HybridGlobalization.Native/pal_idna.h deleted file mode 100644 index d50f90f36ad94..0000000000000 --- a/src/native/libs/System.HybridGlobalization.Native/pal_idna.h +++ /dev/null @@ -1,20 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// - -#pragma once - -#include "pal_locale.h" -#include "pal_compiler.h" - -PALEXPORT int32_t GlobalizationNative_ToAscii(uint32_t flags, - const UChar* lpSrc, - int32_t cwSrcLength, - UChar* lpDst, - int32_t cwDstLength); - -PALEXPORT int32_t GlobalizationNative_ToUnicode(uint32_t flags, - const UChar* lpSrc, - int32_t cwSrcLength, - UChar* lpDst, - int32_t cwDstLength); diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_localeNumberData.h b/src/native/libs/System.HybridGlobalization.Native/pal_localeNumberData.h deleted file mode 100644 index f609c654e1292..0000000000000 --- a/src/native/libs/System.HybridGlobalization.Native/pal_localeNumberData.h +++ /dev/null @@ -1,54 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// - -#pragma once - -#include "pal_locale.h" -#include "pal_compiler.h" - -// Enum that corresponds to managed enum CultureData.LocaleNumberData. -// The numeric values of the enum members match their Win32 counterparts. -typedef enum -{ - LocaleNumber_LanguageId = 0x01, - LocaleNumber_MeasurementSystem = 0x0D, - LocaleNumber_FractionalDigitsCount = 0x00000011, - LocaleNumber_NegativeNumberFormat = 0x00001010, - LocaleNumber_MonetaryFractionalDigitsCount = 0x00000019, - LocaleNumber_PositiveMonetaryNumberFormat = 0x0000001B, - LocaleNumber_NegativeMonetaryNumberFormat = 0x0000001C, - LocaleNumber_FirstDayofWeek = 0x0000100C, - LocaleNumber_FirstWeekOfYear = 0x0000100D, - LocaleNumber_ReadingLayout = 0x00000070, - LocaleNumber_NegativePercentFormat = 0x00000074, - LocaleNumber_PositivePercentFormat = 0x00000075, - LocaleNumber_Digit = 0x00000010, - LocaleNumber_Monetary = 0x00000018 -} LocaleNumberData; - -// Enum that corresponds to managed enum System.Globalization.CalendarWeekRule -typedef enum -{ - WeekRule_FirstDay = 0, - WeekRule_FirstFullWeek = 1, - WeekRule_FirstFourDayWeek = 2 -} CalendarWeekRule; -PALEXPORT int32_t GlobalizationNative_GetLocaleInfoInt(const UChar* localeName, - LocaleNumberData localeNumberData, - int32_t* value); - -PALEXPORT int32_t GlobalizationNative_GetLocaleInfoGroupingSizes(const UChar* localeName, - LocaleNumberData localeGroupingData, - int32_t* primaryGroupSize, - int32_t* secondaryGroupSize); -#if defined(APPLE_HYBRID_GLOBALIZATION) -PALEXPORT int32_t GlobalizationNative_GetLocaleInfoIntNative(const char* localeName, - LocaleNumberData localeNumberData); - -PALEXPORT int32_t GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative(const char* localeName, - LocaleNumberData localeGroupingData); - -PALEXPORT int32_t GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative(const char* localeName, - LocaleNumberData localeGroupingData); -#endif diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_localeStringData.h b/src/native/libs/System.HybridGlobalization.Native/pal_localeStringData.h deleted file mode 100644 index 957021dffa697..0000000000000 --- a/src/native/libs/System.HybridGlobalization.Native/pal_localeStringData.h +++ /dev/null @@ -1,54 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// - -#pragma once - -#include "pal_locale.h" -#include "pal_compiler.h" - -// Enum that corresponds to managed enum CultureData.LocaleStringData. -// The numeric values of the enum members match their Win32 counterparts. -typedef enum -{ - LocaleString_LocalizedDisplayName = 0x02, - LocaleString_EnglishDisplayName = 0x00000072, - LocaleString_NativeDisplayName = 0x00000073, - LocaleString_LocalizedLanguageName = 0x0000006f, - LocaleString_EnglishLanguageName = 0x00001001, - LocaleString_NativeLanguageName = 0x04, - LocaleString_EnglishCountryName = 0x00001002, - LocaleString_NativeCountryName = 0x08, - LocaleString_DecimalSeparator = 0x0E, - LocaleString_ThousandSeparator = 0x0F, - LocaleString_Digits = 0x00000013, - LocaleString_MonetarySymbol = 0x00000014, - LocaleString_CurrencyEnglishName = 0x00001007, - LocaleString_CurrencyNativeName = 0x00001008, - LocaleString_Iso4217MonetarySymbol = 0x00000015, - LocaleString_MonetaryDecimalSeparator = 0x00000016, - LocaleString_MonetaryThousandSeparator = 0x00000017, - LocaleString_AMDesignator = 0x00000028, - LocaleString_PMDesignator = 0x00000029, - LocaleString_PositiveSign = 0x00000050, - LocaleString_NegativeSign = 0x00000051, - LocaleString_Iso639LanguageTwoLetterName = 0x00000059, - LocaleString_Iso639LanguageThreeLetterName = 0x00000067, - LocaleString_Iso3166CountryName = 0x0000005A, - LocaleString_Iso3166CountryName2= 0x00000068, - LocaleString_NaNSymbol = 0x00000069, - LocaleString_PositiveInfinitySymbol = 0x0000006a, - LocaleString_NegativeInfinitySymbol = 0x0000006b, - LocaleString_ParentName = 0x0000006d, - LocaleString_PercentSymbol = 0x00000076, - LocaleString_PerMilleSymbol = 0x00000077 -} LocaleStringData; -PALEXPORT int32_t GlobalizationNative_GetLocaleInfoString(const UChar* localeName, - LocaleStringData localeStringData, - UChar* value, - int32_t valueLength, - const UChar* uiLocaleName); -#if defined(APPLE_HYBRID_GLOBALIZATION) -PALEXPORT const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData, const char* currentUILocaleName); -#endif - diff --git a/src/native/libs/System.HybridGlobalization.Native/pal_locale_internal.h b/src/native/libs/System.HybridGlobalization.Native/pal_locale_internal.h deleted file mode 100644 index c754554bbfdd5..0000000000000 --- a/src/native/libs/System.HybridGlobalization.Native/pal_locale_internal.h +++ /dev/null @@ -1,63 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#pragma once - -#include "pal_icushim_internal.h" - -/* -Function: -UErrorCodeToBool - -Convert an ICU UErrorCode to a Bool compatible with Win32 -Returns 1 for success, 0 otherwise -*/ -int32_t UErrorCodeToBool(UErrorCode code); - -/* -Function: -GetLocale - -Converts a managed localeName into something ICU understands and can use as a localeName. -*/ -int32_t GetLocale(const UChar* localeName, - char* localeNameResult, - int32_t localeNameResultLength, - UBool canonicalize, - UErrorCode* err); - -/* -Function: -u_charsToUChars_safe - -Copies the given null terminated char* to UChar with error checking. Replacement for ICU u_charsToUChars -*/ -void u_charsToUChars_safe(const char* str, UChar* value, int32_t valueLength, UErrorCode* err); - -/* -Function: -FixupLocaleName - -Replace underscores with hyphens to interop with existing .NET code. -Returns the length of the string. -*/ -int32_t FixupLocaleName(UChar* value, int32_t valueLength); - -/* -Function: -DetectDefaultLocaleName - -Detect the default locale for the machine, defaulting to Invaraint if -we can't compute one (different from uloc_getDefault()) would do. -*/ -const char* DetectDefaultLocaleName(void); - -#ifdef __APPLE__ -/* -Function: -DetectDefaultSystemLocaleName - -Detects the default locale string for Apple platforms -*/ -char* DetectDefaultAppleLocaleName(void); -#endif From 7f436a7d8f91dac890fb85ffcadaf8b804d6a3a7 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Wed, 31 Jan 2024 09:44:12 +0100 Subject: [PATCH 22/30] Fix build --- src/native/libs/System.Globalization.Native/pal_common.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/native/libs/System.Globalization.Native/pal_common.h b/src/native/libs/System.Globalization.Native/pal_common.h index 2bb51498f44a1..b621fb0614e5f 100644 --- a/src/native/libs/System.Globalization.Native/pal_common.h +++ b/src/native/libs/System.Globalization.Native/pal_common.h @@ -4,7 +4,7 @@ #pragma once -#if defined(TARGET_UNIX) +// #if defined(TARGET_UNIX) #include "pal_compiler.h" @@ -182,4 +182,4 @@ typedef struct _Range { int32_t length; } Range; -#endif +// #endif From 910d6408a1121b6b4838ece1bd98f12658393020 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Wed, 31 Jan 2024 10:02:49 +0100 Subject: [PATCH 23/30] Fix windows build --- src/native/libs/System.Globalization.Native/pal_common.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/native/libs/System.Globalization.Native/pal_common.h b/src/native/libs/System.Globalization.Native/pal_common.h index b621fb0614e5f..6eb2bb9a29c91 100644 --- a/src/native/libs/System.Globalization.Native/pal_common.h +++ b/src/native/libs/System.Globalization.Native/pal_common.h @@ -4,15 +4,18 @@ #pragma once -// #if defined(TARGET_UNIX) - #include "pal_compiler.h" +#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) + // All ICU headers need to be included here so that all function prototypes are // available before the function pointers are declared below. #include #include #include + +#endif + // calendarData /* * These values should be kept in sync with System.Globalization.CalendarId @@ -181,5 +184,3 @@ typedef struct _Range { int32_t location; int32_t length; } Range; - -// #endif From 7342955a6c35a6d9b493717a518ea78a973a8b29 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Wed, 31 Jan 2024 11:52:38 +0100 Subject: [PATCH 24/30] clean up the code --- .../CMakeLists.txt | 65 +---- .../entrypoints_hg.c | 44 +-- .../pal_calendarData.m | 3 +- .../pal_calendarData_hg.h | 29 +- .../System.Globalization.Native/pal_casing.m | 4 +- .../pal_casing_hg.h | 20 +- .../pal_collation.m | 2 - .../pal_collation_hg.h | 54 ---- .../System.Globalization.Native/pal_hybrid.h | 67 +++-- .../System.Globalization.Native/pal_idna.h | 2 +- .../System.Globalization.Native/pal_locale.m | 4 - .../pal_locale_hg.h | 35 +-- .../pal_locale_hg.m | 4 +- .../pal_normalization.m | 4 +- .../pal_normalization_hg.h | 12 +- .../pal_placeholders.c | 274 ------------------ .../pal_timeZoneInfo.m | 4 +- .../pal_timeZoneInfo_hg.h | 6 +- 18 files changed, 67 insertions(+), 566 deletions(-) delete mode 100644 src/native/libs/System.Globalization.Native/pal_placeholders.c diff --git a/src/native/libs/System.Globalization.Native/CMakeLists.txt b/src/native/libs/System.Globalization.Native/CMakeLists.txt index 4f54b04306e93..b1ffd983d0dc4 100644 --- a/src/native/libs/System.Globalization.Native/CMakeLists.txt +++ b/src/native/libs/System.Globalization.Native/CMakeLists.txt @@ -205,17 +205,7 @@ if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVO pal_common.c ) - if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) - add_definitions(-DAPPLE_HYBRID_GLOBALIZATION) - set(NATIVEGLOBALIZATION_SOURCES - ${NATIVEGLOBALIZATION_SOURCES} - pal_placeholders.c - ) - endif() - - if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) - link_libraries(icucore) - endif() + link_libraries(icucore) if (CMAKE_USE_PTHREADS) add_compile_options(-pthread) @@ -235,26 +225,22 @@ if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVO include_directories(${CMAKE_CURRENT_BINARY_DIR}) elseif (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) add_definitions(-DSTATIC_ICU) - # set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_icushim_static_hybrid.c) set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES}) else() - # set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} pal_icushim.c) set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES}) endif() - if (CLR_CMAKE_TARGET_APPLE) - set(NATIVEGLOBALIZATION_SOURCES_OBJC - pal_locale_hg.m - pal_locale.m - pal_collation.m - pal_casing.m - pal_calendarData.m - pal_normalization.m - pal_timeZoneInfo.m) - set_source_files_properties(${NATIVEGLOBALIZATION_SOURCES_OBJC} PROPERTIES COMPILE_FLAGS "-fobjc-arc ${CLR_CMAKE_COMMON_OBJC_FLAGS}") - set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} ${NATIVEGLOBALIZATION_SOURCES_OBJC}) - endif() + set(NATIVEGLOBALIZATION_SOURCES_OBJC + pal_locale_hg.m + pal_locale.m + pal_collation.m + pal_casing.m + pal_calendarData.m + pal_normalization.m + pal_timeZoneInfo.m) + set_source_files_properties(${NATIVEGLOBALIZATION_SOURCES_OBJC} PROPERTIES COMPILE_FLAGS "-fobjc-arc ${CLR_CMAKE_COMMON_OBJC_FLAGS}") + set(NATIVEGLOBALIZATION_SOURCES ${NATIVEGLOBALIZATION_SOURCES} ${NATIVEGLOBALIZATION_SOURCES_OBJC}) if (MSVC) set_source_files_properties(${NATIVEGLOBALIZATION_SOURCES} PROPERTIES LANGUAGE CXX) @@ -263,10 +249,8 @@ if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVO include_directories("../Common") if (GEN_SHARED_LIB) - if (CLR_CMAKE_TARGET_APPLE) - include(CMakeFindFrameworks) - find_library(FOUNDATION Foundation REQUIRED) - endif() + include(CMakeFindFrameworks) + find_library(FOUNDATION Foundation REQUIRED) add_library(System.HybridGlobalization.Native SHARED @@ -289,29 +273,8 @@ if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVO entrypoints_hg.c ) - if(CLR_CMAKE_TARGET_UNIX) - set_target_properties(System.HybridGlobalization.Native-Static PROPERTIES OUTPUT_NAME System.HybridGlobalization.Native CLEAN_DIRECT_OUTPUT 1) - endif() + set_target_properties(System.HybridGlobalization.Native-Static PROPERTIES OUTPUT_NAME System.HybridGlobalization.Native CLEAN_DIRECT_OUTPUT 1) install (TARGETS System.HybridGlobalization.Native-Static DESTINATION ${STATIC_LIB_DESTINATION} COMPONENT libs) - if(CLR_CMAKE_TARGET_WIN32) - if(STATIC_LIBS_ONLY) - add_library(System.HybridGlobalization.Native.Aot - STATIC - ${NATIVEGLOBALIZATION_SOURCES} - ) - set_target_properties(System.HybridGlobalization.Native.Aot PROPERTIES CLR_CONTROL_FLOW_GUARD OFF) - set_target_properties(System.HybridGlobalization.Native.Aot PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) - - add_library(System.HybridGlobalization.Native.Aot.GuardCF - STATIC - ${NATIVEGLOBALIZATION_SOURCES} - ) - set_target_properties(System.HybridGlobalization.Native.Aot.GuardCF PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) - - install_static_library(System.HybridGlobalization.Native.Aot aotsdk nativeaot) - install_static_library(System.HybridGlobalization.Native.Aot.GuardCF aotsdk nativeaot) - endif() - endif() endif() diff --git a/src/native/libs/System.Globalization.Native/entrypoints_hg.c b/src/native/libs/System.Globalization.Native/entrypoints_hg.c index c46fdcbda436d..528e507e1783a 100644 --- a/src/native/libs/System.Globalization.Native/entrypoints_hg.c +++ b/src/native/libs/System.Globalization.Native/entrypoints_hg.c @@ -17,43 +17,6 @@ typedef uint16_t UChar; static const Entry s_globalizationNative[] = { - DllImportEntry(GlobalizationNative_ChangeCase) - DllImportEntry(GlobalizationNative_ChangeCaseInvariant) - DllImportEntry(GlobalizationNative_ChangeCaseTurkish) - DllImportEntry(GlobalizationNative_CloseSortHandle) - DllImportEntry(GlobalizationNative_CompareString) - DllImportEntry(GlobalizationNative_EndsWith) - DllImportEntry(GlobalizationNative_EnumCalendarInfo) - DllImportEntry(GlobalizationNative_GetCalendarInfo) - DllImportEntry(GlobalizationNative_GetCalendars) - DllImportEntry(GlobalizationNative_GetDefaultLocaleName) - DllImportEntry(GlobalizationNative_GetICUVersion) - DllImportEntry(GlobalizationNative_GetJapaneseEraStartDate) - DllImportEntry(GlobalizationNative_GetLatestJapaneseEra) - DllImportEntry(GlobalizationNative_GetLocaleInfoGroupingSizes) - DllImportEntry(GlobalizationNative_GetLocaleInfoInt) - DllImportEntry(GlobalizationNative_GetLocaleInfoString) - DllImportEntry(GlobalizationNative_GetLocaleName) - DllImportEntry(GlobalizationNative_GetLocales) - DllImportEntry(GlobalizationNative_GetLocaleTimeFormat) - DllImportEntry(GlobalizationNative_GetSortHandle) - DllImportEntry(GlobalizationNative_GetSortKey) - DllImportEntry(GlobalizationNative_GetSortVersion) - DllImportEntry(GlobalizationNative_GetTimeZoneDisplayName) - DllImportEntry(GlobalizationNative_IanaIdToWindowsId) - DllImportEntry(GlobalizationNative_IndexOf) - DllImportEntry(GlobalizationNative_InitICUFunctions) - DllImportEntry(GlobalizationNative_IsNormalized) - DllImportEntry(GlobalizationNative_IsPredefinedLocale) - DllImportEntry(GlobalizationNative_LastIndexOf) - DllImportEntry(GlobalizationNative_LoadICU) -#if defined(STATIC_ICU) - DllImportEntry(GlobalizationNative_LoadICUData) -#endif - DllImportEntry(GlobalizationNative_NormalizeString) - DllImportEntry(GlobalizationNative_StartsWith) - DllImportEntry(GlobalizationNative_WindowsIdToIanaId) -#if defined(APPLE_HYBRID_GLOBALIZATION) DllImportEntry(GlobalizationNative_ChangeCaseInvariantNative) DllImportEntry(GlobalizationNative_ChangeCaseNative) DllImportEntry(GlobalizationNative_CompareStringNative) @@ -76,10 +39,9 @@ static const Entry s_globalizationNative[] = DllImportEntry(GlobalizationNative_IsNormalizedNative) DllImportEntry(GlobalizationNative_NormalizeStringNative) DllImportEntry(GlobalizationNative_StartsWithNative) -#endif - DllImportEntry(GlobalizationNative_ToAscii) - DllImportEntry(GlobalizationNative_ToUnicode) - DllImportEntry(GlobalizationNative_InitOrdinalCasingPage) + DllImportEntry(GlobalizationNative_ToAscii) + DllImportEntry(GlobalizationNative_ToUnicode) + DllImportEntry(GlobalizationNative_InitOrdinalCasingPage) }; EXTERN_C const void* HybridGlobalizationResolveDllImport(const char* name); diff --git a/src/native/libs/System.Globalization.Native/pal_calendarData.m b/src/native/libs/System.Globalization.Native/pal_calendarData.m index d3196350dde25..203a462bd7a65 100644 --- a/src/native/libs/System.Globalization.Native/pal_calendarData.m +++ b/src/native/libs/System.Globalization.Native/pal_calendarData.m @@ -9,7 +9,6 @@ #error This file relies on ARC for memory management, but ARC is not enabled. #endif -#if defined(APPLE_HYBRID_GLOBALIZATION) /* Function: GetCalendarIdentifier @@ -284,4 +283,4 @@ int32_t GlobalizationNative_GetCalendarsNative(const char* localeName, CalendarI return calendarCount; } } -#endif + diff --git a/src/native/libs/System.Globalization.Native/pal_calendarData_hg.h b/src/native/libs/System.Globalization.Native/pal_calendarData_hg.h index e9280c18e3194..817e4eec48e48 100644 --- a/src/native/libs/System.Globalization.Native/pal_calendarData_hg.h +++ b/src/native/libs/System.Globalization.Native/pal_calendarData_hg.h @@ -5,37 +5,10 @@ #include -#include "pal_common.h" #include "pal_locale_hg.h" #include "pal_compiler.h" #include "pal_errors.h" -// the function pointer definition for the callback used in EnumCalendarInfo -typedef void (PAL_CALLBACK_CALLTYPE *EnumCalendarInfoCallback)(const UChar*, const void*); - -PALEXPORT int32_t GlobalizationNative_GetCalendars(const UChar* localeName, - CalendarId* calendars, - int32_t calendarsCapacity); - -PALEXPORT ResultCode GlobalizationNative_GetCalendarInfo(const UChar* localeName, - CalendarId calendarId, - CalendarDataType dataType, - UChar* result, - int32_t resultCapacity); - -PALEXPORT int32_t GlobalizationNative_EnumCalendarInfo(EnumCalendarInfoCallback callback, - const UChar* localeName, - CalendarId calendarId, - CalendarDataType dataType, - const void* context); - -PALEXPORT int32_t GlobalizationNative_GetLatestJapaneseEra(void); - -PALEXPORT int32_t GlobalizationNative_GetJapaneseEraStartDate(int32_t era, - int32_t* startYear, - int32_t* startMonth, - int32_t* startDay); -#if defined(APPLE_HYBRID_GLOBALIZATION) PALEXPORT const char* GlobalizationNative_GetCalendarInfoNative(const char* localeName, CalendarId calendarId, CalendarDataType dataType); @@ -50,4 +23,4 @@ PALEXPORT int32_t GlobalizationNative_GetJapaneseEraStartDateNative(int32_t era, int32_t* startYear, int32_t* startMonth, int32_t* startDay); -#endif + diff --git a/src/native/libs/System.Globalization.Native/pal_casing.m b/src/native/libs/System.Globalization.Native/pal_casing.m index 5a665a897c3be..b6b20bdf02fd9 100644 --- a/src/native/libs/System.Globalization.Native/pal_casing.m +++ b/src/native/libs/System.Globalization.Native/pal_casing.m @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#include "pal_common.h" #include "pal_casing_hg.h" #include "pal_hybrid.h" #include "pal_errors.h" @@ -12,7 +11,6 @@ #error This file relies on ARC for memory management, but ARC is not enabled. #endif -#if defined(APPLE_HYBRID_GLOBALIZATION) /** * Is this code unit a lead surrogate (U+d800..U+dbff)? * @param c 16-bit code unit @@ -148,4 +146,4 @@ int32_t GlobalizationNative_ChangeCaseInvariantNative(const uint16_t* lpSrc, int return Success; } } -#endif + diff --git a/src/native/libs/System.Globalization.Native/pal_casing_hg.h b/src/native/libs/System.Globalization.Native/pal_casing_hg.h index e43304ca21aaf..8e2f1d7b6486e 100644 --- a/src/native/libs/System.Globalization.Native/pal_casing_hg.h +++ b/src/native/libs/System.Globalization.Native/pal_casing_hg.h @@ -4,26 +4,8 @@ #include "pal_locale_hg.h" #include "pal_compiler.h" -PALEXPORT void GlobalizationNative_ChangeCase(const UChar* lpSrc, - int32_t cwSrcLength, - UChar* lpDst, - int32_t cwDstLength, - int32_t bToUpper); - -PALEXPORT void GlobalizationNative_ChangeCaseInvariant(const UChar* lpSrc, - int32_t cwSrcLength, - UChar* lpDst, - int32_t cwDstLength, - int32_t bToUpper); - -PALEXPORT void GlobalizationNative_ChangeCaseTurkish(const UChar* lpSrc, - int32_t cwSrcLength, - UChar* lpDst, - int32_t cwDstLength, - int32_t bToUpper); PALEXPORT void GlobalizationNative_InitOrdinalCasingPage(int32_t pageNumber, UChar* pTarget); -#if defined(APPLE_HYBRID_GLOBALIZATION) PALEXPORT int32_t GlobalizationNative_ChangeCaseNative(const uint16_t* localeName, int32_t lNameLength, const uint16_t* lpSrc, @@ -37,4 +19,4 @@ PALEXPORT int32_t GlobalizationNative_ChangeCaseInvariantNative(const uint16_t* uint16_t* lpDst, int32_t cwDstLength, int32_t bToUpper); -#endif + diff --git a/src/native/libs/System.Globalization.Native/pal_collation.m b/src/native/libs/System.Globalization.Native/pal_collation.m index 4e4440fc56179..337a34494b35b 100644 --- a/src/native/libs/System.Globalization.Native/pal_collation.m +++ b/src/native/libs/System.Globalization.Native/pal_collation.m @@ -11,7 +11,6 @@ #error This file relies on ARC for memory management, but ARC is not enabled. #endif -#if defined(APPLE_HYBRID_GLOBALIZATION) // Enum that corresponds to C# CompareOptions typedef enum { @@ -367,4 +366,3 @@ int32_t GlobalizationNative_GetSortKeyNative(const uint16_t* localeName, int32_t } } -#endif diff --git a/src/native/libs/System.Globalization.Native/pal_collation_hg.h b/src/native/libs/System.Globalization.Native/pal_collation_hg.h index 14dd7e8fdbd27..a0cb893a749e9 100644 --- a/src/native/libs/System.Globalization.Native/pal_collation_hg.h +++ b/src/native/libs/System.Globalization.Native/pal_collation_hg.h @@ -7,59 +7,6 @@ #include "pal_compiler.h" #include "pal_errors.h" -PALEXPORT ResultCode GlobalizationNative_GetSortHandle(const char* lpLocaleName, SortHandle** ppSortHandle); - -PALEXPORT void GlobalizationNative_CloseSortHandle(SortHandle* pSortHandle); - -// If we fail to get the sort version we will fallback to -1 as the sort version. -PALEXPORT int32_t GlobalizationNative_GetSortVersion(SortHandle* pSortHandle); - -PALEXPORT int32_t GlobalizationNative_CompareString(SortHandle* pSortHandle, - const UChar* lpStr1, - int32_t cwStr1Length, - const UChar* lpStr2, - int32_t cwStr2Length, - int32_t options); - -PALEXPORT int32_t GlobalizationNative_IndexOf(SortHandle* pSortHandle, - const UChar* lpTarget, - int32_t cwTargetLength, - const UChar* lpSource, - int32_t cwSourceLength, - int32_t options, - int32_t* pMatchedLength); - -PALEXPORT int32_t GlobalizationNative_LastIndexOf(SortHandle* pSortHandle, - const UChar* lpTarget, - int32_t cwTargetLength, - const UChar* lpSource, - int32_t cwSourceLength, - int32_t options, - int32_t* pMatchedLength); - -PALEXPORT int32_t GlobalizationNative_StartsWith(SortHandle* pSortHandle, - const UChar* lpTarget, - int32_t cwTargetLength, - const UChar* lpSource, - int32_t cwSourceLength, - int32_t options, - int32_t* pMatchedLength); - -PALEXPORT int32_t GlobalizationNative_EndsWith(SortHandle* pSortHandle, - const UChar* lpTarget, - int32_t cwTargetLength, - const UChar* lpSource, - int32_t cwSourceLength, - int32_t options, - int32_t* pMatchedLength); - -PALEXPORT int32_t GlobalizationNative_GetSortKey(SortHandle* pSortHandle, - const UChar* lpStr, - int32_t cwStrLength, - uint8_t* sortKey, - int32_t cbSortKeyLength, - int32_t options); -#if defined(APPLE_HYBRID_GLOBALIZATION) PALEXPORT int32_t GlobalizationNative_CompareStringNative(const uint16_t* localeName, int32_t lNameLength, const uint16_t* lpTarget, @@ -101,4 +48,3 @@ PALEXPORT int32_t GlobalizationNative_GetSortKeyNative(const uint16_t* localeNam int32_t cbSortKeyLength, int32_t options); -#endif diff --git a/src/native/libs/System.Globalization.Native/pal_hybrid.h b/src/native/libs/System.Globalization.Native/pal_hybrid.h index ad4b2d078dd4a..bb7bb4037f7de 100644 --- a/src/native/libs/System.Globalization.Native/pal_hybrid.h +++ b/src/native/libs/System.Globalization.Native/pal_hybrid.h @@ -1,3 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +#pragma once +#include +/** + * Append a code point to a string, overwriting 1 or 2 code units. + * The offset points to the current end of the string contents + * and is advanced (post-increment). + * "Safe" macro, checks for a valid code point. + * Converts code points outside of Basic Multilingual Plane into + * corresponding surrogate pairs if sufficient space in the string. + * High surrogate range: 0xD800 - 0xDBFF + * Low surrogate range: 0xDC00 - 0xDFFF + * If the code point is not valid or a trail surrogate does not fit, + * then isError is set to true. + * + * @param buffer const uint16_t * string buffer + * @param offset string offset, must be offset= (capacity)) /* insufficiently sized destination buffer */ { \ + (isError) = InsufficientBuffer; \ + } else if ((uint32_t)(codePoint) > 0x10ffff) /* invalid code point */ { \ + (isError) = InvalidCodePoint; \ + } else if ((uint32_t)(codePoint) <= 0xffff) { \ + (buffer)[(offset)++] = (uint16_t)(codePoint); \ + } else { \ + (buffer)[(offset)++] = (uint16_t)(((codePoint) >> 10) + 0xd7c0); \ + (buffer)[(offset)++] = (uint16_t)(((codePoint)&0x3ff) | 0xdc00); \ + } \ +} + /* ### Data tables **************************************************/ /** @@ -371,33 +408,3 @@ NULL, NULL }; -/** - * Append a code point to a string, overwriting 1 or 2 code units. - * The offset points to the current end of the string contents - * and is advanced (post-increment). - * "Safe" macro, checks for a valid code point. - * Converts code points outside of Basic Multilingual Plane into - * corresponding surrogate pairs if sufficient space in the string. - * High surrogate range: 0xD800 - 0xDBFF - * Low surrogate range: 0xDC00 - 0xDFFF - * If the code point is not valid or a trail surrogate does not fit, - * then isError is set to true. - * - * @param buffer const uint16_t * string buffer - * @param offset string offset, must be offset= (capacity)) /* insufficiently sized destination buffer */ { \ - (isError) = InsufficientBuffer; \ - } else if ((uint32_t)(codePoint) > 0x10ffff) /* invalid code point */ { \ - (isError) = InvalidCodePoint; \ - } else if ((uint32_t)(codePoint) <= 0xffff) { \ - (buffer)[(offset)++] = (uint16_t)(codePoint); \ - } else { \ - (buffer)[(offset)++] = (uint16_t)(((codePoint) >> 10) + 0xd7c0); \ - (buffer)[(offset)++] = (uint16_t)(((codePoint)&0x3ff) | 0xdc00); \ - } \ -} diff --git a/src/native/libs/System.Globalization.Native/pal_idna.h b/src/native/libs/System.Globalization.Native/pal_idna.h index d50f90f36ad94..6e4c628301632 100644 --- a/src/native/libs/System.Globalization.Native/pal_idna.h +++ b/src/native/libs/System.Globalization.Native/pal_idna.h @@ -4,8 +4,8 @@ #pragma once -#include "pal_locale.h" #include "pal_compiler.h" +#include "pal_locale.h" PALEXPORT int32_t GlobalizationNative_ToAscii(uint32_t flags, const UChar* lpSrc, diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index 5767273c9a3af..c36f33e53044f 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -5,10 +5,6 @@ #include #include "pal_hybrid.h" #include "pal_common.h" -// #include "pal_locale_hybrid.h" -// #include "pal_locale_internal.h" -// #include "pal_localeStringData.h" -// #include "pal_localeNumberData.h" #import #import diff --git a/src/native/libs/System.Globalization.Native/pal_locale_hg.h b/src/native/libs/System.Globalization.Native/pal_locale_hg.h index 99f35f9da244f..0ec2a6e752897 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale_hg.h +++ b/src/native/libs/System.Globalization.Native/pal_locale_hg.h @@ -6,41 +6,13 @@ #include "pal_compiler.h" #include "pal_common.h" -PALEXPORT int32_t GlobalizationNative_GetLocales(UChar *value, int32_t valueLength); - -PALEXPORT int32_t GlobalizationNative_GetLocaleName(const UChar* localeName, UChar* value, int32_t valueLength); - -PALEXPORT int32_t GlobalizationNative_GetDefaultLocaleName(UChar* value, int32_t valueLength); - -PALEXPORT int32_t GlobalizationNative_IsPredefinedLocale(const UChar* localeName); - -PALEXPORT int32_t GlobalizationNative_GetLocaleTimeFormat(const UChar* localeName, - int shortFormat, UChar* value, - int32_t valueLength); -PALEXPORT int32_t GlobalizationNative_GetLocaleInfoInt(const UChar* localeName, - LocaleNumberData localeNumberData, - int32_t* value); - -PALEXPORT int32_t GlobalizationNative_GetLocaleInfoGroupingSizes(const UChar* localeName, - LocaleNumberData localeGroupingData, - int32_t* primaryGroupSize, - int32_t* secondaryGroupSize); -PALEXPORT int32_t GlobalizationNative_GetLocaleInfoString(const UChar* localeName, - LocaleStringData localeStringData, - UChar* value, - int32_t valueLength, - const UChar* uiLocaleName); -#if defined(APPLE_HYBRID_GLOBALIZATION) PALEXPORT const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData, const char* currentUILocaleName); -PALEXPORT int32_t GlobalizationNative_GetLocaleInfoIntNative(const char* localeName, - LocaleNumberData localeNumberData); +PALEXPORT int32_t GlobalizationNative_GetLocaleInfoIntNative(const char* localeName, LocaleNumberData localeNumberData); -PALEXPORT int32_t GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative(const char* localeName, - LocaleNumberData localeGroupingData); +PALEXPORT int32_t GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative(const char* localeName, LocaleNumberData localeGroupingData); -PALEXPORT int32_t GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative(const char* localeName, - LocaleNumberData localeGroupingData); +PALEXPORT int32_t GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative(const char* localeName, LocaleNumberData localeGroupingData); PALEXPORT const char* GlobalizationNative_GetDefaultLocaleNameNative(void); @@ -52,4 +24,3 @@ PALEXPORT int32_t GlobalizationNative_GetLocalesNative(UChar* locales, int32_t l PALEXPORT int32_t GlobalizationNative_IsPredefinedLocaleNative(const char* localeName); -#endif diff --git a/src/native/libs/System.Globalization.Native/pal_locale_hg.m b/src/native/libs/System.Globalization.Native/pal_locale_hg.m index 181bd95b93d83..840c3392298df 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale_hg.m +++ b/src/native/libs/System.Globalization.Native/pal_locale_hg.m @@ -5,7 +5,6 @@ #include #include "pal_hybrid.h" #include "pal_locale_hg.h" -// #include "pal_locale_internal.h" #include "pal_localeStringData.h" #include "pal_localeNumberData.h" @@ -16,7 +15,6 @@ #error This file relies on ARC for memory management, but ARC is not enabled. #endif -#if defined(APPLE_HYBRID_GLOBALIZATION) const char* GlobalizationNative_GetLocaleNameNative(const char* localeName) { @autoreleasepool @@ -796,4 +794,4 @@ int32_t GlobalizationNative_IsPredefinedLocaleNative(const char* localeName) return false; } } -#endif + diff --git a/src/native/libs/System.Globalization.Native/pal_normalization.m b/src/native/libs/System.Globalization.Native/pal_normalization.m index b764debc5c103..efb436128bc85 100644 --- a/src/native/libs/System.Globalization.Native/pal_normalization.m +++ b/src/native/libs/System.Globalization.Native/pal_normalization.m @@ -3,7 +3,6 @@ // #include "pal_errors.h" -#include "pal_common.h" #include "pal_hybrid.h" #include "pal_normalization_hg.h" #import @@ -12,7 +11,6 @@ #error This file relies on ARC for memory management, but ARC is not enabled. #endif -#if defined(APPLE_HYBRID_GLOBALIZATION) static NSString* GetNormalizedStringForForm(NormalizationForm normalizationForm, NSString* sourceString) { switch (normalizationForm) @@ -88,5 +86,5 @@ int32_t GlobalizationNative_NormalizeStringNative(NormalizationForm normalizatio return !isError ? [normalizedString length] : 0; } } -#endif + diff --git a/src/native/libs/System.Globalization.Native/pal_normalization_hg.h b/src/native/libs/System.Globalization.Native/pal_normalization_hg.h index 2ecd338b11cb8..dd21f88d717c0 100644 --- a/src/native/libs/System.Globalization.Native/pal_normalization_hg.h +++ b/src/native/libs/System.Globalization.Native/pal_normalization_hg.h @@ -7,16 +7,6 @@ #include "pal_locale_hg.h" #include "pal_compiler.h" -PALEXPORT int32_t GlobalizationNative_IsNormalized(NormalizationForm normalizationForm, - const UChar* lpStr, - int32_t cwStrLength); - -PALEXPORT int32_t GlobalizationNative_NormalizeString(NormalizationForm normalizationForm, - const UChar* lpSrc, - int32_t cwSrcLength, - UChar* lpDst, - int32_t cwDstLength); -#if defined(APPLE_HYBRID_GLOBALIZATION) PALEXPORT int32_t GlobalizationNative_IsNormalizedNative(NormalizationForm normalizationForm, const uint16_t* lpStr, int32_t cwStrLength); @@ -26,4 +16,4 @@ PALEXPORT int32_t GlobalizationNative_NormalizeStringNative(NormalizationForm no int32_t cwSourceLength, uint16_t* lpDst, int32_t cwDstLength); -#endif + diff --git a/src/native/libs/System.Globalization.Native/pal_placeholders.c b/src/native/libs/System.Globalization.Native/pal_placeholders.c deleted file mode 100644 index 55afa062dbc9b..0000000000000 --- a/src/native/libs/System.Globalization.Native/pal_placeholders.c +++ /dev/null @@ -1,274 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#include -#include - -#include "pal_common.h" -#include "pal_icushim.h" -#include "pal_calendarData_hg.h" -#include "pal_casing_hg.h" -#include "pal_collation_hg.h" -#include "pal_locale_hg.h" -#include "pal_normalization_hg.h" -#include "pal_timeZoneInfo_hg.h" - -#ifdef DEBUG -#define assert_err(cond, msg, err) do \ -{ \ - if(!(cond)) \ - { \ - fprintf(stderr, "%s (%d): error %d: %s. %s (%s failed)\n", __FILE__, __LINE__, err, msg, strerror(err), #cond); \ - assert(false && "assert_err failed"); \ - } \ -} while(0) -#define assert_msg(cond, msg, val) do \ -{ \ - if(!(cond)) \ - { \ - fprintf(stderr, "%s (%d): error %d: %s (%s failed)\n", __FILE__, __LINE__, val, msg, #cond); \ - assert(false && "assert_msg failed"); \ - } \ -} while(0) -#else // DEBUG -#define assert_err(cond, msg, err) -#define assert_msg(cond, msg, val) -#endif // DEBUG - - -// Placeholder for calendar data -int32_t GlobalizationNative_GetCalendars( - const UChar* localeName, CalendarId* calendars, int32_t calendarsCapacity) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -ResultCode GlobalizationNative_GetCalendarInfo( - const UChar* localeName, CalendarId calendarId, CalendarDataType dataType, UChar* result, int32_t resultCapacity) -{ - assert_msg(false, "Not supported on this platform", 0); - return UnknownError; -} - -int32_t GlobalizationNative_EnumCalendarInfo( - EnumCalendarInfoCallback callback, const UChar* localeName, CalendarId calendarId, CalendarDataType dataType, const void* context) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_GetLatestJapaneseEra(void) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_GetJapaneseEraStartDate( - int32_t era, int32_t* startYear, int32_t* startMonth, int32_t* startDay) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -// Placeholder for casing data -void GlobalizationNative_ChangeCase( - const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength, int32_t bToUpper) -{ - assert_msg(false, "Not supported on this platform", 0); -} - -void GlobalizationNative_ChangeCaseInvariant( - const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength, int32_t bToUpper) -{ - assert_msg(false, "Not supported on this platform", 0); -} - -void GlobalizationNative_ChangeCaseTurkish( - const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength, int32_t bToUpper) -{ - assert_msg(false, "Not supported on this platform", 0); -} - -// Placeholder for collation data -ResultCode GlobalizationNative_GetSortHandle( - const char* lpLocaleName, SortHandle** pSortHandle) -{ - assert_msg(false, "Not supported on this platform", 0); - return UnknownError; -} - -void GlobalizationNative_CloseSortHandle(SortHandle* pSortHandle) -{ - assert_msg(false, "Not supported on this platform", 0); -} - -int32_t GlobalizationNative_GetSortVersion(SortHandle* pSortHandle) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_CompareString( - SortHandle* pSortHandle, const UChar* lpStr1, int32_t cwStr1Length, const UChar* lpStr2, int32_t cwStr2Length, int32_t options) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_IndexOf( - SortHandle* pSortHandle, const UChar* lpTarget, int32_t cwTargetLength, const UChar* lpSource, int32_t cwSourceLength, int32_t options, int32_t* pMatchedLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_LastIndexOf( - SortHandle* pSortHandle, const UChar* lpTarget, int32_t cwTargetLength, const UChar* lpSource, int32_t cwSourceLength, int32_t options, int32_t* pMatchedLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_StartsWith( - SortHandle* pSortHandle, const UChar* lpTarget, int32_t cwTargetLength, const UChar* lpSource, int32_t cwSourceLength, int32_t options, int32_t* pMatchedLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_EndsWith( - SortHandle* pSortHandle, const UChar* lpTarget, int32_t cwTargetLength, const UChar* lpSource, int32_t cwSourceLength, int32_t options, int32_t* pMatchedLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_GetSortKey( - SortHandle* pSortHandle, const UChar* lpStr, int32_t cwStrLength, uint8_t* sortKey, int32_t cbSortKeyLength, int32_t options) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -// Placeholder for locale data -int32_t GlobalizationNative_GetLocales( - UChar *value, int32_t valueLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_GetLocaleName( - const UChar* localeName, UChar* value, int32_t valueLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_GetDefaultLocaleName( - UChar* value, int32_t valueLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_IsPredefinedLocale( - const UChar* localeName) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_GetLocaleTimeFormat( - const UChar* localeName, int shortFormat, UChar* value, int32_t valueLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -// Placeholder for locale number data -int32_t GlobalizationNative_GetLocaleInfoInt( - const UChar* localeName, LocaleNumberData localeNumberData, int32_t* value) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_GetLocaleInfoGroupingSizes( - const UChar* localeName, LocaleNumberData localeGroupingData, int32_t* primaryGroupSize, int32_t* secondaryGroupSize) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -// Placeholder for icu shim data -int32_t GlobalizationNative_LoadICU(void) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -void GlobalizationNative_InitICUFunctions( - void* icuuc, void* icuin, const char* version, const char* suffix) -{ - assert_msg(false, "Not supported on this platform", 0); -} - -int32_t GlobalizationNative_GetICUVersion(void) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t -GlobalizationNative_LoadICUData(const char* path) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -// Placeholder for locale string data -int32_t GlobalizationNative_GetLocaleInfoString( - const UChar* localeName, LocaleStringData localeStringData, UChar* value, int32_t valueLength, const UChar* uiLocaleName) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -//Placeholder for normalization data -int32_t GlobalizationNative_IsNormalized( - NormalizationForm normalizationForm, const UChar* lpStr, int32_t cwStrLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -int32_t GlobalizationNative_NormalizeString( - NormalizationForm normalizationForm, const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -// Placeholder for time zone data -int32_t GlobalizationNative_WindowsIdToIanaId( - const UChar* windowsId, const char* region, UChar* ianaId, int32_t ianaIdLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} - -ResultCode GlobalizationNative_GetTimeZoneDisplayName( - const UChar* localeName, const UChar* timeZoneId, TimeZoneDisplayNameType type, UChar* result, int32_t resultLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return UnknownError; -} - -int32_t GlobalizationNative_IanaIdToWindowsId( - const UChar* ianaId, UChar* windowsId, int32_t windowsIdLength) -{ - assert_msg(false, "Not supported on this platform", 0); - return 0; -} diff --git a/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.m b/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.m index e0ccac384d35a..78b2e20d2ac44 100644 --- a/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.m +++ b/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.m @@ -3,7 +3,6 @@ // #include "pal_errors_internal.h" -#include "pal_common.h" #include "pal_hybrid.h" #include "pal_timeZoneInfo_hg.h" #import @@ -12,7 +11,6 @@ #error This file relies on ARC for memory management, but ARC is not enabled. #endif -#if defined(APPLE_HYBRID_GLOBALIZATION) /* Gets the localized display name that is currently in effect for the specified time zone. */ @@ -83,4 +81,4 @@ int32_t GlobalizationNative_GetTimeZoneDisplayNameNative(const uint16_t* localeN return resultCode; } } -#endif + diff --git a/src/native/libs/System.Globalization.Native/pal_timeZoneInfo_hg.h b/src/native/libs/System.Globalization.Native/pal_timeZoneInfo_hg.h index 11490da482940..a56f1ebec9d6d 100644 --- a/src/native/libs/System.Globalization.Native/pal_timeZoneInfo_hg.h +++ b/src/native/libs/System.Globalization.Native/pal_timeZoneInfo_hg.h @@ -8,11 +8,7 @@ #include "pal_compiler.h" #include "pal_errors.h" -PALEXPORT int32_t GlobalizationNative_WindowsIdToIanaId(const UChar* windowsId, const char* region, UChar* ianaId, int32_t ianaIdLength); -PALEXPORT int32_t GlobalizationNative_IanaIdToWindowsId(const UChar* ianaId, UChar* windowsId, int32_t windowsIdLength); -PALEXPORT ResultCode GlobalizationNative_GetTimeZoneDisplayName(const UChar* localeName, const UChar* timeZoneId, TimeZoneDisplayNameType type, UChar* result, int32_t resultLength); -#if defined(APPLE_HYBRID_GLOBALIZATION) PALEXPORT int32_t GlobalizationNative_GetTimeZoneDisplayNameNative(const uint16_t* localeName, int32_t lNameLength, const uint16_t* timeZoneId, int32_t timeZoneIdLength, TimeZoneDisplayNameType type, uint16_t* result, int32_t resultLength); -#endif + From 23f15fb004eb1fe1422d673757b317bcb28aff7a Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Wed, 31 Jan 2024 12:02:46 +0100 Subject: [PATCH 25/30] clean up the code, test both ICU and hybrid on CI --- eng/testing/tests.ioslike.targets | 2 +- .../System.Globalization.Tests.csproj | 1 + .../tests/System.Runtime.Tests/System.Runtime.Tests.csproj | 1 + .../libs/System.Globalization.Native/pal_icushim_internal.h | 2 +- .../libs/System.Globalization.Native/pal_icushim_static.c | 2 -- src/native/libs/System.Globalization.Native/pal_idna.h | 2 +- .../libs/System.Globalization.Native/pal_locale_internal.h | 2 +- src/native/libs/System.Globalization.Native/pal_normalization.c | 2 +- .../libs/System.Globalization.Native/pal_normalization_hg.h | 2 +- .../libs/System.Globalization.Native/pal_timeZoneInfo_hg.h | 2 +- 10 files changed, 9 insertions(+), 9 deletions(-) diff --git a/eng/testing/tests.ioslike.targets b/eng/testing/tests.ioslike.targets index d4dfbe3ebe1e4..73ce3e606a94f 100644 --- a/eng/testing/tests.ioslike.targets +++ b/eng/testing/tests.ioslike.targets @@ -159,7 +159,7 @@ - true + true true AppleTestRunner.dll diff --git a/src/libraries/System.Runtime/tests/System.Globalization.Tests/System.Globalization.Tests.csproj b/src/libraries/System.Runtime/tests/System.Globalization.Tests/System.Globalization.Tests.csproj index e83591144f8b2..c91a17ab0428a 100644 --- a/src/libraries/System.Runtime/tests/System.Globalization.Tests/System.Globalization.Tests.csproj +++ b/src/libraries/System.Runtime/tests/System.Globalization.Tests/System.Globalization.Tests.csproj @@ -8,6 +8,7 @@ true + true diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System.Runtime.Tests.csproj b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System.Runtime.Tests.csproj index 6514d08c8f284..1ab64d15dc6da 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System.Runtime.Tests.csproj +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System.Runtime.Tests.csproj @@ -16,6 +16,7 @@ true true + true - true true AppleTestRunner.dll diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs index 639aea29c8a77..3701ccd7bf6fc 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs @@ -14,7 +14,7 @@ private static partial class Settings { internal static bool Invariant { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.Invariant", "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT"); -#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS || TARGET_BROWSER +#if TARGET_BROWSER internal static bool Hybrid { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.Hybrid", "DOTNET_SYSTEM_GLOBALIZATION_HYBRID"); #endif internal static bool PredefinedCulturesOnly { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.PredefinedCulturesOnly", "DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY", GlobalizationMode.Invariant); @@ -24,7 +24,19 @@ private static partial class Settings // This allows for the whole Settings nested class to be trimmed when Invariant=true, and allows for the Settings // static cctor (on Unix) to be preserved when Invariant=false. internal static bool Invariant => Settings.Invariant; -#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS || TARGET_BROWSER +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS + private static bool GetHybridGlobalizationSwitchValue() { + if (Settings.Invariant) + return false; + string? value; + TryGetStringValue("System.Globalization.Hybrid", "DOTNET_SYSTEM_GLOBALIZATION_HYBRID", out value); + if (value == null || value == "1") + return true; + return false; + } + + internal static bool Hybrid => GetHybridGlobalizationSwitchValue(); +#elif TARGET_BROWSER internal static bool Hybrid => Settings.Hybrid; #endif internal static bool PredefinedCulturesOnly => Settings.PredefinedCulturesOnly; diff --git a/src/libraries/System.Runtime/tests/System.Globalization.Extensions.Tests/System.Globalization.Extensions.Tests.csproj b/src/libraries/System.Runtime/tests/System.Globalization.Extensions.Tests/System.Globalization.Extensions.Tests.csproj index 58d424e4778cd..a46fcb9968ef5 100644 --- a/src/libraries/System.Runtime/tests/System.Globalization.Extensions.Tests/System.Globalization.Extensions.Tests.csproj +++ b/src/libraries/System.Runtime/tests/System.Globalization.Extensions.Tests/System.Globalization.Extensions.Tests.csproj @@ -2,6 +2,7 @@ $(NetCoreAppCurrent) true + false diff --git a/src/libraries/System.Runtime/tests/System.Globalization.Tests/System.Globalization.Tests.csproj b/src/libraries/System.Runtime/tests/System.Globalization.Tests/System.Globalization.Tests.csproj index c91a17ab0428a..e83591144f8b2 100644 --- a/src/libraries/System.Runtime/tests/System.Globalization.Tests/System.Globalization.Tests.csproj +++ b/src/libraries/System.Runtime/tests/System.Globalization.Tests/System.Globalization.Tests.csproj @@ -8,7 +8,6 @@ true - true diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System.Runtime.Tests.csproj b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System.Runtime.Tests.csproj index 1ab64d15dc6da..6514d08c8f284 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System.Runtime.Tests.csproj +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System.Runtime.Tests.csproj @@ -16,7 +16,6 @@ true true - true