8000 Drop old buffer protocol support (#383) · eb-emilio/msgpack-python@9ae4370 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9ae4370

Browse files
authored
Drop old buffer protocol support (msgpack#383)
1 parent af4eea4 commit 9ae4370

File tree

1 file changed

+22
-38
lines changed

1 file changed

+22
-38
lines changed

msgpack/_unpacker.pyx

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -109,38 +109,26 @@ def default_read_extended_type(typecode, data):
109109
cdef inline int get_data_from_buffer(object obj,
110110
Py_buffer *view,
111111
char **buf,
112-
Py_ssize_t *buffer_len,
113-
int *new_protocol) except 0:
112+
Py_ssize_t *buffer_len) except 0:
114113
cdef object contiguous
115114
cdef Py_buffer tmp
116-
if PyObject_CheckBuffer(obj):
117-
new_protocol[0] = 1
118-
if PyObject_GetBuffer(obj, view, PyBUF_FULL_RO) == -1:
119-
raise
120-
if view.itemsize != 1:
121-
PyBuffer_Release(view)
122-
raise BufferError("cannot unpack from multi-byte object")
123-
if PyBuffer_IsContiguous(view, b'A') == 0:
124-
PyBuffer_Release(view)
125-
# create a contiguous copy and get buffer
126-
contiguous = PyMemoryView_GetContiguous(obj, PyBUF_READ, b'C')
127-
PyObject_GetBuffer(contiguous, view, PyBUF_SIMPLE)
128-
# view must hold the only reference to contiguous,
129-
# so memory is freed when view is released
130-
Py_DECREF(contiguous)
131-
buffer_len[0] = view.len
132-
buf[0] = <char*> view.buf
133-
return 1
134-
else:
135-
new_protocol[0] = 0
136-
if PyObject_AsReadBuffer(obj, <const void**> buf, buffer_len) == -1:
137-
raise BufferError("could not get memoryview")
138-
PyErr_WarnEx(RuntimeWarning,
139-
"using old buffer interface to unpack %s; "
140-
"this leads to unpacking errors if slicing is used and "
141-
"will be removed in a future version" % type(obj),
142-
1)
143-
return 1
115+
if PyObject_GetBuffer(obj, view, PyBUF_FULL_RO) == -1:
116+
raise
117+
if view.itemsize != 1:
118+
PyBuffer_Release(view)
119+
raise BufferError("cannot unpack from multi-byte object")
120+
if PyBuffer_IsContiguous(view, b'A') == 0:
121+
PyBuffer_Release(view)
122+
# create a contiguous copy and get buffer
123+
contiguous = PyMemoryView_GetContiguous(obj, PyBUF_READ, b'C')
124+
PyObject_GetBuffer(contiguous, view, PyBUF_SIMPLE)
125+
# view must hold the only reference to contiguous,
126+
# so memory is freed when view is released
127+
Py_DECREF(contiguous)
128+
buffer_len[0] = view.len
129+
buf[0] = <char*> view.buf
130+
return 1
131+
144132

145133
def unpackb(object packed, *, object object_hook=None, object list_hook=None,
146134
bint use_list=True, bint raw=True, bint strict_map_key=False,
@@ -172,12 +160,11 @@ def unpackb(object packed, *, object object_hook=None, object list_hook=None,
172160
cdef char* buf = NULL
173161
cdef Py_ssize_t buf_len
174162
cdef const char* cerr = NULL
175-
cdef int new_protocol = 0
176163

177164
if unicode_errors is not None:
178165
cerr = unicode_errors
179166

180-
get_data_from_buffer(packed, &view, &buf, &buf_len, &new_protocol)
167+
get_data_from_buffer(packed, &view, &buf, &buf_len)
181168

182169
if max_str_len == -1:
183170
max_str_len = buf_len
@@ -196,8 +183,7 @@ def unpackb(object packed, *, object object_hook=None, object list_hook=None,
196183
max_str_len, max_bin_len, max_array_len, max_map_len, max_ext_len)
197184
ret = unpack_construct(&ctx, buf, buf_len, &off)
198185
finally:
199-
if new_protocol:
200-
PyBuffer_Release(&view);
186+
PyBuffer_Release(&view);
201187

202188
if ret == 1:
203189
obj = unpack_data(&ctx)
@@ -392,20 +378,18 @@ cdef class Unpacker(object):
392378
def feed(self, object next_bytes):
393379
"""Append `next_bytes` to internal buffer."""
394380
cdef Py_buffer pybuff
395-
cdef int new_protocol = 0
396381
cdef char* buf
397382
cdef Py_ssize_t buf_len
398383

399384
if self.file_like is not None:
400385
raise AssertionError(
401386
"unpacker.feed() is not be able to use with `file_like`.")
402387

403-
get_data_from_buffer(next_bytes, &pybuff, &buf, &buf_len, &new_protocol)
388+
get_data_from_buffer(next_bytes, &pybuff, &buf, 6804 &buf_len)
404389
try:
405390
self.append_buffer(buf, buf_len)
406391
finally:
407-
if new_protocol:
408-
PyBuffer_Release(&pybuff)
392+
PyBuffer_Release(&pybuff)
409393

410394
cdef append_buffer(self, void* _buf, Py_ssize_t _buf_len):
411395
cdef:

0 commit comments

Comments
 (0)
0