Skip to content

Commit 5c5cacc

Browse files
committed
fix macos
1 parent 2b2236c commit 5c5cacc

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

crates/vm/src/stdlib/posix.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,7 +1515,7 @@ pub mod module {
15151515
#[pyarg(positional)]
15161516
args: crate::function::ArgIterable<OsPath>,
15171517
#[pyarg(positional)]
1518-
env: crate::function::ArgMapping,
1518+
env: Option<crate::function::ArgMapping>,
15191519
#[pyarg(named, default)]
15201520
file_actions: Option<crate::function::ArgIterable<PyTupleRef>>,
15211521
#[pyarg(named, default)]
@@ -1678,7 +1678,22 @@ pub mod module {
16781678
.map_err(|_| vm.new_value_error("path should not have nul bytes"))
16791679
})
16801680
.collect::<Result<_, _>>()?;
1681-
let env = envp_from_dict(self.env, vm)?;
1681+
let env = if let Some(env_dict) = self.env {
1682+
envp_from_dict(env_dict, vm)?
1683+
} else {
1684+
// env=None means use the current environment
1685+
use rustpython_common::os::ffi::OsStringExt;
1686+
env::vars_os()
1687+
.map(|(k, v)| {
1688+
let mut entry = k.into_vec();
1689+
entry.push(b'=');
1690+
entry.extend(v.into_vec());
1691+
CString::new(entry).map_err(|_| {
1692+
vm.new_value_error("environment string contains null byte")
1693+
})
1694+
})
1695+
.collect::<PyResult<Vec<_>>>()?
1696+
};
16821697

16831698
let ret = if spawnp {
16841699
nix::spawn::posix_spawnp(&path, &file_actions, &attrp, &args, &env)

0 commit comments

Comments
 (0)