@@ -23,17 +23,17 @@ pub struct EnvVars<'tcx> {
23
23
impl < ' tcx > EnvVars < ' tcx > {
24
24
pub ( crate ) fn init < ' mir > (
25
25
ecx : & mut InterpCx < ' mir , ' tcx , Evaluator < ' tcx > > ,
26
- mut excluded_env_vars : Vec < String > ,
26
+ excluded_env_vars : Vec < String > ,
27
27
) -> InterpResult < ' tcx > {
28
- if ecx. tcx . sess . target . target . target_os == "windows" {
29
- // Exclude `TERM` var to avoid terminfo trying to open the termcap file.
30
- excluded_env_vars. push ( "TERM" . to_owned ( ) ) ;
31
- }
32
28
if ecx. machine . communicate {
29
+ let target_os = ecx. tcx . sess . target . target . target_os . as_str ( ) ;
33
30
for ( name, value) in env:: vars ( ) {
34
31
if !excluded_env_vars. contains ( & name) {
35
- let var_ptr =
36
- alloc_env_var_as_target_str ( name. as_ref ( ) , value. as_ref ( ) , ecx) ?;
32
+ let var_ptr = match target_os {
33
+ "linux" | "macos" => alloc_env_var_as_c_str ( name. as_ref ( ) , value. as_ref ( ) , ecx) ?,
34
+ "windows" => alloc_env_var_as_wide_str ( name. as_ref ( ) , value. as_ref ( ) , ecx) ?,
35
+ unsupported => throw_unsup_format ! ( "OsString support for target OS `{}` not yet available" , unsupported) ,
36
+ } ;
37
37
ecx. machine . env_vars . map . insert ( OsString :: from ( name) , var_ptr) ;
38
38
}
39
39
}
@@ -42,17 +42,6 @@ impl<'tcx> EnvVars<'tcx> {
42
42
}
43
43
}
44
44
45
- fn alloc_env_var_as_target_str < ' mir , ' tcx > (
46
- name : & OsStr ,
47
- value : & OsStr ,
48
- ecx : & mut InterpCx < ' mir , ' tcx , Evaluator < ' tcx > > ,
49
- ) -> InterpResult < ' tcx , Pointer < Tag > > {
50
- let mut name_osstring = name. to_os_string ( ) ;
51
- name_osstring. push ( "=" ) ;
52
- name_osstring. push ( value) ;
53
- Ok ( ecx. alloc_os_str_as_target_str ( name_osstring. as_os_str ( ) , MiriMemoryKind :: Machine . into ( ) ) ?)
54
- }
55
-
56
45
fn alloc_env_var_as_c_str < ' mir , ' tcx > (
57
46
name : & OsStr ,
58
47
value : & OsStr ,
0 commit comments