mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Merge pull request #2749 from deantvv/os-fdopen-invalid
os: fix fdopen invalid file descriptor
This commit is contained in:
@@ -1878,10 +1878,6 @@ class TestInvalidFD(unittest.TestCase):
|
||||
if hasattr(os, f):
|
||||
self.check(getattr(os, f))
|
||||
|
||||
# TODO: RUSTPYTHON; io.FileIO(fd) should check if the fd passed is valid
|
||||
if f == "fdopen":
|
||||
# this is test_fdopen
|
||||
helper = unittest.expectedFailure(helper)
|
||||
|
||||
return helper
|
||||
for f in singles:
|
||||
|
||||
@@ -8,6 +8,9 @@ cfg_if::cfg_if! {
|
||||
type Offset = i64;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
use crate::stdlib::os::{errno_err, PathOrFd};
|
||||
use crate::VirtualMachine;
|
||||
use crate::{PyObjectRef, PyResult, TryFromObject};
|
||||
pub(crate) use _io::io_open as open;
|
||||
@@ -3571,6 +3574,12 @@ mod _io {
|
||||
}
|
||||
}
|
||||
|
||||
// check file descriptor validity
|
||||
#[cfg(unix)]
|
||||
if let Ok(PathOrFd::Fd(fd)) = PathOrFd::try_from_object(vm, file.clone()) {
|
||||
nix::fcntl::fcntl(fd, nix::fcntl::F_GETFD).map_err(|_| errno_err(vm))?;
|
||||
}
|
||||
|
||||
// Construct a FileIO (subclass of RawIOBase)
|
||||
// This is subsequently consumed by a Buffered Class.
|
||||
let file_io_class = {
|
||||
|
||||
@@ -217,7 +217,7 @@ impl TryFromObject for PyPathLike {
|
||||
}
|
||||
}
|
||||
|
||||
enum PathOrFd {
|
||||
pub(crate) enum PathOrFd {
|
||||
Path(PyPathLike),
|
||||
Fd(i32),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user