Skip to content

Commit d4feb2a

Browse files
committed
incref -> to_owned
1 parent 8dd18d9 commit d4feb2a

Some content is hidden

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

44 files changed

+168
-149
lines changed

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().incref(), "keys").ok()?;
91+
let globals = str_iter_method(self.globals.as_object().to_owned(), "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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,8 +1221,8 @@ mod array {
12211221
fn as_buffer(zelf: &Py<Self>, _vm: &VirtualMachine) -> PyResult<PyBuffer> {
12221222
let array = zelf.read();
12231223
let buf = PyBuffer::new(
1224-
zelf.as_object().incref(),
1225-
PyArrayBufferInternal(zelf.incref()),
1224+
zelf.as_object().to_owned(),
1225+
PyArrayBufferInternal(zelf.to_owned()),
12261226
BufferOptions {
12271227
readonly: false,
12281228
len: array.len(),

stdlib/src/json.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,14 @@ 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.incref().into(), vm)
208-
.and_then(|x| x.into_pyresult(vm))
207+
zelf.parse(
208+
chars.as_str(),
209+
pystr.clone(),
210+
idx,
211+
zelf.to_owned().into(),
212+
vm,
213+
)
214+
.and_then(|x| x.into_pyresult(vm))
209215
}
210216
}
211217
}

stdlib/src/math.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ mod math {
409409
}
410410

411411
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, || {
412+
let method = vm.get_method_or_type_error(value.to_owned(), func_name, || {
413413
format!(
414414
"type '{}' doesn't define '{}' method",
415415
value.class().name(),

vm/src/builtins/bytearray.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,8 @@ impl Comparable for PyByteArray {
711711
impl AsBuffer for PyByteArray {
712712
fn as_buffer(zelf: &crate::Py<Self>, _vm: &VirtualMachine) -> PyResult<PyBuffer> {
713713
let buffer = PyBuffer::new(
714-
zelf.as_object().incref(),
715-
zelf.incref(),
714+
zelf.as_object().to_owned(),
715+
zelf.to_owned(),
716716
BufferOptions {
717717
readonly: false,
718718
len: zelf.len(),

vm/src/builtins/bytes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,8 @@ impl PyBytes {
544544
impl AsBuffer for PyBytes {
545545
fn as_buffer(zelf: &crate::Py<Self>, _vm: &VirtualMachine) -> PyResult<PyBuffer> {
546546
let buf = PyBuffer::new(
547-
zelf.as_object().incref(),
548-
zelf.incref(),
547+
zelf.as_object().to_owned(),
548+
zelf.to_owned(),
549549
BufferOptions {
550550
len: zelf.len(),
551551
..Default::default()

vm/src/builtins/coroutine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl Unconstructible for PyCoroutine {}
108108
impl IterNextIterable for PyCoroutine {}
109109
impl IterNext for PyCoroutine {
110110
fn next(zelf: &crate::Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
111-
Self::send(zelf.incref(), vm.ctx.none(), vm)
111+
Self::send(zelf.to_owned(), vm.ctx.none(), vm)
112112
}
113113
}
114114

@@ -147,7 +147,7 @@ impl PyCoroutineWrapper {
147147
impl IterNextIterable for PyCoroutineWrapper {}
148148
impl IterNext for PyCoroutineWrapper {
149149
fn next(zelf: &crate::Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
150-
Self::send(zelf.incref(), vm.ctx.none(), vm)
150+
Self::send(zelf.to_owned(), vm.ctx.none(), vm)
151151
}
152152
}
153153

vm/src/builtins/dict.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ impl crate::Py<PyDict> {
489489
}
490490

491491
if !exact {
492-
if let Some(method_or_err) = vm.get_method(self.incref().into(), "__missing__") {
492+
if let Some(method_or_err) = vm.get_method(self.to_owned().into(), "__missing__") {
493493
let method = method_or_err?;
494494
return vm.invoke(&method, (key,)).map(Some);
495495
}
@@ -640,7 +640,7 @@ impl IntoIterator for &crate::Py<PyDict> {
640640
type IntoIter = DictIter;
641641

642642
fn into_iter(self) -> Self::IntoIter {
643-
DictIter::new(self.incref())
643+
DictIter::new(self.to_owned())
644644
}
645645
}
646646

vm/src/builtins/float.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl PyObj {
5555
if let Some(float) = self.payload_if_exact::<PyFloat>(vm) {
5656
return Ok(Some(float.value));
5757
}
58-
if let Some(method) = vm.get_method(self.incref(), "__float__") {
58+
if let Some(method) = vm.get_method(self.to_owned(), "__float__") {
5959
let result = vm.invoke(&method?, ())?;
6060
// TODO: returning strict subclasses of float in __float__ is deprecated
6161
return match result.payload::<PyFloat>() {
@@ -66,7 +66,7 @@ impl PyObj {
6666
))),
6767
};
6868
}
69-
if let Some(r) = vm.to_index_opt(self.incref()).transpose()? {
69+
if let Some(r) = vm.to_index_opt(self.to_owned()).transpose()? {
7070
return Ok(Some(try_bigint_to_f64(r.as_bigint(), vm)?));
7171
}
7272
Ok(None)

vm/src/builtins/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ impl PyFunction {
379379
fn repr(zelf: PyRef<Self>, vm: &VirtualMachine) -> String {
380380
let qualname = zelf
381381
.as_object()
382-
.incref()
382+
.to_owned()
383383
.get_attr("__qualname__", vm)
384384
.ok()
385385
.and_then(|qualname_attr| qualname_attr.downcast::<PyStr>().ok())

0 commit comments

Comments
 (0)