PyObjectRef -> &PyObj, &PyRef<T> -> &Py<T>

This commit is contained in:
Noa
2021-10-18 16:01:17 -05:00
committed by Jeong YunWon
parent e5a1c3b137
commit 8dd18d97be
85 changed files with 3350 additions and 1716 deletions

View File

@@ -28,8 +28,8 @@ mod array {
AsBuffer, AsMapping, Comparable, Constructor, IterNext, IterNextIterable, Iterable,
PyComparisonOp,
},
IdProtocol, PyComparisonValue, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
TypeProtocol, VirtualMachine,
IdProtocol, Py, PyComparisonValue, PyObj, PyObjectRef, PyRef, PyResult, PyValue,
TryFromObject, TypeProtocol, VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;
use itertools::Itertools;
@@ -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);
}
}
@@ -1167,8 +1167,8 @@ mod array {
impl Comparable for PyArray {
fn cmp(
zelf: &PyRef<Self>,
other: &PyObjectRef,
zelf: &Py<Self>,
other: &PyObj,
op: PyComparisonOp,
vm: &VirtualMachine,
) -> PyResult<PyComparisonValue> {
@@ -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 {
@@ -1214,11 +1218,11 @@ mod array {
}
impl AsBuffer for PyArray {
fn as_buffer(zelf: &PyRef<Self>, _vm: &VirtualMachine) -> PyResult<PyBuffer> {
fn as_buffer(zelf: &Py<Self>, _vm: &VirtualMachine) -> PyResult<PyBuffer> {
let array = zelf.read();
let buf = PyBuffer::new(
zelf.as_object().clone(),
PyArrayBufferInternal(zelf.clone()),
zelf.as_object().incref(),
PyArrayBufferInternal(zelf.incref()),
BufferOptions {
readonly: false,
len: array.len(),
@@ -1253,7 +1257,7 @@ mod array {
}
impl AsMapping for PyArray {
fn as_mapping(_zelf: &PyRef<Self>, _vm: &VirtualMachine) -> PyMappingMethods {
fn as_mapping(_zelf: &Py<Self>, _vm: &VirtualMachine) -> PyMappingMethods {
PyMappingMethods {
length: Some(Self::length),
subscript: Some(Self::subscript),
@@ -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: &Py<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)

View File

@@ -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;

View File

@@ -16,7 +16,7 @@ mod _csv {
match_class,
protocol::{PyIter, PyIterReturn},
types::{IterNext, IterNextIterable},
PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine,
Py, PyObjectRef, PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine,
};
use itertools::{self, Itertools};
use std::fmt;
@@ -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: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
let string = match zelf.iter.next(vm)? {
PyIterReturn::Return(obj) => obj,
PyIterReturn::StopIteration(v) => return Ok(PyIterReturn::StopIteration(v)),

View File

@@ -9,7 +9,7 @@ mod _json {
function::{IntoPyObject, IntoPyResult, OptionalArg},
protocol::PyIterReturn,
types::{Callable, Constructor},
IdProtocol, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
IdProtocol, Py, PyObjectRef, PyResult, PyValue, VirtualMachine,
};
use num_bigint::BigInt;
use std::str::FromStr;
@@ -195,7 +195,7 @@ 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: &Py<Self>, (pystr, idx): Self::Args, vm: &VirtualMachine) -> PyResult {
if idx < 0 {
return Err(vm.new_value_error("idx cannot be negative".to_owned()));
}
@@ -204,7 +204,7 @@ 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)
zelf.parse(chars.as_str(), pystr.clone(), idx, zelf.incref().into(), vm)
.and_then(|x| x.into_pyresult(vm))
}
}

View File

@@ -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,
PyObj, PyObjectRef, PyRef, PyResult, PySequence, TypeProtocol, VirtualMachine,
};
use num_bigint::BigInt;
use num_traits::{One, Signed, Zero};
@@ -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: &PyObj) -> PyResult {
let method = vm.get_method_or_type_error(value.incref(), func_name, || {
format!(
"type '{}' doesn't define '{}' method",
value.class().name(),

View File

@@ -5,7 +5,7 @@ mod resource {
use crate::vm::{
function::{IntoPyException, IntoPyObject},
stdlib::os,
PyObjectRef, PyResult, PyStructSequence, TryFromBorrowedObject, VirtualMachine,
PyObj, PyObjectRef, PyResult, PyStructSequence, TryFromBorrowedObject, VirtualMachine,
};
use std::{io, mem};
@@ -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: &PyObj) -> PyResult<Self> {
let seq = vm.extract_elements::<libc::rlim_t>(obj)?;
match *seq {
[cur, max] => Ok(Self(libc::rlimit {

View File

@@ -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))),
})
}
}