Skip to content

Clean up Py2 Influence in move.c #26266

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 1 commit into from
May 2, 2019
Merged
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
20 changes: 6 additions & 14 deletions pandas/util/move.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,9 @@ Distributed under the terms of the BSD Simplified License.
The full license is in the LICENSE file, distributed with this software.
*/

#define PY_SSIZE_T_CLEAN
#include <Python.h>

/* alias this because it is not aliased in Python 3 */
#define PyString_CheckExact PyBytes_CheckExact
#define PyString_AS_STRING PyBytes_AS_STRING
#define PyString_GET_SIZE PyBytes_GET_SIZE

/* in python 3, we cannot intern bytes objects so this is always false */
#define PyString_CHECK_INTERNED(cs) 0

#ifndef Py_TPFLAGS_HAVE_GETCHARBUFFER
#define Py_TPFLAGS_HAVE_GETCHARBUFFER 0
#endif // Py_TPFLAGS_HAVE_GETCHARBUFFER
Expand Down Expand Up @@ -45,8 +38,8 @@ static int
stolenbuf_getbuffer(stolenbufobject *self, Py_buffer *view, int flags) {
return PyBuffer_FillInfo(view,
(PyObject*) self,
(void*) PyString_AS_STRING(self->invalid_bytes),
PyString_GET_SIZE(self->invalid_bytes),
(void*) PyBytes_AS_STRING(self->invalid_bytes),
PyBytes_GET_SIZE(self->invalid_bytes),
0, /* not readonly */
flags);
}
Expand Down Expand Up @@ -128,15 +121,14 @@ static PyObject*
move_into_mutable_buffer(PyObject *self, PyObject *bytes_rvalue) {
stolenbufobject *ret;

if (!PyString_CheckExact(bytes_rvalue)) {
if (!PyBytes_CheckExact(bytes_rvalue)) {
PyErr_SetString(PyExc_TypeError,
"stolenbuf can only steal from bytes objects");
return NULL;
}

if (Py_REFCNT(bytes_rvalue) != 1 || PyString_CHECK_INTERNED(bytes_rvalue)) {
/* there is a reference other than the caller's stack or the string is
interned */
if (Py_REFCNT(bytes_rvalue) != 1) {
// there is a reference other than the caller's stack
PyErr_SetObject(badmove, bytes_rvalue);
return NULL;
}
Expand Down