diff --git a/stdlib/src/termios.rs b/stdlib/src/termios.rs index a23efe74c..66f639c88 100644 --- a/stdlib/src/termios.rs +++ b/stdlib/src/termios.rs @@ -67,26 +67,23 @@ mod termios { termios::cfsetospeed(&mut termios, ospeed.try_into_value(vm)?) .map_err(|e| termios_error(e, vm))?; let cc = PyListRef::try_from_object(vm, cc)?; - { - let cc = cc.borrow_vec(); - let cc = <&[PyObjectRef; NCCS]>::try_from(&*cc).map_err(|_| { - vm.new_type_error(format!( - "tcsetattr: attributes[6] must be {} element list", - NCCS - )) - })?; - for (cc, x) in termios.c_cc.iter_mut().zip(cc.iter()) { - *cc = if let Some(c) = x.payload::().filter(|b| b.as_bytes().len() == 1) { - c.as_bytes()[0] as _ - } else if let Some(i) = x.payload::() { - i.try_to_primitive(vm)? - } else { - return Err(vm.new_type_error( - "tcsetattr: elements of attributes must be characters or integers" - .to_owned(), - )); - }; - } + let cc = cc.borrow_vec(); + let cc = <&[PyObjectRef; NCCS]>::try_from(&*cc).map_err(|_| { + vm.new_type_error(format!( + "tcsetattr: attributes[6] must be {} element list", + NCCS + )) + })?; + for (cc, x) in termios.c_cc.iter_mut().zip(cc.iter()) { + *cc = if let Some(c) = x.payload::().filter(|b| b.as_bytes().len() == 1) { + c.as_bytes()[0] as _ + } else if let Some(i) = x.payload::() { + i.try_to_primitive(vm)? + } else { + return Err(vm.new_type_error( + "tcsetattr: elements of attributes must be characters or integers".to_owned(), + )); + }; } termios::tcsetattr(fd, when, &termios).map_err(|e| termios_error(e, vm))?; diff --git a/vm/src/builtins/list.rs b/vm/src/builtins/list.rs index 8f020c709..7269f848a 100644 --- a/vm/src/builtins/list.rs +++ b/vm/src/builtins/list.rs @@ -111,7 +111,7 @@ impl PyList { } #[pymethod(magic)] - fn add(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult { + fn add(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult> { let other = other.payload_if_subclass::(vm).ok_or_else(|| { vm.new_type_error(format!( "Cannot add {} and {}", @@ -146,7 +146,7 @@ impl PyList { } #[pymethod] - fn copy(&self, vm: &VirtualMachine) -> PyListRef { + fn copy(&self, vm: &VirtualMachine) -> PyRef { Self::new_ref(self.borrow_vec().to_vec(), &vm.ctx) } diff --git a/vm/src/builtins/memory.rs b/vm/src/builtins/memory.rs index 56b87f846..0013ed1f1 100644 --- a/vm/src/builtins/memory.rs +++ b/vm/src/builtins/memory.rs @@ -501,7 +501,7 @@ impl PyMemoryView { } #[pymethod] - fn tolist(zelf: PyRef, vm: &VirtualMachine) -> PyResult { + fn tolist(zelf: PyRef, vm: &VirtualMachine) -> PyResult> { zelf.try_not_released(vm)?; let bytes = &*zelf.obj_bytes(); @@ -516,7 +516,7 @@ impl PyMemoryView { }) .try_collect()?; - Ok(PyList::from(elements).into_ref(vm)) + Ok(elements) } #[pymethod] @@ -845,7 +845,7 @@ fn format_unpack( }) } -pub fn unpack_bytes_seq_to_list( +fn unpack_bytes_seq_to_list( bytes: &[u8], format: &str, vm: &VirtualMachine, diff --git a/vm/src/stdlib/sre.rs b/vm/src/stdlib/sre.rs index f528305e0..b39421c9d 100644 --- a/vm/src/stdlib/sre.rs +++ b/vm/src/stdlib/sre.rs @@ -4,8 +4,7 @@ pub(crate) use _sre::make_module; mod _sre { use crate::{ builtins::{ - PyCallableIterator, PyDictRef, PyInt, PyList, PyListRef, PyStr, PyStrRef, PyTuple, - PyTupleRef, + PyCallableIterator, PyDictRef, PyInt, PyList, PyStr, PyStrRef, PyTuple, PyTupleRef, }, common::{ascii, hash::PyHash}, function::{ArgCallable, IntoPyObject, OptionalArg, PosArgs}, @@ -247,7 +246,7 @@ mod _sre { zelf: PyRef, string_args: StringArgs, vm: &VirtualMachine, - ) -> PyResult { + ) -> PyResult> { zelf.with_state( string_args.string.clone(), string_args.pos, @@ -277,7 +276,7 @@ mod _sre { state.start = state.string_position; state.reset(); } - Ok(PyList::from(matchlist).into_ref(vm)) + Ok(matchlist) }, ) } @@ -332,7 +331,7 @@ mod _sre { zelf: PyRef, split_args: SplitArgs, vm: &VirtualMachine, - ) -> PyResult { + ) -> PyResult> { zelf.with_state(split_args.string.clone(), 0, usize::MAX, vm, |mut state| { let mut splitlist: Vec = Vec::new(); @@ -367,7 +366,7 @@ mod _sre { // get segment following last match (even if empty) splitlist.push(slice_drive(&state.string, last, state.string.count(), vm)); - Ok(PyList::from(splitlist).into_ref(vm)) + Ok(splitlist) }) } diff --git a/vm/src/stdlib/sys.rs b/vm/src/stdlib/sys.rs index 92088622c..b87dabcf3 100644 --- a/vm/src/stdlib/sys.rs +++ b/vm/src/stdlib/sys.rs @@ -11,7 +11,7 @@ mod sys { hash::{PyHash, PyUHash}, }; use crate::{ - builtins::{PyDictRef, PyListRef, PyNamespace, PyStr, PyStrRef, PyTupleRef, PyTypeRef}, + builtins::{PyDictRef, PyNamespace, PyStr, PyStrRef, PyTupleRef, PyTypeRef}, frame::FrameRef, function::{FuncArgs, OptionalArg, PosArgs}, stdlib::builtins, @@ -99,15 +99,13 @@ mod sys { // alphabetical order with segments of pyattr and others #[pyattr] - fn argv(vm: &VirtualMachine) -> PyListRef { - vm.ctx.new_list( - vm.state - .settings - .argv - .iter() - .map(|arg| vm.ctx.new_str(arg.clone()).into()) - .collect(), - ) + fn argv(vm: &VirtualMachine) -> Vec { + vm.state + .settings + .argv + .iter() + .map(|arg| vm.ctx.new_str(arg.clone()).into()) + .collect() } #[pyattr]