Skip to content

Commit 70ebe71

Browse files
committed
use PyType_GetBaseByToken
1 parent 72dfba4 commit 70ebe71

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

Modules/arraymodule.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,6 +2965,7 @@ static PyType_Slot array_slots[] = {
29652965
{Py_tp_alloc, PyType_GenericAlloc},
29662966
{Py_tp_new, array_new},
29672967
{Py_tp_traverse, array_tp_traverse},
2968+
{Py_tp_token, Py_TP_USE_SPEC},
29682969

29692970
/* as sequence */
29702971
{Py_sq_length, array_length},
@@ -3207,20 +3208,15 @@ static inline int
32073208
array_subscr_guard(PyObject *lhs, PyObject *rhs)
32083209
{
32093210
PyObject *exc = PyErr_GetRaisedException();
3210-
PyObject *module = PyType_GetModuleByDef(Py_TYPE(lhs), &arraymodule);
3211-
if (module == NULL) {
3212-
if (!PyErr_Occurred() || PyErr_ExceptionMatches(PyExc_TypeError)) {
3213-
/* lhs is not an array instance - ignore the TypeError (if any) */
3214-
PyErr_SetRaisedException(exc);
3215-
return 0;
3216-
}
3217-
else {
3218-
_PyErr_ChainExceptions1(exc);
3219-
return -1;
3211+
int ret = PyType_GetBaseByToken(Py_TYPE(lhs), &array_spec, NULL);
3212+
if (ret < 0) {
3213+
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
3214+
PyErr_Clear();
3215+
ret = 0;
32203216
}
32213217
}
3222-
PyErr_SetRaisedException(exc);
3223-
return array_Check(lhs, get_array_state(module));
3218+
_PyErr_ChainExceptions1(exc);
3219+
return ret;
32243220
}
32253221

32263222
static PyObject *

0 commit comments

Comments
 (0)