Skip to content
2 changes: 1 addition & 1 deletion ast/asdl_rs.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class ExtendModuleVisitor(EmitVisitor):

def visitModule(self, mod):
depth = 0
self.emit("pub fn extend_module_nodes(vm: &VirtualMachine, module: &PyObjectRef) {", depth)
self.emit("pub fn extend_module_nodes(vm: &VirtualMachine, module: &crate::PyObj) {", depth)
self.emit("extend_module!(vm, module, {", depth + 1)
for dfn in mod.dfns:
self.visit(dfn, depth + 2)
Expand Down
2 changes: 1 addition & 1 deletion derive/src/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ impl ToTokens for GetSetNursery {
#( #cfgs )*
class.set_str_attr(
#name,
::rustpython_vm::PyObject::new(
::rustpython_vm::PyGenericObject::new(
::rustpython_vm::builtins::PyGetSet::new(#name.into(), class.clone())
.with_get(&Self::#getter)
#setter #deleter,
Expand Down
2 changes: 1 addition & 1 deletion derive/src/pymodule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn impl_pymodule(attr: AttributeArgs, module_item: Item) -> Result<TokenStre
parse_quote! {
pub(crate) fn extend_module(
vm: &::rustpython_vm::VirtualMachine,
module: &::rustpython_vm::PyObjectRef,
module: &::rustpython_vm::PyObject,
) {
#module_extend_items
}
Expand Down
2 changes: 1 addition & 1 deletion src/shell/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl<'vm> ShellHelper<'vm> {
} else {
// we need to get a variable based off of globals/builtins

let globals = str_iter_method(self.globals.as_object().clone(), "keys").ok()?;
let globals = str_iter_method(self.globals.as_object().to_owned(), "keys").ok()?;
let builtins = str_iter_method(self.vm.builtins.clone(), "__dir__").ok()?;
(first, globals, Some(builtins))
};
Expand Down
28 changes: 16 additions & 12 deletions stdlib/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ mod array {
AsBuffer, AsMapping, Comparable, Constructor, IterNext, IterNextIterable, Iterable,
PyComparisonOp,
},
IdProtocol, PyComparisonValue, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
TypeProtocol, VirtualMachine,
IdProtocol, PyComparisonValue, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult,
PyValue, TryFromObject, TypeProtocol, VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;
use itertools::Itertools;
Expand Down Expand Up @@ -1111,7 +1111,7 @@ mod array {
let iter = Iterator::zip(array_a.iter(vm), array_b.iter(vm));

for (a, b) in iter {
if !vm.bool_eq(&a?, &b?)? {
if !vm.bool_eq(&*a?, &*b?)? {
return Ok(false);
}
}
Expand Down Expand Up @@ -1167,8 +1167,8 @@ mod array {

impl Comparable for PyArray {
fn cmp(
zelf: &PyRef<Self>,
other: &PyObjectRef,
zelf: &PyObjectView<Self>,
other: &PyObject,
op: PyComparisonOp,
vm: &VirtualMachine,
) -> PyResult<PyComparisonValue> {
Expand All @@ -1195,8 +1195,12 @@ mod array {

for (a, b) in iter {
let ret = match op {
PyComparisonOp::Lt | PyComparisonOp::Le => vm.bool_seq_lt(&a?, &b?)?,
PyComparisonOp::Gt | PyComparisonOp::Ge => vm.bool_seq_gt(&a?, &b?)?,
PyComparisonOp::Lt | PyComparisonOp::Le => {
vm.bool_seq_lt(&*a?, &*b?)?
}
PyComparisonOp::Gt | PyComparisonOp::Ge => {
vm.bool_seq_gt(&*a?, &*b?)?
}
_ => unreachable!(),
};
if let Some(v) = ret {
Expand All @@ -1214,11 +1218,11 @@ mod array {
}

impl AsBuffer for PyArray {
fn as_buffer(zelf: &PyRef<Self>, _vm: &VirtualMachine) -> PyResult<PyBuffer> {
fn as_buffer(zelf: &PyObjectView<Self>, _vm: &VirtualMachine) -> PyResult<PyBuffer> {
let array = zelf.read();
let buf = PyBuffer::new(
zelf.as_object().clone(),
PyArrayBufferInternal(zelf.clone()),
zelf.as_object().to_owned(),
PyArrayBufferInternal(zelf.to_owned()),
BufferOptions {
readonly: false,
len: array.len(),
Expand Down Expand Up @@ -1253,7 +1257,7 @@ mod array {
}

impl AsMapping for PyArray {
fn as_mapping(_zelf: &PyRef<Self>, _vm: &VirtualMachine) -> PyMappingMethods {
fn as_mapping(_zelf: &PyObjectView<Self>, _vm: &VirtualMachine) -> PyMappingMethods {
PyMappingMethods {
length: Some(Self::length),
subscript: Some(Self::subscript),
Expand Down Expand Up @@ -1322,7 +1326,7 @@ mod array {

impl IterNextIterable for PyArrayIter {}
impl IterNext for PyArrayIter {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
fn next(zelf: &PyObjectView<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
let pos = zelf.position.fetch_add(1);
let r = if let Some(item) = zelf.array.read().getitem_by_idx(pos, vm)? {
PyIterReturn::Return(item)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/src/bisect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ mod _bisect {
while lo < hi {
// Handles issue 13496.
let mid = (lo + hi) / 2;
if x.rich_compare_bool(&a.get_item(mid, vm)?, Lt, vm)? {
if x.rich_compare_bool(&*a.get_item(mid, vm)?, Lt, vm)? {
hi = mid;
} else {
lo = mid + 1;
Expand Down
4 changes: 2 additions & 2 deletions stdlib/src/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod _csv {
match_class,
protocol::{PyIter, PyIterReturn},
types::{IterNext, IterNextIterable},
PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine,
PyObjectRef, PyObjectView, PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine,
};
use itertools::{self, Itertools};
use std::fmt;
Expand Down Expand Up @@ -172,7 +172,7 @@ mod _csv {
impl Reader {}
impl IterNextIterable for Reader {}
impl IterNext for Reader {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
fn next(zelf: &PyObjectView<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
let string = match zelf.iter.next(vm)? {
PyIterReturn::Return(obj) => obj,
PyIterReturn::StopIteration(v) => return Ok(PyIterReturn::StopIteration(v)),
Expand Down
18 changes: 14 additions & 4 deletions stdlib/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod _json {
function::{IntoPyObject, IntoPyResult, OptionalArg},
protocol::PyIterReturn,
types::{Callable, Constructor},
IdProtocol, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
IdProtocol, PyObjectRef, PyObjectView, PyResult, PyValue, VirtualMachine,
};
use num_bigint::BigInt;
use std::str::FromStr;
Expand Down Expand Up @@ -195,7 +195,11 @@ mod _json {

impl Callable for JsonScanner {
type Args = (PyStrRef, isize);
fn call(zelf: &PyRef<Self>, (pystr, idx): Self::Args, vm: &VirtualMachine) -> PyResult {
fn call(
zelf: &PyObjectView<Self>,
(pystr, idx): Self::Args,
vm: &VirtualMachine,
) -> PyResult {
if idx < 0 {
return Err(vm.new_value_error("idx cannot be negative".to_owned()));
}
Expand All @@ -204,8 +208,14 @@ mod _json {
if idx > 0 && chars.nth(idx - 1).is_none() {
PyIterReturn::StopIteration(Some(vm.ctx.new_int(idx).into())).into_pyresult(vm)
} else {
zelf.parse(chars.as_str(), pystr.clone(), idx, zelf.clone().into(), vm)
.and_then(|x| x.into_pyresult(vm))
zelf.parse(
chars.as_str(),
pystr.clone(),
idx,
zelf.to_owned().into(),
vm,
)
.and_then(|x| x.into_pyresult(vm))
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions stdlib/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod math {
builtins::{try_bigint_to_f64, try_f64_to_bigint, PyFloat, PyInt, PyIntRef},
function::{ArgIntoFloat, ArgIterable, OptionalArg, PosArgs},
utils::Either,
PyObjectRef, PyRef, PyResult, PySequence, TypeProtocol, VirtualMachine,
PyObject, PyObjectRef, PyRef, PyResult, PySequence, TypeProtocol, VirtualMachine,
};
use num_bigint::BigInt;
use num_traits::{One, Signed, Zero};
Expand Down Expand Up @@ -408,8 +408,8 @@ mod math {
}
}

fn try_magic_method(func_name: &str, vm: &VirtualMachine, value: &PyObjectRef) -> PyResult {
let method = vm.get_method_or_type_error(value.clone(), func_name, || {
fn try_magic_method(func_name: &str, vm: &VirtualMachine, value: &PyObject) -> PyResult {
let method = vm.get_method_or_type_error(value.to_owned(), func_name, || {
format!(
"type '{}' doesn't define '{}' method",
value.class().name(),
Expand Down
4 changes: 2 additions & 2 deletions stdlib/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod resource {
use crate::vm::{
function::{IntoPyException, IntoPyObject},
stdlib::os,
PyObjectRef, PyResult, PyStructSequence, TryFromBorrowedObject, VirtualMachine,
PyObject, PyObjectRef, PyResult, PyStructSequence, TryFromBorrowedObject, VirtualMachine,
};
use std::{io, mem};

Expand Down Expand Up @@ -113,7 +113,7 @@ mod resource {

struct Limits(libc::rlimit);
impl TryFromBorrowedObject for Limits {
fn try_from_borrowed_object(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult<Self> {
fn try_from_borrowed_object(vm: &VirtualMachine, obj: &PyObject) -> PyResult<Self> {
let seq = vm.extract_elements::<libc::rlim_t>(obj)?;
match *seq {
[cur, max] => Ok(Self(libc::rlimit {
Expand Down
2 changes: 1 addition & 1 deletion stdlib/src/ssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ mod _ssl {
stream: PyRwLock::new(stream),
socket_type,
server_hostname: args.server_hostname,
owner: PyRwLock::new(args.owner.as_ref().map(PyWeak::downgrade)),
owner: PyRwLock::new(args.owner.as_ref().map(|o| PyWeak::downgrade(o))),
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions vm/src/builtins/asyncgenerator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ impl PyAsyncGenASend {

impl IterNextIterable for PyAsyncGenASend {}
impl IterNext for PyAsyncGenASend {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
fn next(zelf: &crate::PyObjectView<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
PyIterReturn::from_pyresult(zelf.send(vm.ctx.none(), vm), vm)
}
}
Expand Down Expand Up @@ -405,7 +405,7 @@ impl PyAsyncGenAThrow {

impl IterNextIterable for PyAsyncGenAThrow {}
impl IterNext for PyAsyncGenAThrow {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
fn next(zelf: &crate::PyObjectView<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
PyIterReturn::from_pyresult(zelf.send(vm.ctx.none(), vm), vm)
}
}
Expand Down
4 changes: 2 additions & 2 deletions vm/src/builtins/builtinfunc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl PyBuiltinFunction {
impl Callable for PyBuiltinFunction {
type Args = FuncArgs;
#[inline]
fn call(zelf: &PyRef<Self>, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
fn call(zelf: &crate::PyObjectView<Self>, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
(zelf.value.func)(vm, args)
}
}
Expand Down Expand Up @@ -193,7 +193,7 @@ impl GetDescriptor for PyBuiltinMethod {
impl Callable for PyBuiltinMethod {
type Args = FuncArgs;
#[inline]
fn call(zelf: &PyRef<Self>, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
fn call(zelf: &crate::PyObjectView<Self>, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
(zelf.value.func)(vm, args)
}
}
Expand Down
22 changes: 11 additions & 11 deletions vm/src/builtins/bytearray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use crate::{
IterNextIterable, Iterable, PyComparisonOp, Unconstructible, Unhashable,
},
utils::Either,
IdProtocol, PyClassDef, PyClassImpl, PyComparisonValue, PyContext, PyObjectRef, PyRef,
PyResult, PyValue, TypeProtocol, VirtualMachine,
IdProtocol, PyClassDef, PyClassImpl, PyComparisonValue, PyContext, PyObject, PyObjectRef,
PyRef, PyResult, PyValue, TypeProtocol, VirtualMachine,
};
use bstr::ByteSlice;
use crossbeam_utils::atomic::AtomicCell;
Expand Down Expand Up @@ -290,7 +290,7 @@ impl PyByteArray {
}
}

fn irepeat(zelf: &PyRef<Self>, n: usize, vm: &VirtualMachine) -> PyResult<()> {
fn irepeat(zelf: &crate::PyObjectView<Self>, n: usize, vm: &VirtualMachine) -> PyResult<()> {
if n == 1 {
return Ok(());
}
Expand Down Expand Up @@ -696,8 +696,8 @@ impl PyByteArray {

impl Comparable for PyByteArray {
fn cmp(
zelf: &PyRef<Self>,
other: &PyObjectRef,
zelf: &crate::PyObjectView<Self>,
other: &PyObject,
op: PyComparisonOp,
vm: &VirtualMachine,
) -> PyResult<PyComparisonValue> {
Expand All @@ -709,10 +709,10 @@ impl Comparable for PyByteArray {
}

impl AsBuffer for PyByteArray {
fn as_buffer(zelf: &PyRef<Self>, _vm: &VirtualMachine) -> PyResult<PyBuffer> {
fn as_buffer(zelf: &crate::PyObjectView<Self>, _vm: &VirtualMachine) -> PyResult<PyBuffer> {
let buffer = PyBuffer::new(
zelf.as_object().clone(),
zelf.clone(),
zelf.as_object().to_owned(),
zelf.to_owned(),
BufferOptions {
readonly: false,
len: zelf.len(),
Expand Down Expand Up @@ -756,7 +756,7 @@ impl<'a> BufferResizeGuard<'a> for PyByteArray {
}

impl AsMapping for PyByteArray {
fn as_mapping(_zelf: &PyRef<Self>, _vm: &VirtualMachine) -> PyMappingMethods {
fn as_mapping(_zelf: &crate::PyObjectView<Self>, _vm: &VirtualMachine) -> PyMappingMethods {
PyMappingMethods {
length: Some(Self::length),
subscript: Some(Self::subscript),
Expand Down Expand Up @@ -801,7 +801,7 @@ impl Iterable for PyByteArray {
}
}

// fn set_value(obj: &PyObjectRef, value: Vec<u8>) {
// fn set_value(obj: &PyObject, value: Vec<u8>) {
// obj.borrow_mut().kind = PyObjectPayload::Bytes { value };
// }

Expand Down Expand Up @@ -841,7 +841,7 @@ impl Unconstructible for PyByteArrayIterator {}

impl IterNextIterable for PyByteArrayIterator {}
impl IterNext for PyByteArrayIterator {
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
fn next(zelf: &crate::PyObjectView<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
zelf.internal.lock().next(|bytearray, pos| {
let buf = bytearray.borrow_buf();
Ok(match buf.get(pos) {
Expand Down
Loading