as_mapping uses ptr

This commit is contained in:
Jeong YunWon
2021-10-15 05:42:13 +09:00
parent 77b904ce64
commit 113ad3bdea
2 changed files with 5 additions and 5 deletions

View File

@@ -29,7 +29,7 @@ impl PyMapping<PyObjectRef> {
pub fn check(obj: &PyObjectRef, vm: &VirtualMachine) -> bool {
obj.class()
.mro_find_map(|x| x.slots.as_mapping.load())
.map(|f| f(obj, vm).subscript.is_some())
.map(|f| obj.with_ptr(|obj| f(obj, vm)).subscript.is_some())
.unwrap_or(false)
}
@@ -37,7 +37,7 @@ impl PyMapping<PyObjectRef> {
let obj_cls = self.0.class();
for cls in obj_cls.iter_mro() {
if let Some(f) = cls.slots.as_mapping.load() {
return f(&self.0, vm);
return self.0.with_ptr(|zelf| f(zelf, vm));
}
}
PyMappingMethods::default()

View File

@@ -128,7 +128,7 @@ impl Default for PyTypeFlags {
}
pub(crate) type GenericMethod = fn(PyObjectPtr, FuncArgs, &VirtualMachine) -> PyResult;
pub(crate) type AsMappingFunc = fn(&PyObjectRef, &VirtualMachine) -> PyMappingMethods;
pub(crate) type AsMappingFunc = fn(PyObjectPtr, &VirtualMachine) -> PyMappingMethods;
pub(crate) type HashFunc = fn(PyObjectPtr, &VirtualMachine) -> PyResult<PyHash>;
// CallFunc = GenericMethod
pub(crate) type GetattroFunc = fn(PyObjectRef, PyStrRef, &VirtualMachine) -> PyResult;
@@ -150,7 +150,7 @@ pub(crate) type DescrSetFunc =
pub(crate) type NewFunc = fn(PyTypeRef, FuncArgs, &VirtualMachine) -> PyResult;
pub(crate) type DelFunc = fn(PyObjectPtr, &VirtualMachine) -> PyResult<()>;
fn as_mapping_wrapper(zelf: &PyObjectRef, _vm: &VirtualMachine) -> PyMappingMethods {
fn as_mapping_wrapper(zelf: PyObjectPtr, _vm: &VirtualMachine) -> PyMappingMethods {
macro_rules! then_some_closure {
($cond:expr, $closure:expr) => {
if $cond {
@@ -768,7 +768,7 @@ pub trait AsBuffer: PyValue {
pub trait AsMapping: PyValue {
#[inline]
#[pyslot]
fn slot_as_mapping(zelf: &PyObjectRef, vm: &VirtualMachine) -> PyMappingMethods {
fn slot_as_mapping(zelf: PyObjectPtr, vm: &VirtualMachine) -> PyMappingMethods {
let zelf = unsafe { zelf.downcast_unchecked_ref::<Self>() };
Self::as_mapping(zelf, vm)
}