Content-Length: 330705 | pFad | http://github.com/RustPython/RustPython/pull/646/commits/776dd805919a5e9a9e552facf263ac220d81b065

A4 Convert memoryview and slice to Any payload by OddCoincidence · Pull Request #646 · RustPython/RustPython · GitHub
Skip to content

Convert memoryview and slice to Any payload #646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 10, 2019
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








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/RustPython/RustPython/pull/646/commits/776dd805919a5e9a9e552facf263ac220d81b065

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy