[Python-checkins] bpo-40170: Remove PyIndex_Check() macro (GH-19428)

Victor Stinner webhook-mailer at python.org
Tue Apr 7 20:26:49 EDT 2020


https://github.com/python/cpython/commit/307b9d0144e719b016a47fcc43397c070615e01e
commit: 307b9d0144e719b016a47fcc43397c070615e01e
branch: master
author: Victor Stinner <vstinner at python.org>
committer: GitHub <noreply at github.com>
date: 2020-04-08T02:26:41+02:00
summary:

bpo-40170: Remove PyIndex_Check() macro (GH-19428)

Always declare PyIndex_Check() as an opaque function to hide
implementation details: remove PyIndex_Check() macro. The macro
accessed directly the PyTypeObject.tp_as_number member.

files:
A Misc/NEWS.d/next/C API/2020-04-04-23-51-59.bpo-40170.uXQ701.rst
M Include/cpython/abstract.h
M Objects/abstract.c

diff --git a/Include/cpython/abstract.h b/Include/cpython/abstract.h
index 3f834ff727e1d..7bc80833a746e 100644
--- a/Include/cpython/abstract.h
+++ b/Include/cpython/abstract.h
@@ -335,12 +335,6 @@ PyAPI_FUNC(void) PyBuffer_Release(Py_buffer *view);
     (Py_TYPE(obj)->tp_iternext != NULL && \
      Py_TYPE(obj)->tp_iternext != &_PyObject_NextNotImplemented)
 
-/* === Number Protocol ================================================== */
-
-#define PyIndex_Check(obj)                              \
-    (Py_TYPE(obj)->tp_as_number != NULL &&            \
-     Py_TYPE(obj)->tp_as_number->nb_index != NULL)
-
 /* === Sequence protocol ================================================ */
 
 /* Assume tp_as_sequence and sq_item exist and that 'i' does not
diff --git a/Misc/NEWS.d/next/C API/2020-04-04-23-51-59.bpo-40170.uXQ701.rst b/Misc/NEWS.d/next/C API/2020-04-04-23-51-59.bpo-40170.uXQ701.rst
new file mode 100644
index 0000000000000..22bdc74904f41
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2020-04-04-23-51-59.bpo-40170.uXQ701.rst	
@@ -0,0 +1,3 @@
+Always declare :c:func:`PyIndex_Check` as an opaque function to hide
+implementation details: remove ``PyIndex_Check()`` macro. The macro accessed
+directly the :c:member:`PyTypeObject.tp_as_number` member.
diff --git a/Objects/abstract.c b/Objects/abstract.c
index b5d91dbab0c1d..7e1e51b4c87c2 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -1309,8 +1309,6 @@ PyNumber_Absolute(PyObject *o)
 }
 
 
-#undef PyIndex_Check
-
 int
 PyIndex_Check(PyObject *obj)
 {



More information about the Python-checkins mailing list