Use PyObject_AsReadBuffer instead of bytes().
This commit is contained in:
@@ -3789,20 +3789,20 @@ cdef class _SegmentArrayMessageReader(_MessageReader):
|
|||||||
opts.nestingLimit = nesting_limit
|
opts.nestingLimit = nesting_limit
|
||||||
# take a Python array of bytes and constructs a ConstWordArrayArrayPtr
|
# take a Python array of bytes and constructs a ConstWordArrayArrayPtr
|
||||||
num_segments = len(segments)
|
num_segments = len(segments)
|
||||||
cdef char* ptr
|
cdef const void* ptr
|
||||||
|
cdef Py_ssize_t segment_size
|
||||||
cdef schema_cpp.ConstWordArrayPtr seg_ptr
|
cdef schema_cpp.ConstWordArrayPtr seg_ptr
|
||||||
self._seg_ptrs = <schema_cpp.ConstWordArrayPtr*>malloc(num_segments * sizeof(schema_cpp.ConstWordArrayPtr))
|
self._seg_ptrs = <schema_cpp.ConstWordArrayPtr*>malloc(num_segments * sizeof(schema_cpp.ConstWordArrayPtr))
|
||||||
self._objects_to_pin = []
|
self._objects_to_pin = []
|
||||||
for i in range(0, num_segments):
|
for i in range(0, num_segments):
|
||||||
segment = bytes(segments[i])
|
PyObject_AsReadBuffer(segments[i], &ptr, &segment_size)
|
||||||
ptr = segment
|
|
||||||
if (<uintptr_t>ptr) % 8 != 0:
|
if (<uintptr_t>ptr) % 8 != 0:
|
||||||
aligned = _AlignedBuffer(segment)
|
aligned = _AlignedBuffer(segments[i])
|
||||||
ptr = aligned.buf
|
ptr = aligned.buf
|
||||||
self._objects_to_pin.append(aligned)
|
self._objects_to_pin.append(aligned)
|
||||||
else:
|
else:
|
||||||
self._objects_to_pin.append(segment)
|
self._objects_to_pin.append(segments[i])
|
||||||
seg_ptr = schema_cpp.ConstWordArrayPtr(<schema_cpp.word*>ptr, len(segment)//8)
|
seg_ptr = schema_cpp.ConstWordArrayPtr(<schema_cpp.word*>ptr, segment_size//8)
|
||||||
self._seg_ptrs[i] = seg_ptr
|
self._seg_ptrs[i] = seg_ptr
|
||||||
self.thisptr = new schema_cpp.SegmentArrayMessageReader(
|
self.thisptr = new schema_cpp.SegmentArrayMessageReader(
|
||||||
schema_cpp.ConstWordArrayArrayPtr(self._seg_ptrs, num_segments),
|
schema_cpp.ConstWordArrayArrayPtr(self._seg_ptrs, num_segments),
|
||||||
|
|||||||
Reference in New Issue
Block a user