as_buffer uses ptr

This commit is contained in:
Jeong YunWon
2021-10-15 06:52:36 +09:00
parent 08b5768a82
commit 70f8849f05
2 changed files with 3 additions and 3 deletions

View File

@@ -108,7 +108,7 @@ impl TryFromBorrowedObject for PyBuffer {
let obj_cls = obj.class();
for cls in obj_cls.iter_mro() {
if let Some(f) = cls.slots.as_buffer.as_ref() {
return f(obj, vm);
return obj.with_ptr(|obj| f(obj, vm));
}
}
Err(vm.new_type_error(format!(

View File

@@ -134,7 +134,7 @@ pub(crate) type HashFunc = fn(PyObjectPtr, &VirtualMachine) -> PyResult<PyHash>;
pub(crate) type GetattroFunc = fn(PyObjectRef, PyStrRef, &VirtualMachine) -> PyResult;
pub(crate) type SetattroFunc =
fn(&PyObjectRef, PyStrRef, Option<PyObjectRef>, &VirtualMachine) -> PyResult<()>;
pub(crate) type AsBufferFunc = fn(&PyObjectRef, &VirtualMachine) -> PyResult<PyBuffer>;
pub(crate) type AsBufferFunc = fn(PyObjectPtr, &VirtualMachine) -> PyResult<PyBuffer>;
pub(crate) type RichCompareFunc = fn(
PyObjectPtr,
PyObjectPtr,
@@ -754,7 +754,7 @@ pub trait AsBuffer: PyValue {
// TODO: `flags` parameter
#[inline]
#[pyslot]
fn slot_as_buffer(zelf: &PyObjectRef, vm: &VirtualMachine) -> PyResult<PyBuffer> {
fn slot_as_buffer(zelf: PyObjectPtr, vm: &VirtualMachine) -> PyResult<PyBuffer> {
let zelf = zelf
.downcast_ref()
.ok_or_else(|| vm.new_type_error("unexpected payload for as_buffer".to_owned()))?;