Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b1c4698

Browse files
committed
Introduced the oddly-missing PyList_CheckExact(), and used it to replace
a hard-coded type check.
1 parent e138f36 commit b1c4698

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

Include/listobject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ typedef struct {
2727
extern DL_IMPORT(PyTypeObject) PyList_Type;
2828

2929
#define PyList_Check(op) PyObject_TypeCheck(op, &PyList_Type)
30+
#define PyList_CheckExact(op) ((op)->ob_type == &PyList_Type)
3031

3132
extern DL_IMPORT(PyObject *) PyList_New(int size);
3233
extern DL_IMPORT(int) PyList_Size(PyObject *);

Python/ceval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ eval_frame(PyFrameObject *f)
989989
case BINARY_SUBSCR:
990990
w = POP();
991991
v = POP();
992-
if (v->ob_type == &PyList_Type && PyInt_CheckExact(w)) {
992+
if (PyList_CheckExact(v) && PyInt_CheckExact(w)) {
993993
/* INLINE: list[int] */
994994
long i = PyInt_AsLong(w);
995995
if (i < 0)

0 commit comments

Comments
 (0)