Skip to content

BLD: fix py37 build warnings #26769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 27, 2019
19 changes: 13 additions & 6 deletions pandas/io/msgpack/_unpacker.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ from cython cimport Py_ssize_t

from cpython cimport (
PyCallable_Check,
PyBUF_SIMPLE, PyObject_GetBuffer, PyBuffer_Release,
PyBUF_SIMPLE, PyObject_GetBuffer, PyBuffer_Release, Py_buffer,
PyBytes_Size,
PyBytes_FromStringAndSize,
PyBytes_AsString)

cdef extern from "Python.h":
ctypedef struct PyObject
cdef int PyObject_AsReadBuffer(object o, const void** buff,
Py_ssize_t* buf_len) except -1

from libc.stdlib cimport free, malloc
from libc.string cimport memcpy, memmove
Expand Down Expand Up @@ -129,8 +127,14 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
Py_ssize_t buf_len
char* cenc = NULL
char* cerr = NULL
Py_buffer view
bytes extra_bytes

PyObject_AsReadBuffer(packed, <const void**>&buf, &buf_len)
# GH#26769 Effectively re-implement deprecated PyObject_AsReadBuffer;
# based on https://xpra.org/trac/ticket/1884
PyObject_GetBuffer(packed, &view, PyBUF_SIMPLE)
buf = <char*>view.buf
buf_len = view.len

if encoding is not None:
if isinstance(encoding, unicode):
Expand All @@ -149,10 +153,13 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
if ret == 1:
obj = unpack_data(&ctx)
if <Py_ssize_t> off < buf_len:
raise ExtraData(obj, PyBytes_FromStringAndSize(
buf + off, buf_len - off))
extra_bytes = PyBytes_FromStringAndSize(buf + off, buf_len - off)
PyBuffer_Release(&view)
raise ExtraData(obj, extra_bytes)
PyBuffer_Release(&view)
return obj
else:
PyBuffer_Release(&view)
raise UnpackValueError("Unpack failed: error = {ret}".format(ret=ret))


Expand Down