diff --git a/src/helpers.rs b/src/helpers.rs index cdad723502eb..3e89fdf6f3cc 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -588,21 +588,6 @@ fn os_str_to_u16vec<'tcx>(os_str: &OsStr) -> InterpResult<'tcx, Vec> { 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, - ) -> InterpResult<'tcx, Pointer> { - 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, diff --git a/src/shims/env.rs b/src/shims/env.rs index 990ccf7d69bd..7c126140491f 100644 --- a/src/shims/env.rs +++ b/src/shims/env.rs @@ -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, + excluded_env_vars: Vec, ) -> 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> { - 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,