Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
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
7 changes: 3 additions & 4 deletions 7 msgpack/_unpacker.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,9 @@ cdef inline int get_data_from_buffer(object obj,
PyBuffer_Release(view)
# create a contiguous copy and get buffer
contiguous = PyMemoryView_GetContiguous(obj, PyBUF_READ, b'C')
PyObject_GetBuffer(contiguous, view, PyBUF_SIMPLE)
# view must hold the only reference to contiguous,
# so memory is freed when view is released
Py_DECREF(contiguous)
if PyObject_GetBuffer(contiguous, view, PyBUF_SIMPLE) == -1:
raise

Comment thread
KowalskiThomas marked this conversation as resolved.
buffer_len[0] = view.len
buf[0] = <char*> view.buf
return 1
Expand Down
2 changes: 1 addition & 1 deletion 2 msgpack/fallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def feed(self, next_bytes):
self._buf_checkpoint = 0

# Use extend here: INPLACE_ADD += doesn't reliably typecast memoryview in jython
self._buffer.extend(view)
self._buffer.extend(view if view.contiguous else view.tobytes())
view.release()
Comment thread
KowalskiThomas marked this conversation as resolved.

def _consume(self):
Expand Down
12 changes: 12 additions & 0 deletions 12 test/test_memoryview.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,15 @@ def test_multidim_memoryview():
data = view.cast(view.format, (3, 2))
packed = packb(data)
assert packed == b"\xc4\x06\x00\x00\x00\x00\x00\x00"


def test_unpack_noncontiguous_memoryview():
# Use a multi-byte value so the padded stride-2 view is non-contiguous.
packed = packb(2**32)
padded = bytearray()
for byte in packed:
padded.append(byte)
padded.append(0)
noncont = memoryview(bytes(padded))[::2]
assert not noncont.c_contiguous
assert unpackb(noncont) == 2**32
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.