@@ -179,7 +179,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
179
179
let this = self . eval_context_ref ( ) ;
180
180
let os_str: & ' a OsStr = this. read_os_str_from_c_str ( scalar) ?;
181
181
182
- Ok ( match convert_path_separator ( os_str, & this. tcx . sess . target . target . target_os ) {
182
+ Ok ( match convert_path_separator ( os_str, & this. tcx . sess . target . target . target_os , false ) {
183
183
Cow :: Borrowed ( x) => Cow :: Borrowed ( Path :: new ( x) ) ,
184
184
Cow :: Owned ( y) => Cow :: Owned ( PathBuf :: from ( y) ) ,
185
185
} )
@@ -190,7 +190,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
190
190
let this = self . eval_context_ref ( ) ;
191
191
let os_str: OsString = this. read_os_str_from_wide_str ( scalar) ?;
192
192
193
- Ok ( PathBuf :: from ( & convert_path_separator ( & os_str, & this. tcx . sess . target . target . target_os ) ) )
193
+ Ok ( PathBuf :: from ( & convert_path_separator ( & os_str, & this. tcx . sess . target . target . target_os , false ) ) )
194
194
}
195
195
196
196
/// Write a Path to the machine memory (as a null-terminated sequence of bytes),
@@ -202,7 +202,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
202
202
size : u64 ,
203
203
) -> InterpResult < ' tcx , ( bool , u64 ) > {
204
204
let this = self . eval_context_mut ( ) ;
205
- let os_str = convert_path_separator ( path. as_os_str ( ) , & this. tcx . sess . target . target . target_os ) ;
205
+ let os_str = convert_path_separator ( path. as_os_str ( ) , & this. tcx . sess . target . target . target_os , true ) ;
206
206
this. write_os_str_to_c_str ( & os_str, scalar, size)
207
207
}
208
208
@@ -215,35 +215,40 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
215
215
size : u64 ,
216
216
) -> InterpResult < ' tcx , ( bool , u64 ) > {
217
217
let this = self . eval_context_mut ( ) ;
218
- let os_str = convert_path_separator ( path. as_os_str ( ) , & this. tcx . sess . target . target . target_os ) ;
218
+ let os_str = convert_path_separator ( path. as_os_str ( ) , & this. tcx . sess . target . target . target_os , true ) ;
219
219
this. write_os_str_to_wide_str ( & os_str, scalar, size)
220
220
}
221
221
}
222
222
223
223
/// Perform path separator conversion if needed.
224
+ /// if direction == true, Convert from 'host' to 'target'.
225
+ /// if direction == false, Convert from 'target' to 'host'.
224
226
fn convert_path_separator < ' a > (
225
227
os_str : & ' a OsStr ,
226
228
target_os : & str ,
229
+ direction : bool ,
227
230
) -> Cow < ' a , OsStr > {
228
231
#[ cfg( windows) ]
229
232
return if target_os == "windows" {
230
233
// Windows-on-Windows, all fine.
231
234
Cow :: Borrowed ( os_str)
232
235
} else {
233
- // Unix target, Windows host. Need to convert host '\\' to target '/'.
236
+ // Unix target, Windows host.
237
+ let ( from, to) = if direction { ( '\\' , '/' ) } else { ( '/' , '\\' ) } ;
234
238
let converted = os_str
235
239
. encode_wide ( )
236
- . map ( |wchar| if wchar == '\\' as u16 { '/' as u16 } else { wchar } )
240
+ . map ( |wchar| if wchar == from as u16 { to as u16 } else { wchar } )
237
241
. collect :: < Vec < _ > > ( ) ;
238
242
Cow :: Owned ( OsString :: from_wide ( & converted) )
239
243
} ;
240
244
#[ cfg( unix) ]
241
245
return if target_os == "windows" {
242
- // Windows target, Unix host. Need to convert host '/' to target '\'.
246
+ // Windows target, Unix host.
247
+ let ( from, to) = if direction { ( '/' , '\\' ) } else { ( '\\' , '/' ) } ;
243
248
let converted = os_str
244
249
. as_bytes ( )
245
250
. iter ( )
246
- . map ( |& wchar| if wchar == '/' as u8 { '\\' as u8 } else { wchar } )
251
+ . map ( |& wchar| if wchar == from as u8 { to as u8 } else { wchar } )
247
252
. collect :: < Vec < _ > > ( ) ;
248
253
Cow :: Owned ( OsString :: from_vec ( converted) )
249
254
} else {
0 commit comments