Skip to content

Commit fc8f88e

Browse files
committed
change helper fn 'write_os_str_to_wide_str'
1 parent 0d0a457 commit fc8f88e

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a5fb9ae5b2ed3cb011ada9dc1e8633aa0927f279
1+
7b73d14b0b35e7b4f79f2d71dc1bbbab31698288

src/helpers.rs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -463,18 +463,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
463463
}
464464
}
465465

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-
478466
/// Helper function to read an OsString from a null-terminated sequence of bytes, which is what
479467
/// the Unix APIs usually handle.
480468
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
567555
fn write_os_str_to_wide_str(
568556
&mut self,
569557
os_str: &OsStr,
570-
mplace: MPlaceTy<'tcx, Tag>,
558+
scalar: Scalar<Tag>,
571559
size: u64,
572560
) -> InterpResult<'tcx, (bool, u64)> {
573561
#[cfg(windows)]
@@ -593,14 +581,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
593581
return Ok((false, string_length));
594582
}
595583

596-
let this = self.eval_context_mut();
597-
598584
// 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)))?;
604588
Ok((true, string_length))
605589
}
606590

@@ -645,7 +629,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
645629

646630
let arg_type = this.tcx.mk_array(this.tcx.types.u16, size);
647631
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);
649633
arg_place.ptr.assert_ptr()
650634
}
651635

0 commit comments

Comments
 (0)