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:
Victor Stinner 2020-04-08 01:13:53 +02:00 committed by GitHub
parent 9205520d8c
commit ef5c615f5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 3 deletions

View file

@ -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.
*/