Skip to content

Commit d7f2e2e

Browse files
authored
Merge pull request RustPython#3416 from deantvv/os-posix-spawn
os: fix posix_spawn exception
2 parents 40fd9c2 + 98e3d26 commit d7f2e2e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

Lib/test/test_posix.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,8 +1554,6 @@ def test_returns_pid(self):
15541554
with open(pidfile) as f:
15551555
self.assertEqual(f.read(), str(pid))
15561556

1557-
# TODO: RUSTPYTHON: AssertionError: None != 'no_such_executable'
1558-
@unittest.expectedFailure
15591557
def test_no_such_executable(self):
15601558
no_such_executable = 'no_such_executable'
15611559
try:

vm/src/stdlib/posix.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,10 @@ pub mod module {
12781278
fn spawn(self, spawnp: bool, vm: &VirtualMachine) -> PyResult<libc::pid_t> {
12791279
use crate::TryFromBorrowedObject;
12801280

1281-
let path = CString::new(self.path.into_bytes())
1281+
let path = self
1282+
.path
1283+
.clone()
1284+
.into_cstring(vm)
12821285
.map_err(|_| vm.new_value_error("path should not have nul bytes".to_owned()))?;
12831286

12841287
let mut file_actions = unsafe {
@@ -1331,7 +1334,9 @@ pub mod module {
13311334
}
13321335
};
13331336
if ret != 0 {
1334-
return Err(errno_err(vm));
1337+
return Err(IOErrorBuilder::new(std::io::Error::from_raw_os_error(ret))
1338+
.filename(self.path)
1339+
.into_pyexception(vm));
13351340
}
13361341
}
13371342
}
@@ -1403,7 +1408,9 @@ pub mod module {
14031408
if ret == 0 {
14041409
Ok(pid)
14051410
} else {
1406-
Err(errno_err(vm))
1411+
Err(IOErrorBuilder::new(std::io::Error::from_raw_os_error(ret))
1412+
.filename(self.path)
1413+
.into_pyexception(vm))
14071414
}
14081415
}
14091416
}

0 commit comments

Comments
 (0)