Skip to content

Commit c1de780

Browse files
committed
os: fix spawnv tests
1 parent b6fff7a commit c1de780

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

Lib/test/test_os.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,13 +2734,9 @@ def check_waitpid(self, code, exitcode):
27342734
self.assertEqual(os.WEXITSTATUS(status), exitcode)
27352735
self.assertEqual(pid2, pid)
27362736

2737-
# TODO: RUSTPYTHON (AttributeError: module 'os' has no attribute 'spawnv')
2738-
@unittest.expectedFailure
27392737
def test_waitpid(self):
27402738
self.check_waitpid(code='pass', exitcode=0)
27412739

2742-
# TODO: RUSTPYTHON (AttributeError: module 'os' has no attribute 'spawnv')
2743-
@unittest.expectedFailure
27442740
def test_waitpid_exitcode(self):
27452741
exitcode = 23
27462742
code = f'import sys; sys.exit({exitcode})'

vm/src/byteslike.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
use std::ffi;
12
use crate::builtins::memory::{try_buffer_from_object, BufferRef};
23
use crate::builtins::PyStrRef;
34
use crate::common::borrow::{BorrowedValue, BorrowedValueMut};
5+
use crate::exceptions::IntoPyException;
46
use crate::vm::VirtualMachine;
57
use crate::{PyObjectRef, PyResult, TryFromObject};
68

@@ -145,4 +147,9 @@ impl BufOrStr {
145147
Self::Str(s) => s.as_str().as_bytes().into(),
146148
}
147149
}
150+
151+
pub fn to_cstring(&self, vm: &VirtualMachine) -> PyResult<ffi::CString> {
152+
ffi::CString::new(self.borrow_bytes().to_vec()).map_err(|err| err.into_pyexception(vm))
153+
}
154+
148155
}

vm/src/stdlib/os.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2018,6 +2018,7 @@ mod posix {
20182018

20192019
use crate::builtins::dict::PyMapping;
20202020
use crate::builtins::list::PyListRef;
2021+
use crate::byteslike::BufOrStr;
20212022
use crate::PyIterable;
20222023
use bitflags::bitflags;
20232024
use nix::errno::{errno, Errno};
@@ -2565,7 +2566,7 @@ mod posix {
25652566
let path = path.into_cstring(vm)?;
25662567

25672568
let argv = vm.extract_elements_func(argv.as_object(), |obj| {
2568-
PyStrRef::try_from_object(vm, obj)?.to_cstring(vm)
2569+
BufOrStr::try_from_object(vm, obj)?.to_cstring(vm)
25692570
})?;
25702571
let argv: Vec<&ffi::CStr> = argv.iter().map(|entry| entry.as_c_str()).collect();
25712572

0 commit comments

Comments
 (0)