summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-01-23 07:47:21 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-01-23 07:47:21 (GMT)
commit228b12edcce49649d6befa3c03dbcefd5a22ae76 (patch)
tree1066be6909fb981fcf30e1a8e224d43567bd9b92 /Objects
parent60e6e962bac6a668d0df539ebf526a0a1c69eacd (diff)
downloadcpython-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 'Objects')
-rw-r--r--Objects/descrobject.c6
-rw-r--r--Objects/exceptions.c6
-rw-r--r--Objects/fileobject.c3
-rw-r--r--Objects/funcobject.c6
-rw-r--r--Objects/genobject.c3
-rw-r--r--Objects/listobject.c6
-rw-r--r--Objects/tupleobject.c6
-rw-r--r--Objects/typeobject.c36
-rw-r--r--Objects/unicodeobject.c4
9 files changed, 25 insertions, 51 deletions
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index a254a2a..3fb34a3 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -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);
}
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 57a786c..35a8b66 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -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;
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index fcdb5fd..3c3d46d 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -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 *
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index a3af4b3..8ac88b1 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -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;
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 59f53ce..24a1da6 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -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;
}
diff --git a/Objects/listobject.c b/Objects/listobject.c
index b21f637..8994174 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -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 */
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index c0ff499..5bcadeb 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -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 */
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 0fdff31..bf6d3f1 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -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 *
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index b711f0c..0b79c5b 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -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;
}