Skip to content

Commit 776dd80

Browse files
memoryview
1 parent 157d18d commit 776dd80

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

vm/src/obj/objmemory.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1-
use crate::pyobject::{PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyResult, TypeProtocol};
1+
use crate::pyobject::{
2+
PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectPayload2, PyObjectRef, PyResult,
3+
TypeProtocol,
4+
};
25
use crate::vm::VirtualMachine;
36

7+
#[derive(Debug)]
8+
pub struct PyMemoryView {
9+
obj: PyObjectRef,
10+
}
11+
12+
impl PyObjectPayload2 for PyMemoryView {
13+
fn required_type(ctx: &PyContext) -> PyObjectRef {
14+
ctx.memoryview_type()
15+
}
16+
}
17+
418
pub fn new_memory_view(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
519
arg_check!(vm, args, required = [(cls, None), (bytes_object, None)]);
620
vm.ctx.set_attr(&cls, "obj", bytes_object.clone());
721
Ok(PyObject::new(
8-
PyObjectPayload::MemoryView {
9-
obj: bytes_object.clone(),
22+
PyObjectPayload::AnyRustValue {
23+
value: Box::new(PyMemoryView {
24+
obj: bytes_object.clone(),
25+
}),
1026
},
1127
cls.clone(),
1228
))

vm/src/pyobject.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,9 +1490,6 @@ pub enum PyObjectPayload {
14901490
stop: Option<BigInt>,
14911491
step: Option<BigInt>,
14921492
},
1493-
MemoryView {
1494-
obj: PyObjectRef,
1495-
},
14961493
WeakRef {
14971494
referent: PyObjectWeakRef,
14981495
},
@@ -1526,7 +1523,6 @@ impl PyObjectPayload2 for PyIteratorValue {
15261523
impl fmt::Debug for PyObjectPayload {
15271524
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
15281525
match self {
1529-
PyObjectPayload::MemoryView { ref obj } => write!(f, "bytes/bytearray {:?}", obj),
15301526
PyObjectPayload::WeakRef { .. } => write!(f, "weakref"),
15311527
PyObjectPayload::Slice { .. } => write!(f, "slice"),
15321528
PyObjectPayload::AnyRustValue { value } => value.fmt(f),

0 commit comments

Comments
 (0)