44//! Bindings to the ICU library.
55
66use std:: cmp:: Ordering ;
7- use std:: ffi:: CStr ;
7+ use std:: ffi:: { CStr , c_char } ;
88use std:: mem;
99use std:: mem:: MaybeUninit ;
1010use std:: ops:: Range ;
@@ -904,32 +904,38 @@ struct LibraryFunctions {
904904 uregex_end64 : icu_ffi:: uregex_end64 ,
905905}
906906
907+ macro_rules! proc_name {
908+ ( $s: literal) => {
909+ concat!( $s, env!( "EDIT_CFG_ICU_RENAMING_VERSION" ) , "\0 " ) . as_ptr( ) as * const c_char
910+ } ;
911+ }
912+
907913// Found in libicuuc.so on UNIX, icuuc.dll/icu.dll on Windows.
908- const LIBICUUC_PROC_NAMES : [ & CStr ; 10 ] = [
909- c "u_errorName",
910- c "ucasemap_open",
911- c "ucasemap_utf8FoldCase",
912- c "ucnv_getAvailableName",
913- c "ucnv_getStandardName",
914- c "ucnv_open",
915- c "ucnv_close",
916- c "ucnv_convertEx",
917- c "utext_setup",
918- c "utext_close",
914+ const LIBICUUC_PROC_NAMES : [ * const c_char ; 10 ] = [
915+ proc_name ! ( "u_errorName" ) ,
916+ proc_name ! ( "ucasemap_open" ) ,
917+ proc_name ! ( "ucasemap_utf8FoldCase" ) ,
918+ proc_name ! ( "ucnv_getAvailableName" ) ,
919+ proc_name ! ( "ucnv_getStandardName" ) ,
920+ proc_name ! ( "ucnv_open" ) ,
921+ proc_name ! ( "ucnv_close" ) ,
922+ proc_name ! ( "ucnv_convertEx" ) ,
923+ proc_name ! ( "utext_setup" ) ,
924+ proc_name ! ( "utext_close" ) ,
919925] ;
920926
921927// Found in libicui18n.so on UNIX, icuin.dll/icu.dll on Windows.
922- const LIBICUI18N_PROC_NAMES : [ & CStr ; 10 ] = [
923- c "ucol_open",
924- c "ucol_strcollUTF8",
925- c "uregex_open",
926- c "uregex_close",
927- c "uregex_setTimeLimit",
928- c "uregex_setUText",
929- c "uregex_reset64",
930- c "uregex_findNext",
931- c "uregex_start64",
932- c "uregex_end64",
928+ const LIBICUI18N_PROC_NAMES : [ * const c_char ; 10 ] = [
929+ proc_name ! ( "ucol_open" ) ,
930+ proc_name ! ( "ucol_strcollUTF8" ) ,
931+ proc_name ! ( "uregex_open" ) ,
932+ proc_name ! ( "uregex_close" ) ,
933+ proc_name ! ( "uregex_setTimeLimit" ) ,
934+ proc_name ! ( "uregex_setUText" ) ,
935+ proc_name ! ( "uregex_reset64" ) ,
936+ proc_name ! ( "uregex_findNext" ) ,
937+ proc_name ! ( "uregex_start64" ) ,
938+ proc_name ! ( "uregex_end64" ) ,
933939] ;
934940
935941enum LibraryFunctionsState {
@@ -952,10 +958,7 @@ fn init_if_needed() -> apperr::Result<&'static LibraryFunctions> {
952958 unsafe {
953959 LIBRARY_FUNCTIONS = LibraryFunctionsState :: Failed ;
954960
955- let Ok ( libicuuc) = sys:: load_libicuuc ( ) else {
956- return ;
957- } ;
958- let Ok ( libicui18n) = sys:: load_libicui18n ( ) else {
961+ let Ok ( icu) = sys:: load_icu ( ) else {
959962 return ;
960963 } ;
961964
@@ -979,25 +982,26 @@ fn init_if_needed() -> apperr::Result<&'static LibraryFunctions> {
979982 let mut funcs = MaybeUninit :: < LibraryFunctions > :: uninit ( ) ;
980983 let mut ptr = funcs. as_mut_ptr ( ) as * mut TransparentFunction ;
981984
982- #[ cfg( unix ) ]
985+ #[ cfg( edit_icu_renaming_auto_detect ) ]
983986 let scratch_outer = scratch_arena ( None ) ;
984- #[ cfg( unix) ]
985- let suffix = sys:: icu_proc_suffix ( & scratch_outer, libicuuc) ;
986-
987- for ( handle, names) in
988- [ ( libicuuc, & LIBICUUC_PROC_NAMES [ ..] ) , ( libicui18n, & LIBICUI18N_PROC_NAMES [ ..] ) ]
989- {
990- for name in names {
991- #[ cfg( unix) ]
987+ #[ cfg( edit_icu_renaming_auto_detect) ]
988+ let suffix = sys:: icu_detect_renaming_suffix ( & scratch_outer, icu. libicuuc ) ;
989+
990+ for ( handle, names) in [
991+ ( icu. libicuuc , & LIBICUUC_PROC_NAMES [ ..] ) ,
992+ ( icu. libicui18n , & LIBICUI18N_PROC_NAMES [ ..] ) ,
993+ ] {
994+ for & name in names {
995+ #[ cfg( edit_icu_renaming_auto_detect) ]
992996 let scratch = scratch_arena ( Some ( & scratch_outer) ) ;
993- #[ cfg( unix ) ]
994- let name = & sys:: add_icu_proc_suffix ( & scratch, name, & suffix) ;
997+ #[ cfg( edit_icu_renaming_auto_detect ) ]
998+ let name = sys:: icu_add_renaming_suffix ( & scratch, name, & suffix) ;
995999
9961000 let Ok ( func) = sys:: get_proc_address ( handle, name) else {
9971001 debug_assert ! (
9981002 false ,
999- "Failed to load ICU function: {}" ,
1000- name . to_string_lossy ( )
1003+ "Failed to load ICU function: {:? }" ,
1004+ CStr :: from_ptr ( name )
10011005 ) ;
10021006 return ;
10031007 } ;
@@ -1293,6 +1297,12 @@ mod icu_ffi {
12931297mod tests {
12941298 use super :: * ;
12951299
1300+ #[ ignore]
1301+ #[ test]
1302+ fn init ( ) {
1303+ assert ! ( init_if_needed( ) . is_ok( ) ) ;
1304+ }
1305+
12961306 #[ test]
12971307 fn test_compare_strings_ascii ( ) {
12981308 // Empty strings
0 commit comments