Skip to content

bpo-40170: Convert PyObject_CheckBuffer() macro to a function #19376

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
Apr 7, 2020
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
4 changes: 1 addition & 3 deletions Include/cpython/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,7 @@ PyAPI_FUNC(Py_ssize_t) PyObject_LengthHint(PyObject *o, Py_ssize_t);
/* === New Buffer API ============================================ */

/* Return 1 if the getbuffer function is available, otherwise return 0. */
#define PyObject_CheckBuffer(obj) \
((Py_TYPE(obj)->tp_as_buffer != NULL) && \
(Py_TYPE(obj)->tp_as_buffer->bf_getbuffer != NULL))
PyAPI_FUNC(int) PyObject_CheckBuffer(PyObject *obj);

/* This is a C-API version of the getbuffer function call. It checks
to make sure object has the required function pointer and issues the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Convert :c:func:`PyObject_CheckBuffer` macro to a function to hide
implementation details: the macro accessed directly the
:c:member:`PyTypeObject.tp_as_buffer` member.
10 changes: 10 additions & 0 deletions Objects/abstract.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,16 @@ PyObject_DelItemString(PyObject *o, const char *key)
return ret;
}


/* Return 1 if the getbuffer function is available, otherwise return 0. */
int
PyObject_CheckBuffer(PyObject *obj)
{
PyBufferProcs *tp_as_buffer = Py_TYPE(obj)->tp_as_buffer;
return (tp_as_buffer != NULL && tp_as_buffer->bf_getbuffer != NULL);
}


/* We release the buffer right after use of this function which could
cause issues later on. Don't use these functions in new code.
*/
Expand Down