mirror of
https://github.com/apache/arrow.git
synced 2026-10-28 16:47:19 +08:00
get rid of MutableBuffer
This commit is contained in:
1 parent
08f24a55aa
commit
d14ab870e3
4 files changed
+12
-57
No files matched your search
@@ -152,6 +152,7 @@ cdef extern from "arrow/api.h" namespace "arrow" nogil:
|
||||
uint8_t* data()
|
||||
int64_t size()
|
||||
shared_ptr[CBuffer] parent()
|
||||
c_bool is_mutable() const
|
||||
|
||||
cdef cppclass CMutableBuffer" arrow::MutableBuffer"(CBuffer):
|
||||
CMutableBuffer(const uint8_t* data, int64_t size)
|
||||
|
||||
+7
-26
@@ -532,7 +532,10 @@ cdef class Buffer:
|
||||
buffer.len = self.size
|
||||
buffer.ndim = 1
|
||||
buffer.obj = self
|
||||
buffer.readonly = 1
|
||||
if self.buffer.get().is_mutable():
|
||||
buffer.readonly = 0
|
||||
else:
|
||||
buffer.readonly = 1
|
||||
buffer.shape = self.shape
|
||||
buffer.strides = self.strides
|
||||
buffer.suboffsets = NULL
|
||||
@@ -549,35 +552,13 @@ cdef class Buffer:
|
||||
p[0] = <void*> self.buffer.get().data()
|
||||
return self.size
|
||||
|
||||
|
||||
cdef class MutableBuffer(Buffer):
|
||||
|
||||
def __cinit__(self):
|
||||
pass
|
||||
|
||||
cdef void init_mutable(self, const shared_ptr[CMutableBuffer]& buffer):
|
||||
Buffer.init(self, <shared_ptr[CBuffer]>(buffer))
|
||||
self.mutable_buffer = buffer
|
||||
|
||||
def __getbuffer__(self, cp.Py_buffer* buffer, int flags):
|
||||
|
||||
buffer.buf = <char *>self.mutable_buffer.get().mutable_data()
|
||||
buffer.format = 'b'
|
||||
buffer.internal = NULL
|
||||
buffer.itemsize = 1
|
||||
buffer.len = self.size
|
||||
buffer.ndim = 1
|
||||
buffer.obj = self
|
||||
buffer.readonly = 0
|
||||
buffer.shape = self.shape
|
||||
buffer.strides = self.strides
|
||||
buffer.suboffsets = NULL
|
||||
|
||||
def __getwritebuffer__(self, Py_ssize_t idx, void **p):
|
||||
if not self.buffer.get().is_mutable():
|
||||
raise SystemError("trying to write an immutable buffer")
|
||||
if idx != 0:
|
||||
raise SystemError("accessing non-existent buffer segment")
|
||||
if p != NULL:
|
||||
p[0] = <void*> self.mutable_buffer.get().data()
|
||||
p[0] = <void*> self.buffer.get().data()
|
||||
return self.size
|
||||
|
||||
|
||||
|
||||
@@ -313,13 +313,6 @@ cdef class Buffer:
|
||||
cdef void init(self, const shared_ptr[CBuffer]& buffer)
|
||||
|
||||
|
||||
cdef class MutableBuffer(Buffer):
|
||||
cdef:
|
||||
shared_ptr[CMutableBuffer] mutable_buffer
|
||||
|
||||
cdef void init_mutable(self, const shared_ptr[CMutableBuffer]& buffer)
|
||||
|
||||
|
||||
cdef class NativeFile:
|
||||
cdef:
|
||||
shared_ptr[RandomAccessFile] rd_file
|
||||
|
||||
@@ -26,7 +26,7 @@ from libcpp.vector cimport vector as c_vector
|
||||
from libc.stdint cimport int64_t, uint8_t, uintptr_t
|
||||
from cpython.pycapsule cimport *
|
||||
|
||||
from pyarrow.lib cimport Buffer, MutableBuffer, NativeFile, check_status
|
||||
from pyarrow.lib cimport Buffer, NativeFile, check_status
|
||||
from pyarrow.includes.libarrow cimport (CMutableBuffer, CBuffer,
|
||||
CFixedSizeBufferWriter, CStatus)
|
||||
|
||||
@@ -191,26 +191,6 @@ cdef class PlasmaBuffer(Buffer):
|
||||
self.client.release(self.object_id)
|
||||
|
||||
|
||||
cdef class MutablePlasmaBuffer(MutableBuffer):
|
||||
|
||||
cdef:
|
||||
ObjectID object_id
|
||||
PlasmaClient client
|
||||
|
||||
def __cinit__(self, ObjectID object_id, PlasmaClient client):
|
||||
"""Initialize a PlasmaBuffer."""
|
||||
self.object_id = object_id
|
||||
self.client = client
|
||||
|
||||
def __dealloc__(self):
|
||||
"""
|
||||
Notify Plasma that the object is no longer needed.
|
||||
|
||||
If the plasma client has been shut down, then don't do anything.
|
||||
"""
|
||||
self.client.release(self.object_id)
|
||||
|
||||
|
||||
cdef class PlasmaClient:
|
||||
"""
|
||||
The PlasmaClient is used to interface with a plasma store and manager.
|
||||
@@ -253,10 +233,10 @@ cdef class PlasmaClient:
|
||||
|
||||
cdef _make_mutable_plasma_buffer(self, ObjectID object_id, uint8_t* data,
|
||||
int64_t size):
|
||||
cdef shared_ptr[CMutableBuffer] buffer
|
||||
cdef shared_ptr[CBuffer] buffer
|
||||
buffer.reset(new CMutableBuffer(data, size))
|
||||
result = MutablePlasmaBuffer(object_id, self)
|
||||
result.init_mutable(buffer)
|
||||
result = PlasmaBuffer(object_id, self)
|
||||
result.init(buffer)
|
||||
return result
|
||||
|
||||
@property
|
||||
|
||||
Reference in new issue
Block a user