diff --git a/vm/src/types/slot.rs b/vm/src/types/slot.rs index f6094a792..32db64b33 100644 --- a/vm/src/types/slot.rs +++ b/vm/src/types/slot.rs @@ -127,7 +127,7 @@ impl Default for PyTypeFlags { } } -pub(crate) type GenericMethod = fn(&PyObjectRef, FuncArgs, &VirtualMachine) -> PyResult; +pub(crate) type GenericMethod = fn(PyObjectPtr, FuncArgs, &VirtualMachine) -> PyResult; pub(crate) type AsMappingFunc = fn(&PyObjectRef, &VirtualMachine) -> PyMappingMethods; pub(crate) type HashFunc = fn(PyObjectPtr, &VirtualMachine) -> PyResult; // CallFunc = GenericMethod @@ -200,8 +200,8 @@ fn hash_wrapper(zelf: PyObjectPtr, vm: &VirtualMachine) -> PyResult { } } -fn call_wrapper(zelf: &PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult { - vm.call_special_method(zelf.clone(), "__call__", args) +fn call_wrapper(zelf: PyObjectPtr, args: FuncArgs, vm: &VirtualMachine) -> PyResult { + vm.call_special_method((*zelf).clone(), "__call__", args) } fn getattro_wrapper(zelf: PyObjectRef, name: PyStrRef, vm: &VirtualMachine) -> PyResult { @@ -385,7 +385,7 @@ pub trait Callable: PyValue { #[inline] #[pyslot] - fn slot_call(zelf: &PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult { + fn slot_call(zelf: PyObjectPtr, args: FuncArgs, vm: &VirtualMachine) -> PyResult { if let Some(zelf) = zelf.downcast_ref() { Self::call(zelf, args.bind(vm)?, vm) } else { @@ -395,8 +395,8 @@ pub trait Callable: PyValue { #[inline] #[pymethod] - fn __call__(zelf: PyRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult { - Self::call(&zelf, args.bind(vm)?, vm) + fn __call__(zelf: PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult { + zelf.with_ptr(|zelf| Self::slot_call(zelf, args.bind(vm)?, vm)) } fn call(zelf: &PyRef, args: Self::Args, vm: &VirtualMachine) -> PyResult; } diff --git a/vm/src/vm.rs b/vm/src/vm.rs index e57c0ed29..8620c23a6 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -1203,7 +1203,7 @@ impl VirtualMachine { match slot_call { Some(slot_call) => { self.trace_event(TraceEvent::Call)?; - let result = slot_call(callable, args, self); + let result = callable.with_ptr(|zelf| slot_call(zelf, args, self)); self.trace_event(TraceEvent::Return)?; result }