Make PySequence_Check() and PyMapping_Check() handle NULL inputs. This
goes beyond what most of the other checks do, but it is nice defensive
programming and solves the OP's problem.
int
PySequence_Check(PyObject *s)
{
- if (PyInstance_Check(s))
+ if (s && PyInstance_Check(s))
return PyObject_HasAttrString(s, "__getitem__");
return s != NULL && s->ob_type->tp_as_sequence &&
s->ob_type->tp_as_sequence->sq_item != NULL;
int
PyMapping_Check(PyObject *o)
{
- if (PyInstance_Check(o))
+ if (o && PyInstance_Check(o))
return PyObject_HasAttrString(o, "__getitem__");
return o && o->ob_type->tp_as_mapping &&