[Python-checkins] bpo-40170: Convert PyObject_CheckBuffer() macro to a function (GH-19376)

Victor Stinner webhook-mailer at python.org
Tue Apr 7 19:13:57 EDT 2020


https://github.com/python/cpython/commit/ef5c615f5ae72c4f6979159c94da46afefbfab9a
commit: ef5c615f5ae72c4f6979159c94da46afefbfab9a
branch: master
author: Victor Stinner <vstinner at python.org>
committer: GitHub <noreply at github.com>
date: 2020-04-08T01:13:53+02:00
summary:

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.

files:
A Misc/NEWS.d/next/C API/2020-04-05-00-02-13.bpo-40170.IFsGZ-.rst
M Include/cpython/abstract.h
M Objects/abstract.c

diff --git a/Include/cpython/abstract.h b/Include/cpython/abstract.h
index 9d23c8c11be57..3f834ff727e1d 100644
--- a/Include/cpython/abstract.h
+++ b/Include/cpython/abstract.h
@@ -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
diff --git a/Misc/NEWS.d/next/C API/2020-04-05-00-02-13.bpo-40170.IFsGZ-.rst b/Misc/NEWS.d/next/C API/2020-04-05-00-02-13.bpo-40170.IFsGZ-.rst
new file mode 100644
index 0000000000000..fb378faa90c51
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2020-04-05-00-02-13.bpo-40170.IFsGZ-.rst	
@@ -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.
diff --git a/Objects/abstract.c b/Objects/abstract.c
index e975edd7c5bc4..49a38d8f6e290 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -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.
  */



More information about the Python-checkins mailing list