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

@ -2583,8 +2583,7 @@ ast2obj_mod(void* _o)
mod_ty o = (mod_ty)_o;
PyObject *result = NULL, *value = NULL;
if (!o) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
switch (o->kind) {
@ -2638,8 +2637,7 @@ ast2obj_stmt(void* _o)
stmt_ty o = (stmt_ty)_o;
PyObject *result = NULL, *value = NULL;
if (!o) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
switch (o->kind) {
@ -3063,8 +3061,7 @@ ast2obj_expr(void* _o)
expr_ty o = (expr_ty)_o;
PyObject *result = NULL, *value = NULL;
if (!o) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
switch (o->kind) {
@ -3526,8 +3523,7 @@ ast2obj_slice(void* _o)
slice_ty o = (slice_ty)_o;
PyObject *result = NULL, *value = NULL;
if (!o) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
switch (o->kind) {
@ -3705,8 +3701,7 @@ ast2obj_comprehension(void* _o)
comprehension_ty o = (comprehension_ty)_o;
PyObject *result = NULL, *value = NULL;
if (!o) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
result = PyType_GenericNew(comprehension_type, NULL, NULL);
@ -3744,8 +3739,7 @@ ast2obj_excepthandler(void* _o)
excepthandler_ty o = (excepthandler_ty)_o;
PyObject *result = NULL, *value = NULL;
if (!o) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
switch (o->kind) {
@ -3792,8 +3786,7 @@ ast2obj_arguments(void* _o)
arguments_ty o = (arguments_ty)_o;
PyObject *result = NULL, *value = NULL;
if (!o) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
result = PyType_GenericNew(arguments_type, NULL, NULL);
@ -3841,8 +3834,7 @@ ast2obj_arg(void* _o)
arg_ty o = (arg_ty)_o;
PyObject *result = NULL, *value = NULL;
if (!o) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
result = PyType_GenericNew(arg_type, NULL, NULL);
@ -3880,8 +3872,7 @@ ast2obj_keyword(void* _o)
keyword_ty o = (keyword_ty)_o;
PyObject *result = NULL, *value = NULL;
if (!o) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
result = PyType_GenericNew(keyword_type, NULL, NULL);
@ -3909,8 +3900,7 @@ ast2obj_alias(void* _o)
alias_ty o = (alias_ty)_o;
PyObject *result = NULL, *value = NULL;
if (!o) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
result = PyType_GenericNew(alias_type, NULL, NULL);
@ -3938,8 +3928,7 @@ ast2obj_withitem(void* _o)
withitem_ty o = (withitem_ty)_o;
PyObject *result = NULL, *value = NULL;
if (!o) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
result = PyType_GenericNew(withitem_type, NULL, NULL);

View file

@ -1369,8 +1369,7 @@ builtin_setattr_impl(PyObject *module, PyObject *obj, PyObject *name,
{
if (PyObject_SetAttr(obj, name, value) != 0)
return NULL;
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
@ -1392,8 +1391,7 @@ builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name)
{
if (PyObject_SetAttr(obj, name, (PyObject *)NULL) != 0)
return NULL;
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}

View file

@ -260,8 +260,7 @@ _imp_acquire_lock_impl(PyObject *module)
#ifdef WITH_THREAD
_PyImport_AcquireLock();
#endif
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
/*[clinic input]
@ -283,8 +282,7 @@ _imp_release_lock_impl(PyObject *module)
return NULL;
}
#endif
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
void
@ -1853,8 +1851,7 @@ _imp_init_frozen_impl(PyObject *module, PyObject *name)
if (ret < 0)
return NULL;
if (ret == 0) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
m = PyImport_AddModuleObject(name);
Py_XINCREF(m);

View file

@ -514,8 +514,7 @@ va_build_value(const char *format, va_list va, int flags)
if (n < 0)
return NULL;
if (n == 0) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
va_copy(lva, va);
if (n == 1) {

View file

@ -179,8 +179,7 @@ sys_displayhook(PyObject *self, PyObject *o)
/* After printing, also assign to '_' */
/* Before, set '_' to None to avoid recursion */
if (o == Py_None) {
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
if (_PyObject_SetAttrId(builtins, &PyId__, Py_None) != 0)
return NULL;
@ -211,8 +210,7 @@ sys_displayhook(PyObject *self, PyObject *o)
return NULL;
if (_PyObject_SetAttrId(builtins, &PyId__, o) != 0)
return NULL;
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
PyDoc_STRVAR(displayhook_doc,
@ -228,8 +226,7 @@ sys_excepthook(PyObject* self, PyObject* args)
if (!PyArg_UnpackTuple(args, "excepthook", 3, 3, &exc, &value, &tb))
return NULL;
PyErr_Display(exc, value, tb);
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
PyDoc_STRVAR(excepthook_doc,
@ -461,8 +458,7 @@ sys_settrace(PyObject *self, PyObject *args)
PyEval_SetTrace(NULL, NULL);
else
PyEval_SetTrace(trace_trampoline, args);
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
PyDoc_STRVAR(settrace_doc,
@ -500,8 +496,7 @@ sys_setprofile(PyObject *self, PyObject *args)
PyEval_SetProfile(NULL, NULL);
else
PyEval_SetProfile(profile_trampoline, args);
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
PyDoc_STRVAR(setprofile_doc,
@ -542,8 +537,7 @@ sys_setcheckinterval(PyObject *self, PyObject *args)
return NULL;
if (!PyArg_ParseTuple(args, "i:setcheckinterval", &_check_interval))
return NULL;
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
PyDoc_STRVAR(setcheckinterval_doc,
@ -581,8 +575,7 @@ sys_setswitchinterval(PyObject *self, PyObject *args)
return NULL;
}
_PyEval_SetSwitchInterval((unsigned long) (1e6 * d));
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
PyDoc_STRVAR(setswitchinterval_doc,
@ -644,8 +637,7 @@ sys_setrecursionlimit(PyObject *self, PyObject *args)
}
Py_SetRecursionLimit(new_limit);
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
static PyObject *
@ -1032,8 +1024,7 @@ sys_setdlopenflags(PyObject *self, PyObject *args)
if (!tstate)
return NULL;
tstate->interp->dlopenflags = new_val;
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
PyDoc_STRVAR(setdlopenflags_doc,
@ -1074,8 +1065,7 @@ sys_mdebug(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i:mdebug", &flag))
return NULL;
mallopt(M_DEBUG, flag);
Py_INCREF(Py_None);
return Py_None;
Py_RETURN_NONE;
}
#endif /* USE_MALLOPT */