]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40170: Convert PyObject_CheckBuffer() macro to a function (GH-19376)
authorVictor Stinner <vstinner@python.org>
Tue, 7 Apr 2020 23:13:53 +0000 (01:13 +0200)
committerGitHub <noreply@github.com>
Tue, 7 Apr 2020 23:13:53 +0000 (01:13 +0200)
Convert PyObject_CheckBuffer() macro to a function to hide
implementation details: the macro accessed directly the
PyTypeObject.tp_as_buffer member.

Include/cpython/abstract.h
Misc/NEWS.d/next/C API/2020-04-05-00-02-13.bpo-40170.IFsGZ-.rst [new file with mode: 0644]
Objects/abstract.c

index 9d23c8c11be577c21cebe1084ea1767865e97017..3f834ff727e1d4b90078ef276424c70bde48a7ce 100644 (file)
@@ -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 (file)
index 0000000..fb378fa
--- /dev/null
@@ -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.
index e975edd7c5bc4a64f82dd7c03d665d5649f345ff..49a38d8f6e2903fb76e7bc405ba7e6a7bcc9635f 100644 (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.
  */