Skip to content

Commit 3dced01

Browse files
oskar-skogyouknowone
authored andcommitted
Move os.system from posix.rs to os.rs
Fixes RustPython#5100
1 parent 848db34 commit 3dced01

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

extra_tests/snippets/stdlib_os.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,9 @@ def __exit__(self, exc_type, exc_val, exc_tb):
502502
assert set(collected_files) == set(expected_files)
503503

504504
# system()
505-
if "win" not in sys.platform:
506-
assert os.system('ls') == 0
507-
assert os.system('{') != 0
505+
if os.name in ('posix', 'nt'):
506+
assert os.system('echo test') == 0
507+
assert os.system('&') != 0
508508

509509
for arg in [None, 1, 1.0, TabError]:
510510
assert_raises(TypeError, os.system, arg)

vm/src/stdlib/os.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ pub(super) mod _os {
142142
protocol::PyIterReturn,
143143
recursion::ReprGuard,
144144
types::{IterNext, Iterable, PyStructSequence, Representable, SelfIter},
145+
utils::ToCString,
145146
vm::VirtualMachine,
146147
AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject,
147148
};
@@ -1028,6 +1029,14 @@ pub(super) mod _os {
10281029
})
10291030
}
10301031

1032+
#[cfg(any(unix, windows))]
1033+
#[pyfunction]
1034+
fn system(command: PyStrRef, vm: &VirtualMachine) -> PyResult<i32> {
1035+
let cstr = command.to_cstring(vm)?;
1036+
let x = unsafe { libc::system(cstr.as_ptr()) };
1037+
Ok(x)
1038+
}
1039+
10311040
#[derive(FromArgs)]
10321041
struct UtimeArgs {
10331042
path: OsPath,

vm/src/stdlib/posix.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -901,13 +901,6 @@ pub mod module {
901901
nix::unistd::pipe2(oflags).map_err(|err| err.into_pyexception(vm))
902902
}
903903

904-
#[pyfunction]
905-
fn system(command: PyStrRef, vm: &VirtualMachine) -> PyResult<i32> {
906-
let cstr = command.to_cstring(vm)?;
907-
let x = unsafe { libc::system(cstr.as_ptr()) };
908-
Ok(x)
909-
}
910-
911904
fn _chmod(
912905
path: OsPath,
913906
dir_fd: DirFd<0>,

0 commit comments

Comments
 (0)