From be274ec39e9b2b8705b60f3b8a3a72822e313608 Mon Sep 17 00:00:00 2001 From: coolreader18 <33094578+coolreader18@users.noreply.github.com> Date: Wed, 9 Oct 2019 23:32:14 -0500 Subject: [PATCH] Fill in _os.environ with the correct types of strings --- vm/src/stdlib/os.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/vm/src/stdlib/os.rs b/vm/src/stdlib/os.rs index e5355289b..bb6338073 100644 --- a/vm/src/stdlib/os.rs +++ b/vm/src/stdlib/os.rs @@ -457,8 +457,26 @@ fn os_unsetenv(key: Either, vm: &VirtualMachine) -> PyR fn _os_environ(vm: &VirtualMachine) -> PyDictRef { let environ = vm.ctx.new_dict(); - for (key, value) in env::vars() { - environ.set_item(&key, vm.new_str(value), vm).unwrap(); + #[cfg(unix)] + { + use std::os::unix::ffi::OsStringExt; + for (key, value) in env::vars_os() { + environ + .set_item( + &vm.ctx.new_bytes(key.into_vec()), + vm.ctx.new_bytes(value.into_vec()), + vm, + ) + .unwrap(); + } + } + #[cfg(windows)] + { + for (key, value) in env::vars() { + environ + .set_item(&vm.new_str(key), vm.new_str(value), vm) + .unwrap(); + } } environ }