Skip to content

Commit b1bbdc4

Browse files
committed
Make sure that tp_as_xxx methods are never NULL in PyType_Ready()
PyType_Ready() now sets type tp_as_xxx members to a structure filled of NULL if a member is NULL. It avoids checking if tp_as_xxx is NULL in Objects/abstract.c functions.
1 parent e66bec0 commit b1bbdc4

22 files changed

Lines changed: 205 additions & 367 deletions

Include/internal/pycore_abstract.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ extern "C" {
1212
static inline int
1313
_PyIndex_Check(PyObject *obj)
1414
{
15-
PyNumberMethods *tp_as_number = Py_TYPE(obj)->tp_as_number;
16-
return (tp_as_number != NULL && tp_as_number->nb_index != NULL);
15+
return (Py_TYPE(obj)->tp_as_number->nb_index != NULL);
1716
}
1817

1918
// Exported for external JIT support

Include/internal/pycore_slots_generated.h

Lines changed: 0 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_bisectmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ get_sq_item(PyObject *s)
3535
// The parts of PySequence_GetItem that we only need to do once
3636
PyTypeObject *tp = Py_TYPE(s);
3737
PySequenceMethods *m = tp->tp_as_sequence;
38-
if (m && m->sq_item) {
38+
if (m->sq_item) {
3939
return m->sq_item;
4040
}
4141
const char *msg;
42-
if (tp->tp_as_mapping && tp->tp_as_mapping->mp_subscript) {
42+
if (tp->tp_as_mapping->mp_subscript) {
4343
msg = "%.200s is not a sequence";
4444
}
4545
else {

Modules/_testinternalcapi/test_cases.c.h

Lines changed: 2 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)