From d71910cdc2d4f1ae764eba2c31351d3804a2e0ff Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 10 Mar 2023 06:11:36 +0900 Subject: [PATCH] ArgSize for io.rs --- vm/src/stdlib/io.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/vm/src/stdlib/io.rs b/vm/src/stdlib/io.rs index 86dfc1e19..ae8c1c5ff 100644 --- a/vm/src/stdlib/io.rs +++ b/vm/src/stdlib/io.rs @@ -111,7 +111,7 @@ mod _io { }, convert::ToPyObject, function::{ - ArgBytesLike, ArgIterable, ArgMemoryBuffer, Either, FuncArgs, IntoFuncArgs, + ArgBytesLike, ArgIterable, ArgMemoryBuffer, ArgSize, Either, FuncArgs, IntoFuncArgs, OptionalArg, OptionalOption, PySetterValue, }, protocol::{ @@ -169,7 +169,7 @@ mod _io { // In a few functions, the default value is -1 rather than None. // Make sure the default value doesn't affect compatibility. #[pyarg(positional, default)] - size: Option, + size: Option, } impl OptionalSize { @@ -181,6 +181,7 @@ mod _io { pub fn try_usize(self, vm: &VirtualMachine) -> PyResult> { self.size .map(|v| { + let v = *v; if v >= 0 { Ok(v as usize) } else { @@ -1597,7 +1598,7 @@ mod _io { fn read(&self, size: OptionalSize, vm: &VirtualMachine) -> PyResult> { let mut data = self.reader().lock(vm)?; let raw = data.check_init(vm)?; - let n = size.size.unwrap_or(-1); + let n = size.size.map(|s| *s).unwrap_or(-1); if n < -1 { return Err(vm.new_value_error("read length must be non-negative or -1".to_owned())); }