Skip to content

Commit ef5c615

Browse files
authored
bpo-40170: Convert PyObject_CheckBuffer() macro to a function (GH-19376)
Convert PyObject_CheckBuffer() macro to a function to hide implementation details: the macro accessed directly the PyTypeObject.tp_as_buffer member.
1 parent 9205520 commit ef5c615

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

Include/cpython/abstract.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,7 @@ PyAPI_FUNC(Py_ssize_t) PyObject_LengthHint(PyObject *o, Py_ssize_t);
264264
/* === New Buffer API ============================================ */
265265

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

271269
/* This is a C-API version of the getbuffer function call. It checks
272270
to make sure object has the required function pointer and issues the
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Convert :c:func:`PyObject_CheckBuffer` macro to a function to hide
2+
implementation details: the macro accessed directly the
3+
:c:member:`PyTypeObject.tp_as_buffer` member.

Objects/abstract.c

+10
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,16 @@ PyObject_DelItemString(PyObject *o, const char *key)
277277
return ret;
278278
}
279279

280+
281+
/* Return 1 if the getbuffer function is available, otherwise return 0. */
282+
int
283+
PyObject_CheckBuffer(PyObject *obj)
284+
{
285+
PyBufferProcs *tp_as_buffer = Py_TYPE(obj)->tp_as_buffer;
286+
return (tp_as_buffer != NULL && tp_as_buffer->bf_getbuffer != NULL);
287+
}
288+
289+
280290
/* We release the buffer right after use of this function which could
281291
cause issues later on. Don't use these functions in new code.
282292
*/

0 commit comments

Comments
 (0)