Skip to content

Commit 4d0623e

Browse files
committed
Fill in _os.environ with the correct types of strings
1 parent fc52ab7 commit 4d0623e

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

vm/src/stdlib/os.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,26 @@ fn os_unsetenv(key: Either<PyStringRef, PyBytesRef>, vm: &VirtualMachine) -> PyR
458458

459459
fn _os_environ(vm: &VirtualMachine) -> PyDictRef {
460460
let environ = vm.ctx.new_dict();
461-
for (key, value) in env::vars() {
462-
environ.set_item(&key, vm.new_str(value), vm).unwrap();
461+
#[cfg(unix)]
462+
{
463+
use std::os::unix::ffi::OsStringExt;
464+
for (key, value) in env::vars_os() {
465+
environ
466+
.set_item(
467+
&vm.ctx.new_bytes(key.into_vec()),
468+
vm.ctx.new_bytes(value.into_vec()),
469+
vm,
470+
)
471+
.unwrap();
472+
}
473+
}
474+
#[cfg(windows)]
475+
{
476+
for (key, value) in env::vars() {
477+
environ
478+
.set_item(&vm.new_str(key), vm.new_str(value), vm)
479+
.unwrap();
480+
}
463481
}
464482
environ
465483
}

0 commit comments

Comments
 (0)