]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40170: Remove PyIndex_Check() macro (GH-19428)
authorVictor Stinner <vstinner@python.org>
Wed, 8 Apr 2020 00:26:41 +0000 (02:26 +0200)
committerGitHub <noreply@github.com>
Wed, 8 Apr 2020 00:26:41 +0000 (02:26 +0200)
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.

Include/cpython/abstract.h
Misc/NEWS.d/next/C API/2020-04-04-23-51-59.bpo-40170.uXQ701.rst [new file with mode: 0644]
Objects/abstract.c

index 3f834ff727e1d4b90078ef276424c70bde48a7ce..7bc80833a746ef00f1e1ae805511489aedc423a3 100644 (file)
@@ -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 (file)
index 0000000..22bdc74
--- /dev/null
@@ -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.
index b5d91dbab0c1dfaf19f11888c390919877f0d31e..7e1e51b4c87c2d60c2b81d1ad2e1e753274304e7 100644 (file)
@@ -1309,8 +1309,6 @@ PyNumber_Absolute(PyObject *o)
 }
 
 
-#undef PyIndex_Check
-
 int
 PyIndex_Check(PyObject *obj)
 {