Skip to content
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ from libc.stdint cimport *
from libcpp.cast cimport *
from libcpp cimport bool
from cpython cimport Py_buffer
from cpython.buffer cimport PyBuffer_FillInfo
from cpython.bytes cimport PyBytes_AsString
from cpython.ref cimport PyObject, Py_INCREF, Py_DECREF
from cpython.object cimport Py_TYPE, PyObject_CallObject
Expand Down Expand Up @@ -1007,26 +1008,17 @@ cdef class PyWholeMemoryUniqueID:
return self.shape[0]

def __getbuffer__(self, Py_buffer *buffer, int flags):
buffer.buf = &self.wholememory_unique_id.internal[0]
buffer.format = 'c'
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually the default is NULL or b"B", which is uint8_t (or unsigned char). This is what PyBuffer_FillInfo uses. Also this is how bytes and bytearray work

IIUC b"c" is basically equivalent, but is seldom used. So switching to b"B" should still work in similar cases and work better in cases where b"B" is expected

Though please let me know if there is additional context we should consider here

buffer.internal = NULL
buffer.itemsize = 1
buffer.len = self.shape[0]
buffer.ndim = 1
buffer.obj = self
buffer.readonly = 0
buffer.shape = self.shape
buffer.strides = self.strides
buffer.suboffsets = NULL
PyBuffer_FillInfo(
buffer,
self,
&self.wholememory_unique_id.internal[0],
self.shape[0],
False,
flags
)

def __releasebuffer__(self, Py_buffer *buffer):
buffer.buf = NULL
buffer.format = 'c'
buffer.len = 0
buffer.ndim = 0
buffer.obj = None
buffer.shape = NULL
buffer.strides = NULL
pass

def __dlpack__(self, stream=None):
cdef DLManagedTensor * dlm_tensor = \
Expand Down Expand Up @@ -1216,13 +1208,7 @@ cdef class PyWholeMemoryFlattenDlpack:
buffer.suboffsets = NULL

def __releasebuffer__(self, Py_buffer *buffer):
buffer.buf = NULL
buffer.format = 'c'
buffer.len = 0
buffer.ndim = 0
buffer.obj = None
buffer.shape = NULL
buffer.strides = NULL
pass

@property
def ptr(self):
Expand Down
Loading