PyTuple_Check and other type check functions didn't check the NULL pointer

NotGuru xu.mathena at gmail.com
Sun Mar 23 19:01:31 EDT 2008


I was writing some C extensions for Python and use PyTupleType_Check
extensively. I found that all the PySomeType_Check macros directly
delegate the job to PyObject_TypeCheck(op, &PyType_Type). The
PyObject_TypeCheck(op, &PyType_Type) is again a macro and defined as
((ob)->ob_type == (tp) || PyType_IsSubtype((ob)->ob_type, (tp)))

in object.h.

My questions is: is it necessary to check the null pointer in the
macro or it's a job for the user? Semantically all the type check
should report a false if a null pointer is encountered. I've already
had the patch to this issue but I am not sure if I think this problem
right.  I don't know if there are some python core developers around
but I would like to hear all opinions towards this.

BTW, if the user didn't check null pointer before call the function, a
segmentation fault might occur.




More information about the Python-list mailing list