Skip to content

Commit d7cb77e

Browse files
committed
update fcntl.ioctl's first arg can take other objects having fileno method not only Integer
1 parent ef4bea5 commit d7cb77e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

stdlib/src/fcntl.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ mod fcntl {
5252
#[cfg(any(target_os = "dragonfly", target_os = "netbsd", target_vendor = "apple"))]
5353
#[pyattr]
5454
use libc::F_GETPATH;
55+
use rustpython_vm::PyObjectRef;
5556

5657
#[pyfunction]
5758
fn fcntl(
@@ -89,12 +90,21 @@ mod fcntl {
8990

9091
#[pyfunction]
9192
fn ioctl(
92-
fd: i32,
93+
obj: PyObjectRef,
9394
request: u32,
9495
arg: OptionalArg<Either<Either<ArgMemoryBuffer, ArgStrOrBytesLike>, i32>>,
9596
mutate_flag: OptionalArg<bool>,
9697
vm: &VirtualMachine,
9798
) -> PyResult {
99+
let fd = obj.try_to_value(vm).or_else(|_| {
100+
let meth = vm.get_method_or_type_error(
101+
obj.clone(),
102+
vm.ctx.interned_str("fileno").unwrap(),
103+
|| "ioctl first arg must be an int or object with a fileno() method".to_owned(),
104+
)?;
105+
vm.invoke(&meth, ())?.try_into_value(vm)
106+
})?;
107+
98108
let arg = arg.unwrap_or_else(|| Either::B(0));
99109
match arg {
100110
Either::A(buf_kind) => {

0 commit comments

Comments
 (0)