Issue #28999: Use Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE wherever

possible.  Patch is writen with Coccinelle.
This commit is contained in:
Serhiy Storchaka 2017-01-23 09:47:21 +02:00
parent 60e6e962ba
commit 228b12edcc
57 changed files with 225 additions and 445 deletions

View file

@ -419,8 +419,7 @@ static PyObject *
member_get_doc(PyMemberDescrObject *descr, void *closure)
{
if (descr->d_member->doc == NULL) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
return PyUnicode_FromString(descr->d_member->doc);
}
@ -435,8 +434,7 @@ static PyObject *
getset_get_doc(PyGetSetDescrObject *descr, void *closure)
{
if (descr->d_getset->doc == NULL) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
return PyUnicode_FromString(descr->d_getset->doc);
}

View file

@ -184,8 +184,7 @@ static PyObject *
BaseException_get_args(PyBaseExceptionObject *self)
{
if (self->args == NULL) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
Py_INCREF(self->args);
return self->args;
@ -210,8 +209,7 @@ static PyObject *
BaseException_get_tb(PyBaseExceptionObject *self)
{
if (self->traceback == NULL) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
Py_INCREF(self->traceback);
return self->traceback;

View file

@ -456,8 +456,7 @@ static PyMethodDef stdprinter_methods[] = {
static PyObject *
get_closed(PyStdPrinter_Object *self, void *closure)
{
Py_INCREF(Py_False);
return Py_False;
Py_RETURN_FALSE;
}
static PyObject *

View file

@ -322,8 +322,7 @@ static PyObject *
func_get_defaults(PyFunctionObject *op)
{
if (op->func_defaults == NULL) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
Py_INCREF(op->func_defaults);
return op->func_defaults;
@ -350,8 +349,7 @@ static PyObject *
func_get_kwdefaults(PyFunctionObject *op)
{
if (op->func_kwdefaults == NULL) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
Py_INCREF(op->func_kwdefaults);
return op->func_kwdefaults;

View file

@ -402,8 +402,7 @@ gen_close(PyGenObject *gen, PyObject *args)
if (PyErr_ExceptionMatches(PyExc_StopIteration)
|| PyErr_ExceptionMatches(PyExc_GeneratorExit)) {
PyErr_Clear(); /* ignore these errors */
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
return NULL;
}

View file

@ -2284,12 +2284,10 @@ list_richcompare(PyObject *v, PyObject *w, int op)
/* We have an item that differs -- shortcuts for EQ/NE */
if (op == Py_EQ) {
Py_INCREF(Py_False);
return Py_False;
Py_RETURN_FALSE;
}
if (op == Py_NE) {
Py_INCREF(Py_True);
return Py_True;
Py_RETURN_TRUE;
}
/* Compare the final item again using the proper operator */

View file

@ -631,12 +631,10 @@ tuplerichcompare(PyObject *v, PyObject *w, int op)
/* We have an item that differs -- shortcuts for EQ/NE */
if (op == Py_EQ) {
Py_INCREF(Py_False);
return Py_False;
Py_RETURN_FALSE;
}
if (op == Py_NE) {
Py_INCREF(Py_True);
return Py_True;
Py_RETURN_TRUE;
}
/* Compare the final item again using the proper operator */

View file

@ -140,8 +140,7 @@ _PyType_GetDocFromInternalDoc(const char *name, const char *internal_doc)
const char *doc = _PyType_DocWithoutSignature(name, internal_doc);
if (!doc || *doc == '\0') {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
return PyUnicode_FromString(doc);
@ -158,8 +157,7 @@ _PyType_GetTextSignatureFromInternalDoc(const char *name, const char *internal_d
else
end = NULL;
if (!end) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
/* back "end" up until it points just past the final ')' */
@ -761,8 +759,7 @@ static PyObject *
type_dict(PyTypeObject *type, void *context)
{
if (type->tp_dict == NULL) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
return PyDictProxy_New(type->tp_dict);
}
@ -5330,8 +5327,7 @@ wrap_sq_setitem(PyObject *self, PyObject *args, void *wrapped)
res = (*func)(self, i, value);
if (res == -1 && PyErr_Occurred())
return NULL;
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
static PyObject *
@ -5351,8 +5347,7 @@ wrap_sq_delitem(PyObject *self, PyObject *args, void *wrapped)
res = (*func)(self, i, NULL);
if (res == -1 && PyErr_Occurred())
return NULL;
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
/* XXX objobjproc is a misnomer; should be objargpred */
@ -5385,8 +5380,7 @@ wrap_objobjargproc(PyObject *self, PyObject *args, void *wrapped)
res = (*func)(self, key, value);
if (res == -1 && PyErr_Occurred())
return NULL;
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
static PyObject *
@ -5402,8 +5396,7 @@ wrap_delitem(PyObject *self, PyObject *args, void *wrapped)
res = (*func)(self, key, NULL);
if (res == -1 && PyErr_Occurred())
return NULL;
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
/* Helper to check for object.__setattr__ or __delattr__ applied to a type.
@ -5440,8 +5433,7 @@ wrap_setattr(PyObject *self, PyObject *args, void *wrapped)
res = (*func)(self, name, value);
if (res < 0)
return NULL;
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
static PyObject *
@ -5459,8 +5451,7 @@ wrap_delattr(PyObject *self, PyObject *args, void *wrapped)
res = (*func)(self, name, NULL);
if (res < 0)
return NULL;
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
static PyObject *
@ -5571,8 +5562,7 @@ wrap_descr_set(PyObject *self, PyObject *args, void *wrapped)
ret = (*func)(self, obj, value);
if (ret < 0)
return NULL;
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
static PyObject *
@ -5588,8 +5578,7 @@ wrap_descr_delete(PyObject *self, PyObject *args, void *wrapped)
ret = (*func)(self, obj, NULL);
if (ret < 0)
return NULL;
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
static PyObject *
@ -5599,8 +5588,7 @@ wrap_init(PyObject *self, PyObject *args, void *wrapped, PyObject *kwds)
if (func(self, args, kwds) < 0)
return NULL;
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
static PyObject *

View file

@ -8254,9 +8254,7 @@ charmapencode_lookup(Py_UCS4 c, PyObject *mapping)
if (PyErr_ExceptionMatches(PyExc_LookupError)) {
/* No mapping found means: mapping is undefined. */
PyErr_Clear();
x = Py_None;
Py_INCREF(x);
return x;
Py_RETURN_NONE;
} else
return NULL;
}