mirror of
https://github.com/rust-lang/rust.git
synced 2026-06-02 06:28:20 +03:00
follow-up to reviews
This commit is contained in:
@@ -588,21 +588,6 @@ fn os_str_to_u16vec<'tcx>(os_str: &OsStr) -> InterpResult<'tcx, Vec<u16>> {
|
||||
Ok((true, string_length))
|
||||
}
|
||||
|
||||
/// Dispatches to appropriate implementations for allocating & writing OsString in Memory,
|
||||
/// depending on the interpretation target.
|
||||
fn alloc_os_str_as_target_str(
|
||||
&mut self,
|
||||
os_str: &OsStr,
|
||||
memkind: MemoryKind<MiriMemoryKind>,
|
||||
) -> InterpResult<'tcx, Pointer<Tag>> {
|
||||
let target_os = self.eval_context_ref().tcx.sess.target.target.target_os.as_str();
|
||||
match target_os {
|
||||
"linux" | "macos" => Ok(self.alloc_os_str_as_c_str(os_str, memkind)),
|
||||
"windows" => Ok(self.alloc_os_str_as_wide_str(os_str, memkind)),
|
||||
unsupported => throw_unsup_format!("OsString support for target OS `{}` not yet available", unsupported),
|
||||
}
|
||||
}
|
||||
|
||||
/// Allocate enough memory to store the given `OsStr` as a null-terminated sequence of bytes.
|
||||
fn alloc_os_str_as_c_str(
|
||||
&mut self,
|
||||
|
||||
+7
-18
@@ -23,17 +23,17 @@ pub struct EnvVars<'tcx> {
|
||||
impl<'tcx> EnvVars<'tcx> {
|
||||
pub(crate) fn init<'mir>(
|
||||
ecx: &mut InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
|
||||
mut excluded_env_vars: Vec<String>,
|
||||
excluded_env_vars: Vec<String>,
|
||||
) -> InterpResult<'tcx> {
|
||||
if ecx.tcx.sess.target.target.target_os == "windows" {
|
||||
// Exclude `TERM` var to avoid terminfo trying to open the termcap file.
|
||||
excluded_env_vars.push("TERM".to_owned());
|
||||
}
|
||||
if ecx.machine.communicate {
|
||||
let target_os = ecx.tcx.sess.target.target.target_os.as_str();
|
||||
for (name, value) in env::vars() {
|
||||
if !excluded_env_vars.contains(&name) {
|
||||
let var_ptr =
|
||||
alloc_env_var_as_target_str(name.as_ref(), value.as_ref(), ecx)?;
|
||||
let var_ptr = match target_os {
|
||||
"linux" | "macos" => alloc_env_var_as_c_str(name.as_ref(), value.as_ref(), ecx)?,
|
||||
"windows" => alloc_env_var_as_wide_str(name.as_ref(), value.as_ref(), ecx)?,
|
||||
unsupported => throw_unsup_format!("OsString support for target OS `{}` not yet available", unsupported),
|
||||
};
|
||||
ecx.machine.env_vars.map.insert(OsString::from(name), var_ptr);
|
||||
}
|
||||
}
|
||||
@@ -42,17 +42,6 @@ pub(crate) fn init<'mir>(
|
||||
}
|
||||
}
|
||||
|
||||
fn alloc_env_var_as_target_str<'mir, 'tcx>(
|
||||
name: &OsStr,
|
||||
value: &OsStr,
|
||||
ecx: &mut InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
|
||||
) -> InterpResult<'tcx, Pointer<Tag>> {
|
||||
let mut name_osstring = name.to_os_string();
|
||||
name_osstring.push("=");
|
||||
name_osstring.push(value);
|
||||
Ok(ecx.alloc_os_str_as_target_str(name_osstring.as_os_str(), MiriMemoryKind::Machine.into())?)
|
||||
}
|
||||
|
||||
fn alloc_env_var_as_c_str<'mir, 'tcx>(
|
||||
name: &OsStr,
|
||||
value: &OsStr,
|
||||
|
||||
Reference in New Issue
Block a user