From 64ada3af8b1f605442522c8d87ed6ed4edf0635d Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Mon, 15 Dec 2025 22:54:30 +0900 Subject: [PATCH 1/2] fix memoryview --- crates/vm/src/builtins/memory.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/vm/src/builtins/memory.rs b/crates/vm/src/builtins/memory.rs index c8656cb136..c1b1496e8c 100644 --- a/crates/vm/src/builtins/memory.rs +++ b/crates/vm/src/builtins/memory.rs @@ -693,12 +693,13 @@ impl PyMemoryView { #[pymethod] fn __len__(&self, vm: &VirtualMachine) -> PyResult { self.try_not_released(vm)?; - Ok(if self.desc.ndim() == 0 { - 1 + if self.desc.ndim() == 0 { + // 0-dimensional memoryview has no length + Err(vm.new_type_error("0-dim memory has no length".to_owned())) } else { // shape for dim[0] - self.desc.dim_desc[0].0 - }) + Ok(self.desc.dim_desc[0].0) + } } #[pymethod] From 6adebaf614bf168d9788186351143d0e062e470b Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Mon, 15 Dec 2025 22:55:23 +0900 Subject: [PATCH 2/2] retype slot zelf --- crates/vm/src/types/slot.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/crates/vm/src/types/slot.rs b/crates/vm/src/types/slot.rs index a4169fdd83..f52e7296a7 100644 --- a/crates/vm/src/types/slot.rs +++ b/crates/vm/src/types/slot.rs @@ -950,8 +950,9 @@ where pub trait Initializer: PyPayload { type Args: FromArgs; - #[pyslot] #[inline] + #[pyslot] + #[pymethod(name = "__init__")] fn slot_init(zelf: PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult<()> { #[cfg(debug_assertions)] let class_name_for_debug = zelf.class().name().to_string(); @@ -979,13 +980,6 @@ pub trait Initializer: PyPayload { Self::init(zelf, args, vm) } - #[pymethod] - #[inline] - fn __init__(zelf: PyRef, args: Self::Args, vm: &VirtualMachine) -> PyResult<()> { - // TODO: check if this is safe. zelf may need to be `PyObjectRef` - Self::init(zelf, args, vm) - } - fn init(zelf: PyRef, args: Self::Args, vm: &VirtualMachine) -> PyResult<()>; } @@ -1340,8 +1334,8 @@ pub trait GetAttr: PyPayload { #[inline] #[pymethod] - fn __getattribute__(zelf: PyRef, name: PyStrRef, vm: &VirtualMachine) -> PyResult { - Self::getattro(&zelf, &name, vm) + fn __getattribute__(zelf: PyObjectRef, name: PyStrRef, vm: &VirtualMachine) -> PyResult { + Self::slot_getattro(&zelf, &name, vm) } } @@ -1371,18 +1365,18 @@ pub trait SetAttr: PyPayload { #[inline] #[pymethod] fn __setattr__( - zelf: PyRef, + zelf: PyObjectRef, name: PyStrRef, value: PyObjectRef, vm: &VirtualMachine, ) -> PyResult<()> { - Self::setattro(&zelf, &name, PySetterValue::Assign(value), vm) + Self::slot_setattro(&zelf, &name, PySetterValue::Assign(value), vm) } #[inline] #[pymethod] - fn __delattr__(zelf: PyRef, name: PyStrRef, vm: &VirtualMachine) -> PyResult<()> { - Self::setattro(&zelf, &name, PySetterValue::Delete, vm) + fn __delattr__(zelf: PyObjectRef, name: PyStrRef, vm: &VirtualMachine) -> PyResult<()> { + Self::slot_setattro(&zelf, &name, PySetterValue::Delete, vm) } }