Why should Py_INCREF(Py_None) be required before returning Py_None in C?
Missing a Py_INCREF will result in an incorrect counting of references for Py_None, which may lead the interpreter to deallocate Py_None. Since Py_None is allocated statically in the Objects/object.c file: PyObject _Py_NoneStruct = { _PyObject_EXTRA_INIT 1, &PyNone_Type }; And in Include/object.h there is the define: #define Py_None (&_Py_NoneStruct) So what will happen, is that the … Read more