Skip to content

Commit e5a1c3b

Browse files
committed
setattro uses PyObjectPtr
1 parent 70f8849 commit e5a1c3b

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

vm/src/builtins/object.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,12 @@ impl PyBaseObject {
161161

162162
#[pyslot]
163163
fn slot_setattro(
164-
obj: &PyObjectRef,
164+
obj: PyObjectPtr,
165165
attr_name: PyStrRef,
166166
value: Option<PyObjectRef>,
167167
vm: &VirtualMachine,
168168
) -> PyResult<()> {
169-
setattr(obj, attr_name, value, vm)
169+
setattr(&*obj, attr_name, value, vm)
170170
}
171171

172172
/// Return str(self).

vm/src/protocol/object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl PyObjectRef {
6161
))
6262
})?
6363
};
64-
setattro(self, attr_name, attr_value, vm)
64+
self.with_ptr(|zelf| setattro(zelf, attr_name, attr_value, vm))
6565
}
6666

6767
// PyObject *PyObject_GenericGetAttr(PyObject *o, PyObject *name)

vm/src/types/slot.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub(crate) type HashFunc = fn(PyObjectPtr, &VirtualMachine) -> PyResult<PyHash>;
133133
// CallFunc = GenericMethod
134134
pub(crate) type GetattroFunc = fn(PyObjectRef, PyStrRef, &VirtualMachine) -> PyResult;
135135
pub(crate) type SetattroFunc =
136-
fn(&PyObjectRef, PyStrRef, Option<PyObjectRef>, &VirtualMachine) -> PyResult<()>;
136+
fn(PyObjectPtr, PyStrRef, Option<PyObjectRef>, &VirtualMachine) -> PyResult<()>;
137137
pub(crate) type AsBufferFunc = fn(PyObjectPtr, &VirtualMachine) -> PyResult<PyBuffer>;
138138
pub(crate) type RichCompareFunc = fn(
139139
PyObjectPtr,
@@ -209,17 +209,18 @@ fn getattro_wrapper(zelf: PyObjectRef, name: PyStrRef, vm: &VirtualMachine) -> P
209209
}
210210

211211
fn setattro_wrapper(
212-
zelf: &PyObjectRef,
212+
zelf: PyObjectPtr,
213213
name: PyStrRef,
214214
value: Option<PyObjectRef>,
215215
vm: &VirtualMachine,
216216
) -> PyResult<()> {
217+
let zelf = (*zelf).clone();
217218
match value {
218219
Some(value) => {
219-
vm.call_special_method(zelf.clone(), "__setattr__", (name, value))?;
220+
vm.call_special_method(zelf, "__setattr__", (name, value))?;
220221
}
221222
None => {
222-
vm.call_special_method(zelf.clone(), "__delattr__", (name,))?;
223+
vm.call_special_method(zelf, "__delattr__", (name,))?;
223224
}
224225
};
225226
Ok(())
@@ -712,7 +713,7 @@ pub trait SetAttr: PyValue {
712713
#[pyslot]
713714
#[inline]
714715
fn slot_setattro(
715-
obj: &PyObjectRef,
716+
obj: PyObjectPtr,
716717
name: PyStrRef,
717718
value: Option<PyObjectRef>,
718719
vm: &VirtualMachine,

0 commit comments

Comments
 (0)