Skip to content

Commit 73039e9

Browse files
committed
raise BufferError consistently in cffi backend
1 parent d33861b commit 73039e9

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

zmq/backend/cffi/message.py

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ def __init__(self, data=None, track=False, copy=None, copy_threshold=None):
8282
self._bytes = data
8383

8484
self._buffer = memoryview(data)
85+
if not self._buffer.contiguous:
86+
raise BufferError("memoryview: underlying buffer is not contiguous")
87+
# from_buffer silently copies if memory is not contiguous
8588
c_data = ffi.from_buffer(self._buffer)
8689
data_len_c = self._buffer.nbytes
8790

zmq/backend/cffi/socket.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,9 @@ def recv(self, flags=0, copy=True, track=False):
338338
def recv_into(self, buffer, /, *, nbytes: int = 0, flags: int = 0) -> int:
339339
view = memoryview(buffer)
340340
if not view.contiguous:
341-
raise ValueError("Can only recv_into contiguous buffers")
341+
raise BufferError("Can only recv_into contiguous buffers")
342342
if view.readonly:
343-
raise ValueError("Cannot recv_into readonly buffer")
343+
raise BufferError("Cannot recv_into readonly buffer")
344344
if nbytes < 0:
345345
raise ValueError(f"{nbytes=} must be non-negative")
346346
view_bytes = view.nbytes

0 commit comments

Comments
 (0)