From 08b5768a82da4ce606f11004acb85ec770c2c78b Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 15 Oct 2021 06:50:48 +0900 Subject: [PATCH] iternext uses ptr --- vm/src/protocol/iter.rs | 2 +- vm/src/stdlib/io.rs | 4 ++-- vm/src/types/slot.rs | 11 ++++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/vm/src/protocol/iter.rs b/vm/src/protocol/iter.rs index 5c0b397bdf..f03f737e39 100644 --- a/vm/src/protocol/iter.rs +++ b/vm/src/protocol/iter.rs @@ -42,7 +42,7 @@ where )) })? }; - iternext(self.0.borrow(), vm) + self.0.borrow().with_ptr(|zelf| iternext(zelf, vm)) } pub fn iter<'a, 'b, U>( diff --git a/vm/src/stdlib/io.rs b/vm/src/stdlib/io.rs index 0179c5218d..ea76e4f883 100644 --- a/vm/src/stdlib/io.rs +++ b/vm/src/stdlib/io.rs @@ -525,8 +525,8 @@ mod _io { } impl IterNext for _IOBase { - fn slot_iternext(zelf: &PyObjectRef, vm: &VirtualMachine) -> PyResult { - let line = vm.call_method(zelf, "readline", ())?; + fn slot_iternext(zelf: PyObjectPtr, vm: &VirtualMachine) -> PyResult { + let line = vm.call_method(&*zelf, "readline", ())?; Ok(if !line.clone().try_to_bool(vm)? { PyIterReturn::StopIteration(None) } else { diff --git a/vm/src/types/slot.rs b/vm/src/types/slot.rs index 2285ad3502..f638615060 100644 --- a/vm/src/types/slot.rs +++ b/vm/src/types/slot.rs @@ -142,7 +142,7 @@ pub(crate) type RichCompareFunc = fn( &VirtualMachine, ) -> PyResult>; pub(crate) type IterFunc = fn(PyObjectRef, &VirtualMachine) -> PyResult; -pub(crate) type IterNextFunc = fn(&PyObjectRef, &VirtualMachine) -> PyResult; +pub(crate) type IterNextFunc = fn(PyObjectPtr, &VirtualMachine) -> PyResult; pub(crate) type DescrGetFunc = fn(PyObjectRef, Option, Option, &VirtualMachine) -> PyResult; pub(crate) type DescrSetFunc = @@ -239,8 +239,8 @@ fn iter_wrapper(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult { vm.call_special_method(zelf, "__iter__", ()) } -fn iternext_wrapper(zelf: &PyObjectRef, vm: &VirtualMachine) -> PyResult { - PyIterReturn::from_pyresult(vm.call_special_method(zelf.clone(), "__next__", ()), vm) +fn iternext_wrapper(zelf: PyObjectPtr, vm: &VirtualMachine) -> PyResult { + PyIterReturn::from_pyresult(vm.call_special_method((*zelf).clone(), "__next__", ()), vm) } fn descr_get_wrapper( @@ -828,7 +828,7 @@ pub trait Iterable: PyValue { #[pyimpl(with(Iterable))] pub trait IterNext: PyValue + Iterable { #[pyslot] - fn slot_iternext(zelf: &PyObjectRef, vm: &VirtualMachine) -> PyResult { + fn slot_iternext(zelf: PyObjectPtr, vm: &VirtualMachine) -> PyResult { if let Some(zelf) = zelf.downcast_ref() { Self::next(zelf, vm) } else { @@ -841,7 +841,8 @@ pub trait IterNext: PyValue + Iterable { #[inline] #[pymethod] fn __next__(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult { - Self::slot_iternext(&zelf, vm).into_pyresult(vm) + zelf.with_ptr(|zelf| Self::slot_iternext(zelf, vm)) + .into_pyresult(vm) } }