mirror of https://github.com/python/cpython
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.
This commit is contained in:
parent
9205520d8c
commit
ef5c615f5a
|
@ -264,9 +264,7 @@ PyAPI_FUNC(Py_ssize_t) PyObject_LengthHint(PyObject *o, Py_ssize_t);
|
||||||
/* === New Buffer API ============================================ */
|
/* === New Buffer API ============================================ */
|
||||||
|
|
||||||
/* Return 1 if the getbuffer function is available, otherwise return 0. */
|
/* Return 1 if the getbuffer function is available, otherwise return 0. */
|
||||||
#define PyObject_CheckBuffer(obj) \
|
PyAPI_FUNC(int) PyObject_CheckBuffer(PyObject *obj);
|
||||||
((Py_TYPE(obj)->tp_as_buffer != NULL) && \
|
|
||||||
(Py_TYPE(obj)->tp_as_buffer->bf_getbuffer != NULL))
|
|
||||||
|
|
||||||
/* This is a C-API version of the getbuffer function call. It checks
|
/* 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
|
to make sure object has the required function pointer and issues the
|
||||||
|
|
|
@ -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.
|
|
@ -277,6 +277,16 @@ PyObject_DelItemString(PyObject *o, const char *key)
|
||||||
return ret;
|
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
|
/* We release the buffer right after use of this function which could
|
||||||
cause issues later on. Don't use these functions in new code.
|
cause issues later on. Don't use these functions in new code.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue