@@ -1122,10 +1122,18 @@ pub(crate) mod module {
11221122 }
11231123
11241124 #[ pyfunction]
1125- fn _path_splitroot ( path : OsPath , vm : & VirtualMachine ) -> PyResult < ( String , String ) > {
1125+ fn _path_splitroot (
1126+ path : OsPath ,
1127+ _vm : & VirtualMachine ,
1128+ ) -> (
1129+ rustpython_common:: wtf8:: Wtf8Buf ,
1130+ rustpython_common:: wtf8:: Wtf8Buf ,
1131+ ) {
1132+ use rustpython_common:: wtf8:: Wtf8Buf ;
1133+
11261134 let orig: Vec < _ > = path. path . to_wide ( ) ;
11271135 if orig. is_empty ( ) {
1128- return Ok ( ( "" . to_owned ( ) , "" . to_owned ( ) ) ) ;
1136+ return ( Wtf8Buf :: new ( ) , Wtf8Buf :: new ( ) ) ;
11291137 }
11301138 let backslashed: Vec < _ > = orig
11311139 . iter ( )
@@ -1134,15 +1142,11 @@ pub(crate) mod module {
11341142 . chain ( std:: iter:: once ( 0 ) ) // null-terminated
11351143 . collect ( ) ;
11361144
1137- fn from_utf16 ( wstr : & [ u16 ] , vm : & VirtualMachine ) -> PyResult < String > {
1138- String :: from_utf16 ( wstr) . map_err ( |e| vm. new_unicode_decode_error ( e. to_string ( ) ) )
1139- }
1140-
11411145 let mut end: * const u16 = std:: ptr:: null ( ) ;
11421146 let hr = unsafe {
11431147 windows_sys:: Win32 :: UI :: Shell :: PathCchSkipRoot ( backslashed. as_ptr ( ) , & mut end)
11441148 } ;
1145- let ( root , path ) = if hr == 0 {
1149+ if hr == 0 {
11461150 // S_OK
11471151 assert ! ( !end. is_null( ) ) ;
11481152 let len: usize = unsafe { end. offset_from ( backslashed. as_ptr ( ) ) }
@@ -1155,11 +1159,13 @@ pub(crate) mod module {
11551159 len,
11561160 backslashed. len( )
11571161 ) ;
1158- ( from_utf16 ( & orig[ ..len] , vm) ?, from_utf16 ( & orig[ len..] , vm) ?)
1162+ (
1163+ Wtf8Buf :: from_wide ( & orig[ ..len] ) ,
1164+ Wtf8Buf :: from_wide ( & orig[ len..] ) ,
1165+ )
11591166 } else {
1160- ( "" . to_owned ( ) , from_utf16 ( & orig, vm) ?)
1161- } ;
1162- Ok ( ( root, path) )
1167+ ( Wtf8Buf :: new ( ) , Wtf8Buf :: from_wide ( & orig) )
1168+ }
11631169 }
11641170
11651171 #[ pyfunction]
0 commit comments