|
1 | 1 | use std::{mem, iter};
|
2 |
| -use std::ffi::{OsStr, OsString}; |
| 2 | +use std::ffi::OsStr; |
3 | 3 |
|
4 | 4 | use syntax::source_map::DUMMY_SP;
|
5 | 5 | use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX};
|
@@ -453,9 +453,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
453 | 453 |
|
454 | 454 | /// Helper function to read an OsString from a null-terminated sequence of bytes, which is what
|
455 | 455 | /// the Unix APIs usually handle.
|
456 |
| - fn read_os_string_from_c_string(&mut self, scalar: Scalar<Tag>) -> InterpResult<'tcx, OsString> { |
457 |
| - let bytes = self.eval_context_mut().memory.read_c_str(scalar)?; |
458 |
| - Ok(bytes_to_os_str(bytes)?.into()) |
| 456 | + fn read_os_string_from_c_string<'a>(&'a self, scalar: Scalar<Tag>) -> InterpResult<'tcx, &'a OsStr> |
| 457 | + where 'tcx: 'a, 'mir: 'a |
| 458 | + { |
| 459 | + let this = self.eval_context_ref(); |
| 460 | + let bytes = this.memory.read_c_str(scalar)?; |
| 461 | + bytes_to_os_str(bytes) |
459 | 462 | }
|
460 | 463 |
|
461 | 464 | /// Helper function to write an OsStr as a null-terminated sequence of bytes, which is what
|
@@ -501,7 +504,7 @@ fn os_str_to_bytes<'tcx, 'a>(os_str: &'a OsStr) -> InterpResult<'tcx, &'a [u8]>
|
501 | 504 | }
|
502 | 505 |
|
503 | 506 | #[cfg(not(target_os = "unix"))]
|
504 |
| -fn bytes_to_os_str<'tcx, 'a>(bytes: &'a[u8]) -> InterpResult<'tcx, &'a OsStr> { |
| 507 | +fn bytes_to_os_str<'tcx, 'a>(bytes: &'a [u8]) -> InterpResult<'tcx, &'a OsStr> { |
505 | 508 | let s = std::str::from_utf8(bytes)
|
506 | 509 | .map_err(|_| err_unsup_format!("{:?} is not a valid utf-8 string", bytes))?;
|
507 | 510 | Ok(&OsStr::new(s))
|
|
0 commit comments