Esempio n. 1
0
def PyMemoryView_FromBuffer(space, view):
    """Create a memoryview object wrapping the given buffer structure view.
    The memoryview object then owns the buffer represented by view, which
    means you shouldn't try to call PyBuffer_Release() yourself: it
    will be done on deallocation of the memoryview object."""
    if not view.c_buf:
        raise oefmt(
            space.w_ValueError,
            "cannot make memory view from a buffer with a NULL data "
            "pointer")
    buf = CBuffer(space, view.c_buf, view.c_len, view.c_obj)
    return space.wrap(W_MemoryView(buf))
def PyMemoryView_FromMemory(space, mem, size, flags):
    """Expose a raw memory area as a view of contiguous bytes. flags can be
    PyBUF_READ or PyBUF_WRITE. view->format is set to "B" (unsigned bytes).
    The memoryview has complete buffer information.
    """
    readonly = int(widen(flags) == PyBUF_WRITE)
    view = CPyBuffer(space,
                     cts.cast('void*', mem),
                     size,
                     None,
                     readonly=readonly)
    w_mview = W_MemoryView(view)
    return w_mview
Esempio n. 3
0
 def newmemoryview(self, view):
     return W_MemoryView(view)
Esempio n. 4
0
 def newbuffer(self, w_obj):
     return W_MemoryView(w_obj)
Esempio n. 5
0
 def newmemoryview(self, w_obj):
     return W_MemoryView(w_obj)
Esempio n. 6
0
 def getbuffer_w(self, space):
     return space.wrap(W_MemoryView(BytesIOBuffer(self)))