X Tutup
Skip to content

Commit 8dd18d9

Browse files
coolreader18youknowone
authored andcommitted
PyObjectRef -> &PyObj, &PyRef<T> -> &Py<T>
1 parent e5a1c3b commit 8dd18d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+3381
-1747
lines changed

ast/asdl_rs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ class ExtendModuleVisitor(EmitVisitor):
401401

402402
def visitModule(self, mod):
403403
depth = 0
404-
self.emit("pub fn extend_module_nodes(vm: &VirtualMachine, module: &PyObjectRef) {", depth)
404+
self.emit("pub fn extend_module_nodes(vm: &VirtualMachine, module: &crate::PyObj) {", depth)
405405
self.emit("extend_module!(vm, module, {", depth + 1)
406406
for dfn in mod.dfns:
407407
self.visit(dfn, depth + 2)

derive/src/pymodule.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub fn impl_pymodule(attr: AttributeArgs, module_item: Item) -> Result<TokenStre
7676
parse_quote! {
7777
pub(crate) fn extend_module(
7878
vm: &::rustpython_vm::VirtualMachine,
79-
module: &::rustpython_vm::PyObjectRef,
79+
module: &::rustpython_vm::PyObj,
8080
) {
8181
#module_extend_items
8282
}

src/shell/helper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl<'vm> ShellHelper<'vm> {
8888
} else {
8989
// we need to get a variable based off of globals/builtins
9090

91-
let globals = str_iter_method(self.globals.as_object().clone(), "keys").ok()?;
91+
let globals = str_iter_method(self.globals.as_object().incref(), "keys").ok()?;
9292
let builtins = str_iter_method(self.vm.builtins.clone(), "__dir__").ok()?;
9393
(first, globals, Some(builtins))
9494
};

stdlib/src/array.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ mod array {
2828
AsBuffer, AsMapping, Comparable, Constructor, IterNext, IterNextIterable, Iterable,
2929
PyComparisonOp,
3030
},
31-
IdProtocol, PyComparisonValue, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
32-
TypeProtocol, VirtualMachine,
31+
IdProtocol, Py, PyComparisonValue, PyObj, PyObjectRef, PyRef, PyResult, PyValue,
32+
TryFromObject, TypeProtocol, VirtualMachine,
3333
};
3434
use crossbeam_utils::atomic::AtomicCell;
3535
use itertools::Itertools;
@@ -1111,7 +1111,7 @@ mod array {
11111111
let iter = Iterator::zip(array_a.iter(vm), array_b.iter(vm));
11121112

11131113
for (a, b) in iter {
1114-
if !vm.bool_eq(&a?, &b?)? {
1114+
if !vm.bool_eq(&*a?, &*b?)? {
11151115
return Ok(false);
11161116
}
11171117
}
@@ -1167,8 +1167,8 @@ mod array {
11671167

11681168
impl Comparable for PyArray {
11691169
fn cmp(
1170-
zelf: &PyRef<Self>,
1171-
other: &PyObjectRef,
1170+
zelf: &Py<Self>,
1171+
other: &PyObj,
11721172
op: PyComparisonOp,
11731173
vm: &VirtualMachine,
11741174
) -> PyResult<PyComparisonValue> {
@@ -1195,8 +1195,12 @@ mod array {
11951195

11961196
for (a, b) in iter {
11971197
let ret = match op {
1198-
PyComparisonOp::Lt | PyComparisonOp::Le => vm.bool_seq_lt(&a?, &b?)?,
1199-
PyComparisonOp::Gt | PyComparisonOp::Ge => vm.bool_seq_gt(&a?, &b?)?,
1198+
PyComparisonOp::Lt | PyComparisonOp::Le => {
1199+
vm.bool_seq_lt(&*a?, &*b?)?
1200+
}
1201+
PyComparisonOp::Gt | PyComparisonOp::Ge => {
1202+
vm.bool_seq_gt(&*a?, &*b?)?
1203+
}
12001204
_ => unreachable!(),
12011205
};
12021206
if let Some(v) = ret {
@@ -1214,11 +1218,11 @@ mod array {
12141218
}
12151219

12161220
impl AsBuffer for PyArray {
1217-
fn as_buffer(zelf: &PyRef<Self>, _vm: &VirtualMachine) -> PyResult<PyBuffer> {
1221+
fn as_buffer(zelf: &Py<Self>, _vm: &VirtualMachine) -> PyResult<PyBuffer> {
12181222
let array = zelf.read();
12191223
let buf = PyBuffer::new(
1220-
zelf.as_object().clone(),
1221-
PyArrayBufferInternal(zelf.clone()),
1224+
zelf.as_object().incref(),
1225+
PyArrayBufferInternal(zelf.incref()),
12221226
BufferOptions {
12231227
readonly: false,
12241228
len: array.len(),
@@ -1253,7 +1257,7 @@ mod array {
12531257
}
12541258

12551259
impl AsMapping for PyArray {
1256-
fn as_mapping(_zelf: &PyRef<Self>, _vm: &VirtualMachine) -> PyMappingMethods {
1260+
fn as_mapping(_zelf: &Py<Self>, _vm: &VirtualMachine) -> PyMappingMethods {
12571261
PyMappingMethods {
12581262
length: Some(Self::length),
12591263
subscript: Some(Self::subscript),
@@ -1322,7 +1326,7 @@ mod array {
13221326

13231327
impl IterNextIterable for PyArrayIter {}
13241328
impl IterNext for PyArrayIter {
1325-
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
1329+
fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
13261330
let pos = zelf.position.fetch_add(1);
13271331
let r = if let Some(item) = zelf.array.read().getitem_by_idx(pos, vm)? {
13281332
PyIterReturn::Return(item)

stdlib/src/bisect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ mod _bisect {
105105
while lo < hi {
106106
// Handles issue 13496.
107107
let mid = (lo + hi) / 2;
108-
if x.rich_compare_bool(&a.get_item(mid, vm)?, Lt, vm)? {
108+
if x.rich_compare_bool(&*a.get_item(mid, vm)?, Lt, vm)? {
109109
hi = mid;
110110
} else {
111111
lo = mid + 1;

stdlib/src/csv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mod _csv {
1616
match_class,
1717
protocol::{PyIter, PyIterReturn},
1818
types::{IterNext, IterNextIterable},
19-
PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine,
19+
Py, PyObjectRef, PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine,
2020
};
2121
use itertools::{self, Itertools};
2222
use std::fmt;
@@ -172,7 +172,7 @@ mod _csv {
172172
impl Reader {}
173173
impl IterNextIterable for Reader {}
174174
impl IterNext for Reader {
175-
fn next(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
175+
fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
176176
let string = match zelf.iter.next(vm)? {
177177
PyIterReturn::Return(obj) => obj,
178178
PyIterReturn::StopIteration(v) => return Ok(PyIterReturn::StopIteration(v)),

stdlib/src/json.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod _json {
99
function::{IntoPyObject, IntoPyResult, OptionalArg},
1010
protocol::PyIterReturn,
1111
types::{Callable, Constructor},
12-
IdProtocol, PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine,
12+
IdProtocol, Py, PyObjectRef, PyResult, PyValue, VirtualMachine,
1313
};
1414
use num_bigint::BigInt;
1515
use std::str::FromStr;
@@ -195,7 +195,7 @@ mod _json {
195195

196196
impl Callable for JsonScanner {
197197
type Args = (PyStrRef, isize);
198-
fn call(zelf: &PyRef<Self>, (pystr, idx): Self::Args, vm: &VirtualMachine) -> PyResult {
198+
fn call(zelf: &Py<Self>, (pystr, idx): Self::Args, vm: &VirtualMachine) -> PyResult {
199199
if idx < 0 {
200200
return Err(vm.new_value_error("idx cannot be negative".to_owned()));
201201
}
@@ -204,7 +204,7 @@ mod _json {
204204
if idx > 0 && chars.nth(idx - 1).is_none() {
205205
PyIterReturn::StopIteration(Some(vm.ctx.new_int(idx).into())).into_pyresult(vm)
206206
} else {
207-
zelf.parse(chars.as_str(), pystr.clone(), idx, zelf.clone().into(), vm)
207+
zelf.parse(chars.as_str(), pystr.clone(), idx, zelf.incref().into(), vm)
208208
.and_then(|x| x.into_pyresult(vm))
209209
}
210210
}

stdlib/src/math.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod math {
66
builtins::{try_bigint_to_f64, try_f64_to_bigint, PyFloat, PyInt, PyIntRef},
77
function::{ArgIntoFloat, ArgIterable, OptionalArg, PosArgs},
88
utils::Either,
9-
PyObjectRef, PyRef, PyResult, PySequence, TypeProtocol, VirtualMachine,
9+
PyObj, PyObjectRef, PyRef, PyResult, PySequence, TypeProtocol, VirtualMachine,
1010
};
1111
use num_bigint::BigInt;
1212
use num_traits::{One, Signed, Zero};
@@ -408,8 +408,8 @@ mod math {
408408
}
409409
}
410410

411-
fn try_magic_method(func_name: &str, vm: &VirtualMachine, value: &PyObjectRef) -> PyResult {
412-
let method = vm.get_method_or_type_error(value.clone(), func_name, || {
411+
fn try_magic_method(func_name: &str, vm: &VirtualMachine, value: &PyObj) -> PyResult {
412+
let method = vm.get_method_or_type_error(value.incref(), func_name, || {
413413
format!(
414414
"type '{}' doesn't define '{}' method",
415415
value.class().name(),

stdlib/src/resource.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod resource {
55
use crate::vm::{
66
function::{IntoPyException, IntoPyObject},
77
stdlib::os,
8-
PyObjectRef, PyResult, PyStructSequence, TryFromBorrowedObject, VirtualMachine,
8+
PyObj, PyObjectRef, PyResult, PyStructSequence, TryFromBorrowedObject, VirtualMachine,
99
};
1010
use std::{io, mem};
1111

@@ -113,7 +113,7 @@ mod resource {
113113

114114
struct Limits(libc::rlimit);
115115
impl TryFromBorrowedObject for Limits {
116-
fn try_from_borrowed_object(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult<Self> {
116+
fn try_from_borrowed_object(vm: &VirtualMachine, obj: &PyObj) -> PyResult<Self> {
117117
let seq = vm.extract_elements::<libc::rlim_t>(obj)?;
118118
match *seq {
119119
[cur, max] => Ok(Self(libc::rlimit {

stdlib/src/ssl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ mod _ssl {
802802
stream: PyRwLock::new(stream),
803803
socket_type,
804804
server_hostname: args.server_hostname,
805-
owner: PyRwLock::new(args.owner.as_ref().map(PyWeak::downgrade)),
805+
owner: PyRwLock::new(args.owner.as_ref().map(|o| PyWeak::downgrade(o))),
806806
})
807807
}
808808
}

0 commit comments

Comments
 (0)
X Tutup