@@ -463,18 +463,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
463
463
}
464
464
}
465
465
466
- /// Dispatches to appropriate implementations for reading an OsString from Memory,
467
- /// depending on the interpretation target.
468
- /// FIXME: Use `Cow` to avoid copies
469
- fn read_os_str_from_target_str ( & self , scalar : Scalar < Tag > ) -> InterpResult < ' tcx , OsString > {
470
- let target_os = self . eval_context_ref ( ) . tcx . sess . target . target . target_os . as_str ( ) ;
471
- match target_os {
472
- "linux" | "macos" => self . read_os_str_from_c_str ( scalar) . map ( |x| x. to_os_string ( ) ) ,
473
- "windows" => self . read_os_str_from_wide_str ( scalar) ,
474
- unsupported => throw_unsup_format ! ( "OsString support for target OS `{}` not yet available" , unsupported) ,
475
- }
476
- }
477
-
478
466
/// Helper function to read an OsString from a null-terminated sequence of bytes, which is what
479
467
/// the Unix APIs usually handle.
480
468
fn read_os_str_from_c_str < ' a > ( & ' a self , scalar : Scalar < Tag > ) -> InterpResult < ' tcx , & ' a OsStr >
@@ -567,7 +555,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
567
555
fn write_os_str_to_wide_str (
568
556
& mut self ,
569
557
os_str : & OsStr ,
570
- mplace : MPlaceTy < ' tcx , Tag > ,
558
+ scalar : Scalar < Tag > ,
571
559
size : u64 ,
572
560
) -> InterpResult < ' tcx , ( bool , u64 ) > {
573
561
#[ cfg( windows) ]
@@ -593,14 +581,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
593
581
return Ok ( ( false , string_length) ) ;
594
582
}
595
583
596
- let this = self . eval_context_mut ( ) ;
597
-
598
584
// Store the UTF-16 string.
599
- let char_size = Size :: from_bytes ( 2 ) ;
600
- for ( idx, c) in u16_vec. into_iter ( ) . chain ( iter:: once ( 0x0000 ) ) . enumerate ( ) {
601
- let place = this. mplace_field ( mplace, idx) ?;
602
- this. write_scalar ( Scalar :: from_uint ( c, char_size) , place. into ( ) ) ?;
603
- }
585
+ self . eval_context_mut ( )
586
+ . memory
587
+ . write_u16s ( scalar, u16_vec. into_iter ( ) . chain ( iter:: once ( 0x0000 ) ) ) ?;
604
588
Ok ( ( true , string_length) )
605
589
}
606
590
@@ -645,7 +629,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
645
629
646
630
let arg_type = this. tcx . mk_array ( this. tcx . types . u16 , size) ;
647
631
let arg_place = this. allocate ( this. layout_of ( arg_type) . unwrap ( ) , memkind) ;
648
- assert ! ( self . write_os_str_to_wide_str( os_str, arg_place, size) . unwrap( ) . 0 ) ;
632
+ assert ! ( self . write_os_str_to_wide_str( os_str, arg_place. ptr , size) . unwrap( ) . 0 ) ;
649
633
arg_place. ptr . assert_ptr ( )
650
634
}
651
635
0 commit comments