Move os.system from posix.rs to os.rs

Fixes #5100
This commit is contained in:
Oskar Skog authored and Jeong, YunWon committed 2024-12-06 12:19:34 +09:00
1 parent 848db340da
commit 3dced01af0
3 files changed
+12 -10

No files matched your search

+3 -3
View File
@@ -502,9 +502,9 @@ with TestWithTempDir() as tmpdir:
assert set(collected_files) == set(expected_files)
# system()
if "win" not in sys.platform:
assert os.system('ls') == 0
assert os.system('{') != 0
if os.name in ('posix', 'nt'):
assert os.system('echo test') == 0
assert os.system('&') != 0
for arg in [None, 1, 1.0, TabError]:
assert_raises(TypeError, os.system, arg)
+9
View File
@@ -142,6 +142,7 @@ pub(super) mod _os {
protocol::PyIterReturn,
recursion::ReprGuard,
types::{IterNext, Iterable, PyStructSequence, Representable, SelfIter},
utils::ToCString,
vm::VirtualMachine,
AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject,
};
@@ -1028,6 +1029,14 @@ pub(super) mod _os {
})
}
#[cfg(any(unix, windows))]
#[pyfunction]
fn system(command: PyStrRef, vm: &VirtualMachine) -> PyResult<i32> {
let cstr = command.to_cstring(vm)?;
let x = unsafe { libc::system(cstr.as_ptr()) };
Ok(x)
}
#[derive(FromArgs)]
struct UtimeArgs {
path: OsPath,
-7
View File
@@ -901,13 +901,6 @@ pub mod module {
nix::unistd::pipe2(oflags).map_err(|err| err.into_pyexception(vm))
}
#[pyfunction]
fn system(command: PyStrRef, vm: &VirtualMachine) -> PyResult<i32> {
let cstr = command.to_cstring(vm)?;
let x = unsafe { libc::system(cstr.as_ptr()) };
Ok(x)
}
fn _chmod(
path: OsPath,
dir_fd: DirFd<0>,