diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-01-23 07:47:21 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-01-23 07:47:21 (GMT) |
commit | 228b12edcce49649d6befa3c03dbcefd5a22ae76 (patch) | |
tree | 1066be6909fb981fcf30e1a8e224d43567bd9b92 /Python | |
parent | 60e6e962bac6a668d0df539ebf526a0a1c69eacd (diff) | |
download | cpython-228b12edcce49649d6befa3c03dbcefd5a22ae76.zip cpython-228b12edcce49649d6befa3c03dbcefd5a22ae76.tar.gz cpython-228b12edcce49649d6befa3c03dbcefd5a22ae76.tar.bz2 |
Issue #28999: Use Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE wherever
possible. Patch is writen with Coccinelle.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/Python-ast.c | 33 | ||||
-rw-r--r-- | Python/bltinmodule.c | 6 | ||||
-rw-r--r-- | Python/import.c | 9 | ||||
-rw-r--r-- | Python/modsupport.c | 3 | ||||
-rw-r--r-- | Python/sysmodule.c | 30 |
5 files changed, 27 insertions, 54 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c index e0607ba..a049641 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -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); diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 3473cc3..2204344 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -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; } diff --git a/Python/import.c b/Python/import.c index aef1800..38976f6 100644 --- a/Python/import.c +++ b/Python/import.c @@ -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); diff --git a/Python/modsupport.c b/Python/modsupport.c index 01b5dc9..e9e025b 100644 --- a/Python/modsupport.c +++ b/Python/modsupport.c @@ -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) { diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 9c4d9e6..81520ea 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -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 */ |