Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-40170: Remove PyIndex_Check() macro #19375

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions Include/cpython/abstract.h
Expand Up @@ -337,12 +337,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
Expand Down
@@ -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.
6 changes: 3 additions & 3 deletions Objects/abstract.c
Expand Up @@ -1291,15 +1291,15 @@ PyNumber_Absolute(PyObject *o)
return type_error("bad operand type for abs(): '%.200s'", o);
}

#undef PyIndex_Check

int
PyIndex_Check(PyObject *obj)
{
return Py_TYPE(obj)->tp_as_number != NULL &&
Py_TYPE(obj)->tp_as_number->nb_index != NULL;
PyNumberMethods *tp_as_number = Py_TYPE(obj)->tp_as_number;
return (tp_as_number != NULL && tp_as_number->nb_index != NULL);
}


/* Return a Python int from the object item.
Raise TypeError if the result is not an int
or if the object cannot be interpreted as an index.
Expand Down