Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
memoryview
  • Loading branch information
OddCoincidence committed Mar 9, 2019
commit 776dd805919a5e9a9e552facf263ac220d81b065
22 changes: 19 additions & 3 deletions vm/src/obj/objmemory.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
use crate::pyobject::{PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyResult, TypeProtocol};
use crate::pyobject::{
PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectPayload2, PyObjectRef, PyResult,
TypeProtocol,
};
use crate::vm::VirtualMachine;

#[derive(Debug)]
pub struct PyMemoryView {
obj: PyObjectRef,
}

impl PyObjectPayload2 for PyMemoryView {
fn required_type(ctx: &PyContext) -> PyObjectRef {
ctx.memoryview_type()
}
}

pub fn new_memory_view(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(vm, args, required = [(cls, None), (bytes_object, None)]);
vm.ctx.set_attr(&cls, "obj", bytes_object.clone());
Ok(PyObject::new(
PyObjectPayload::MemoryView {
obj: bytes_object.clone(),
PyObjectPayload::AnyRustValue {
value: Box::new(PyMemoryView {
obj: bytes_object.clone(),
}),
},
cls.clone(),
))
Expand Down
4 changes: 0 additions & 4 deletions vm/src/pyobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1490,9 +1490,6 @@ pub enum PyObjectPayload {
stop: Option<BigInt>,
step: Option<BigInt>,
},
MemoryView {
obj: PyObjectRef,
},
WeakRef {
referent: PyObjectWeakRef,
},
Expand Down Expand Up @@ -1526,7 +1523,6 @@ impl PyObjectPayload2 for PyIteratorValue {
impl fmt::Debug for PyObjectPayload {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
PyObjectPayload::MemoryView { ref obj } => write!(f, "bytes/bytearray {:?}", obj),
PyObjectPayload::WeakRef { .. } => write!(f, "weakref"),
PyObjectPayload::Slice { .. } => write!(f, "slice"),
PyObjectPayload::AnyRustValue { value } => value.fmt(f),
Expand Down