[Python-checkins] cpython: Issue #28999: Use Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE wherever
serhiy.storchaka
python-checkins at python.org
Mon Jan 23 02:47:48 EST 2017
https://hg.python.org/cpython/rev/df87db35833e
changeset: 106280:df87db35833e
parent: 106278:88085dc1e036
user: Serhiy Storchaka <storchaka at gmail.com>
date: Mon Jan 23 09:47:21 2017 +0200
summary:
Issue #28999: Use Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE wherever
possible. Patch is writen with Coccinelle.
files:
Modules/_blake2/blake2b_impl.c | 3 +-
Modules/_blake2/blake2s_impl.c | 3 +-
Modules/_csv.c | 12 +--
Modules/_ctypes/_ctypes.c | 30 +++-------
Modules/_ctypes/_ctypes_test.c | 6 +-
Modules/_ctypes/callproc.c | 12 +--
Modules/_ctypes/cfield.c | 15 +---
Modules/_curses_panel.c | 25 +++-----
Modules/_cursesmodule.c | 62 +++++++--------------
Modules/_dbmmodule.c | 3 +-
Modules/_gdbmmodule.c | 15 +---
Modules/_io/bufferedio.c | 6 +-
Modules/_lsprof.c | 9 +--
Modules/_randommodule.c | 3 +-
Modules/_scproxy.c | 3 +-
Modules/_sha3/sha3module.c | 3 +-
Modules/_sqlite/connection.c | 9 +--
Modules/_sre.c | 12 +--
Modules/_ssl.c | 6 +-
Modules/_testcapimodule.c | 36 ++++--------
Modules/_testmultiphase.c | 3 +-
Modules/_threadmodule.c | 6 +-
Modules/arraymodule.c | 24 ++-----
Modules/faulthandler.c | 6 +-
Modules/fpectlmodule.c | 6 +-
Modules/fpetestmodule.c | 3 +-
Modules/gcmodule.c | 12 +--
Modules/md5module.c | 3 +-
Modules/mmapmodule.c | 18 ++----
Modules/ossaudiodev.c | 15 +---
Modules/parsermodule.c | 3 +-
Modules/posixmodule.c | 15 +---
Modules/pyexpat.c | 12 +--
Modules/selectmodule.c | 9 +--
Modules/sha1module.c | 3 +-
Modules/sha256module.c | 3 +-
Modules/sha512module.c | 3 +-
Modules/socketmodule.c | 24 ++-----
Modules/syslogmodule.c | 6 +-
Modules/termios.c | 15 +---
Modules/timemodule.c | 6 +-
Modules/zipimport.c | 9 +--
Objects/descrobject.c | 6 +-
Objects/exceptions.c | 6 +-
Objects/fileobject.c | 3 +-
Objects/funcobject.c | 6 +-
Objects/genobject.c | 3 +-
Objects/listobject.c | 6 +-
Objects/tupleobject.c | 6 +-
Objects/typeobject.c | 36 ++++--------
Objects/unicodeobject.c | 4 +-
PC/_msi.c | 36 ++++--------
Python/Python-ast.c | 33 +++-------
Python/bltinmodule.c | 6 +-
Python/import.c | 9 +--
Python/modsupport.c | 3 +-
Python/sysmodule.c | 30 +++-------
57 files changed, 225 insertions(+), 445 deletions(-)
diff --git a/Modules/_blake2/blake2b_impl.c b/Modules/_blake2/blake2b_impl.c
--- a/Modules/_blake2/blake2b_impl.c
+++ b/Modules/_blake2/blake2b_impl.c
@@ -310,8 +310,7 @@
#endif /* !WITH_THREAD */
PyBuffer_Release(&buf);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/*[clinic input]
diff --git a/Modules/_blake2/blake2s_impl.c b/Modules/_blake2/blake2s_impl.c
--- a/Modules/_blake2/blake2s_impl.c
+++ b/Modules/_blake2/blake2s_impl.c
@@ -310,8 +310,7 @@
#endif /* !WITH_THREAD */
PyBuffer_Release(&buf);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/*[clinic input]
diff --git a/Modules/_csv.c b/Modules/_csv.c
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -152,8 +152,7 @@
get_nullchar_as_None(Py_UCS4 c)
{
if (c == '\0') {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
else
return PyUnicode_FromOrdinal(c);
@@ -1294,8 +1293,7 @@
Py_DECREF(row_iter);
if (PyErr_Occurred())
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static struct PyMethodDef Writer_methods[] = {
@@ -1450,8 +1448,7 @@
return NULL;
}
Py_DECREF(dialect);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
@@ -1459,8 +1456,7 @@
{
if (PyDict_DelItem(_csvstate_global->dialects, name_obj) < 0)
return PyErr_Format(_csvstate_global->error_obj, "unknown dialect");
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -156,8 +156,7 @@
Py_CLEAR(self->key);
Py_CLEAR(self->dict);
}
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyTypeObject DictRemover_Type = {
@@ -979,8 +978,7 @@
if (-1 == PyDict_SetItemString((PyObject *)dict, "_type_", type))
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *_byref(PyObject *);
@@ -1496,8 +1494,7 @@
PyObject *as_parameter;
int res;
if (value == Py_None) {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
if (PyUnicode_Check(value)) {
PyCArgObject *parg;
@@ -1561,8 +1558,7 @@
PyObject *as_parameter;
int res;
if (value == Py_None) {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
if (PyBytes_Check(value)) {
PyCArgObject *parg;
@@ -1629,8 +1625,7 @@
/* None */
if (value == Py_None) {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/* Should probably allow buffer interface as well */
/* int, long */
@@ -2602,8 +2597,7 @@
Py_DECREF(mydict);
if (res == -1)
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/*
@@ -2825,8 +2819,7 @@
return result;
} else if (value == Py_None && PyCPointerTypeObject_Check(type)) {
*(void **)ptr = NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
} else {
PyErr_Format(PyExc_TypeError,
"expected %s instance, got %s",
@@ -2980,8 +2973,7 @@
Py_INCREF(self->errcheck);
return self->errcheck;
}
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static int
@@ -3019,8 +3011,7 @@
Py_INCREF(dict->restype);
return dict->restype;
} else {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
}
@@ -3057,8 +3048,7 @@
Py_INCREF(dict->argtypes);
return dict->argtypes;
} else {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
}
diff --git a/Modules/_ctypes/_ctypes_test.c b/Modules/_ctypes/_ctypes_test.c
--- a/Modules/_ctypes/_ctypes_test.c
+++ b/Modules/_ctypes/_ctypes_test.c
@@ -363,8 +363,7 @@
int i;
if (!PyArg_ParseTuple(args, "si", &name, &i))
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
EXPORT(void) _py_func_si(char *s, int i)
@@ -373,8 +372,7 @@
PyObject *py_func(PyObject *self, PyObject *args)
{
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
EXPORT(void) _py_func(void)
diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c
--- a/Modules/_ctypes/callproc.c
+++ b/Modules/_ctypes/callproc.c
@@ -892,8 +892,7 @@
return PyLong_FromLong(*(int *)result);
if (restype == Py_None) {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
dict = PyType_stgdict(restype);
@@ -1263,8 +1262,7 @@
return NULL;
if (!FreeLibrary((HMODULE)hMod))
return PyErr_SetFromWindowsErr(GetLastError());
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static const char copy_com_pointer_doc[] =
@@ -1349,8 +1347,7 @@
ctypes_dlerror());
return NULL;
}
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *py_dl_sym(PyObject *self, PyObject *args)
@@ -1624,8 +1621,7 @@
obj->b_size = size;
}
done:
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c
--- a/Modules/_ctypes/cfield.c
+++ b/Modules/_ctypes/cfield.c
@@ -1337,8 +1337,7 @@
return PyBytes_FromStringAndSize(*(char **)ptr,
strlen(*(char **)ptr));
} else {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
}
@@ -1360,8 +1359,7 @@
#else
*(wchar_t **)ptr = (wchar_t *)PyLong_AsUnsignedLongMask(value);
#endif
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
if (!PyUnicode_Check(value)) {
PyErr_Format(PyExc_TypeError,
@@ -1392,8 +1390,7 @@
if (p) {
return PyUnicode_FromWideChar(p, wcslen(p));
} else {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
}
#endif
@@ -1452,8 +1449,7 @@
/* Hm, it seems NULL pointer and zero length string are the
same in BSTR, see Don Box, p 81
*/
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
}
#endif
@@ -1493,8 +1489,7 @@
P_get(void *ptr, Py_ssize_t size)
{
if (*(void **)ptr == NULL) {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
return PyLong_FromVoidPtr(*(void **)ptr);
}
diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c
--- a/Modules/_curses_panel.c
+++ b/Modules/_curses_panel.c
@@ -59,8 +59,7 @@
PyCursesCheckERR(int code, const char *fname)
{
if (code != ERR) {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
} else {
if (fname == NULL) {
PyErr_SetString(_curses_panelstate_global->PyCursesError, catchall_ERR);
@@ -177,8 +176,8 @@
#define Panel_NoArgTrueFalseFunction(X) \
static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self) \
{ \
- if (X (self->pan) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
- else { Py_INCREF(Py_True); return Py_True; } }
+ if (X (self->pan) == FALSE) { Py_RETURN_FALSE; } \
+ else { Py_RETURN_TRUE; } }
#define Panel_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self, PyObject *args) \
@@ -245,8 +244,7 @@
if (pan == NULL) { /* valid output, it means the calling panel
is on top of the stack */
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
po = find_po(pan);
if (po == NULL) {
@@ -270,8 +268,7 @@
if (pan == NULL) { /* valid output, it means the calling panel
is on the bottom of the stack */
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
po = find_po(pan);
if (po == NULL) {
@@ -319,8 +316,7 @@
}
Py_INCREF(temp);
Py_SETREF(po->wo, temp);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
@@ -406,8 +402,7 @@
if (pan == NULL) { /* valid output, it means
there's no panel at all */
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
po = find_po(pan);
if (po == NULL) {
@@ -452,8 +447,7 @@
if (pan == NULL) { /* valid output, it means
there's no panel at all */
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
po = find_po(pan);
if (po == NULL) {
@@ -469,8 +463,7 @@
{
PyCursesInitialised;
update_panels();
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -188,8 +188,7 @@
PyCursesCheckERR(int code, const char *fname)
{
if (code != ERR) {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
} else {
if (fname == NULL) {
PyErr_SetString(PyCursesError, catchall_ERR);
@@ -414,14 +413,14 @@
static PyObject * PyCursesWindow_ ## X \
(PyCursesWindowObject *self) \
{ \
- if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
- else { Py_INCREF(Py_True); return Py_True; } }
+ if (X (self->win) == FALSE) { Py_RETURN_FALSE; } \
+ else { Py_RETURN_TRUE; } }
#define Window_NoArgNoReturnVoidFunction(X) \
static PyObject * PyCursesWindow_ ## X \
(PyCursesWindowObject *self) \
{ \
- X(self->win); Py_INCREF(Py_None); return Py_None; }
+ X(self->win); Py_RETURN_NONE; }
#define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \
static PyObject * PyCursesWindow_ ## X \
@@ -436,7 +435,7 @@
{ \
TYPE arg1; \
if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL; \
- X(self->win,arg1); Py_INCREF(Py_None); return Py_None; }
+ X(self->win,arg1); Py_RETURN_NONE; }
#define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \
static PyObject * PyCursesWindow_ ## X \
@@ -900,8 +899,7 @@
wborder(self->win,
ch[0], ch[1], ch[2], ch[3],
ch[4], ch[5], ch[6], ch[7]);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
@@ -915,8 +913,7 @@
return NULL;
}
box(self->win,ch1,ch2);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
#if defined(HAVE_NCURSES_H) || defined(MVWDELCH_IS_EXPRESSION)
@@ -1593,11 +1590,9 @@
return NULL;
} else
if (erg == FALSE) {
- Py_INCREF(Py_False);
- return Py_False;
+ Py_RETURN_FALSE;
} else {
- Py_INCREF(Py_True);
- return Py_True;
+ Py_RETURN_TRUE;
}
}
@@ -2158,8 +2153,7 @@
/* not checking for PyCursesInitialised here since filter() must
be called before initscr() */
filter();
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
@@ -2365,11 +2359,9 @@
if (!PyArg_ParseTuple(args,"i",&ch)) return NULL;
if (has_key(ch) == FALSE) {
- Py_INCREF(Py_False);
- return Py_False;
+ Py_RETURN_FALSE;
}
- Py_INCREF(Py_True);
- return Py_True;
+ Py_RETURN_TRUE;
}
#endif /* STRICT_SYSV_CURSES */
@@ -2566,8 +2558,7 @@
initialised_setupterm = TRUE;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
@@ -2603,11 +2594,9 @@
return NULL;
result = is_term_resized(lines, columns);
if (result == TRUE) {
- Py_INCREF(Py_True);
- return Py_True;
+ Py_RETURN_TRUE;
} else {
- Py_INCREF(Py_False);
- return Py_False;
+ Py_RETURN_FALSE;
}
}
#endif /* HAVE_CURSES_IS_TERM_RESIZED */
@@ -2819,14 +2808,12 @@
switch(PyTuple_Size(args)) {
case 0:
qiflush();
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
case 1:
if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL;
if (flag) qiflush();
else noqiflush();
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
default:
PyErr_SetString(PyExc_TypeError, "qiflush requires 0 or 1 arguments");
return NULL;
@@ -2954,8 +2941,7 @@
setsyx(y,x);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
@@ -2979,8 +2965,7 @@
return NULL;
PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp);
Py_DECREF(cp);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
} else {
PyErr_SetString(PyCursesError, "start_color() returned ERR");
return NULL;
@@ -3025,8 +3010,7 @@
capname = tigetstr( capname );
if (capname == 0 || capname == (char*) -1) {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
return PyBytes_FromString( capname );
}
@@ -3180,8 +3164,7 @@
return NULL;
}
use_env(flag);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
#ifndef STRICT_SYSV_CURSES
@@ -3195,8 +3178,7 @@
code = use_default_colors();
if (code != ERR) {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
} else {
PyErr_SetString(PyCursesError, "use_default_colors() returned ERR");
return NULL;
diff --git a/Modules/_dbmmodule.c b/Modules/_dbmmodule.c
--- a/Modules/_dbmmodule.c
+++ b/Modules/_dbmmodule.c
@@ -187,8 +187,7 @@
if (self->di_dbm)
dbm_close(self->di_dbm);
self->di_dbm = NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/*[clinic input]
diff --git a/Modules/_gdbmmodule.c b/Modules/_gdbmmodule.c
--- a/Modules/_gdbmmodule.c
+++ b/Modules/_gdbmmodule.c
@@ -255,8 +255,7 @@
if (self->di_dbm)
gdbm_close(self->di_dbm);
self->di_dbm = NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/* XXX Should return a set or a set view */
@@ -375,8 +374,7 @@
return v;
}
else {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
}
@@ -415,8 +413,7 @@
return v;
}
else {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
}
@@ -445,8 +442,7 @@
PyErr_SetString(DbmError, gdbm_strerror(gdbm_errno));
return NULL;
}
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/*[clinic input]
@@ -464,8 +460,7 @@
{
check_dbmobject_open(self);
gdbm_sync(self->di_dbm);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -1689,8 +1689,7 @@
return res;
}
Py_DECREF(res);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
remaining -= r;
written += r;
@@ -1714,8 +1713,7 @@
return res;
}
Py_DECREF(res);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
if (remaining > r) {
memcpy(out + written, self->buffer + self->pos, r);
diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c
--- a/Modules/_lsprof.c
+++ b/Modules/_lsprof.c
@@ -692,8 +692,7 @@
return NULL;
PyEval_SetProfile(profiler_callback, (PyObject*)self);
self->flags |= POF_ENABLED;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static void
@@ -726,8 +725,7 @@
flush_unmatched(self);
if (pending_exception(self))
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(clear_doc, "\
@@ -740,8 +738,7 @@
profiler_clear(ProfilerObject *pObj, PyObject* noarg)
{
clearEntries(pObj);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static void
diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c
--- a/Modules/_randommodule.c
+++ b/Modules/_randommodule.c
@@ -376,8 +376,7 @@
}
self->index = (int)index;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
diff --git a/Modules/_scproxy.c b/Modules/_scproxy.c
--- a/Modules/_scproxy.c
+++ b/Modules/_scproxy.c
@@ -64,8 +64,7 @@
proxyDict = SCDynamicStoreCopyProxies(NULL);
if (!proxyDict) {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
result = PyDict_New();
diff --git a/Modules/_sha3/sha3module.c b/Modules/_sha3/sha3module.c
--- a/Modules/_sha3/sha3module.c
+++ b/Modules/_sha3/sha3module.c
@@ -403,8 +403,7 @@
}
PyBuffer_Release(&buf);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -400,8 +400,7 @@
if (PyErr_Occurred()) {
return NULL;
} else {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
}
@@ -443,8 +442,7 @@
if (PyErr_Occurred()) {
return NULL;
} else {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
}
@@ -487,8 +485,7 @@
if (PyErr_Occurred()) {
return NULL;
} else {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
}
diff --git a/Modules/_sre.c b/Modules/_sre.c
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -481,8 +481,7 @@
/* want empty string */
i = j = 0;
else {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
} else {
i = STATE_OFFSET(state, state->mark[index]);
@@ -2368,8 +2367,7 @@
{
if (self->lastindex >= 0)
return PyLong_FromSsize_t(self->lastindex);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
@@ -2383,8 +2381,7 @@
return result;
PyErr_Clear();
}
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
@@ -2466,8 +2463,7 @@
} else if (status == 0) {
/* no match */
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -755,8 +755,7 @@
PySSL_END_ALLOW_THREADS
self->handshake_done = 1;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
error:
Py_XDECREF(sock);
@@ -4500,8 +4499,7 @@
buf += written;
len -= written;
} while (len);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -64,8 +64,7 @@
#undef CHECK_SIZEOF
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject*
@@ -169,8 +168,7 @@
Py_DECREF(list);
#undef NLIST
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static int
@@ -234,8 +232,7 @@
}
}
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject*
@@ -614,8 +611,7 @@
return raiseTestError("test_long_and_overflow",
"overflow was not cleared");
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/* Test the PyLong_AsLongLongAndOverflow API. General conversion to
@@ -779,8 +775,7 @@
return raiseTestError("test_long_long_and_overflow",
"overflow was not cleared");
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/* Test the PyLong_As{Size,Ssize}_t API. At present this just tests that
@@ -887,8 +882,7 @@
"L code returned wrong value for int 42");
Py_DECREF(tuple);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
@@ -1224,8 +1218,7 @@
"k code returned wrong value for long -0xFFF..000042");
Py_DECREF(tuple);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
@@ -1672,8 +1665,7 @@
"u# code returned wrong values for u'test'");
Py_DECREF(tuple);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/* Test Z and Z# codes for PyArg_ParseTuple */
@@ -2118,8 +2110,7 @@
return raiseTestError("test_long_numbits",
"wrong result for _PyLong_Sign");
}
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/* Example passing NULLs to PyObject_Str(NULL). */
@@ -2336,11 +2327,9 @@
if (r<0) {
Py_DECREF(callable); /* unsuccessful add, destroy the extra reference */
- Py_INCREF(Py_False);
- return Py_False;
+ Py_RETURN_FALSE;
}
- Py_INCREF(Py_True);
- return Py_True;
+ Py_RETURN_TRUE;
}
#endif
@@ -2726,8 +2715,7 @@
Py_DECREF(op1);
print_delta(7, &start, &stop);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
#endif
diff --git a/Modules/_testmultiphase.c b/Modules/_testmultiphase.c
--- a/Modules/_testmultiphase.c
+++ b/Modules/_testmultiphase.c
@@ -36,8 +36,7 @@
Py_INCREF(o);
return o;
}
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -180,8 +180,7 @@
PyThread_release_lock(self->lock_lock);
self->locked = 0;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(release_doc,
@@ -1111,8 +1110,7 @@
thread_PyThread_interrupt_main(PyObject * self)
{
PyErr_SetInterrupt();
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(interrupt_doc,
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1007,8 +1007,7 @@
{
if (ins1(self, where, v) != 0)
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/*[clinic input]
@@ -1122,8 +1121,7 @@
if (cmp > 0) {
if (array_del_slice(self, i, i+1) != 0)
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
else if (cmp < 0)
return NULL;
@@ -1185,8 +1183,7 @@
{
if (array_do_extend(self, bb) == -1)
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/*[clinic input]
@@ -1315,8 +1312,7 @@
"don't know how to byteswap this array type");
return NULL;
}
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/*[clinic input]
@@ -1349,8 +1345,7 @@
}
}
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/*[clinic input]
@@ -1453,8 +1448,7 @@
}
done:
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/*[clinic input]
@@ -1491,8 +1485,7 @@
}
}
}
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/*[clinic input]
@@ -1557,8 +1550,7 @@
buffer->buf, n * itemsize);
}
PyBuffer_Release(buffer);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/*[clinic input]
diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c
--- a/Modules/faulthandler.c
+++ b/Modules/faulthandler.c
@@ -521,12 +521,10 @@
faulthandler_disable_py(PyObject *self)
{
if (!fatal_error.enabled) {
- Py_INCREF(Py_False);
- return Py_False;
+ Py_RETURN_FALSE;
}
faulthandler_disable();
- Py_INCREF(Py_True);
- return Py_True;
+ Py_RETURN_TRUE;
}
static PyObject*
diff --git a/Modules/fpectlmodule.c b/Modules/fpectlmodule.c
--- a/Modules/fpectlmodule.c
+++ b/Modules/fpectlmodule.c
@@ -102,8 +102,7 @@
/* Do any architecture-specific one-time only initialization here. */
fpe_reset(sigfpe_handler);
- Py_INCREF (Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static void fpe_reset(Sigfunc *handler)
@@ -233,8 +232,7 @@
#else
fputs("Operation not implemented\n", stderr);
#endif
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static void sigfpe_handler(int signo)
diff --git a/Modules/fpetestmodule.c b/Modules/fpetestmodule.c
--- a/Modules/fpetestmodule.c
+++ b/Modules/fpetestmodule.c
@@ -95,8 +95,7 @@
r = nest2(2, 2.0);
printerr(r);
- Py_INCREF (Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static void printerr(double r)
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -1164,8 +1164,7 @@
gc_enable(PyObject *self, PyObject *noargs)
{
enabled = 1;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(gc_disable__doc__,
@@ -1177,8 +1176,7 @@
gc_disable(PyObject *self, PyObject *noargs)
{
enabled = 0;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(gc_isenabled__doc__,
@@ -1246,8 +1244,7 @@
if (!PyArg_ParseTuple(args, "i:set_debug", &debug))
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(gc_get_debug__doc__,
@@ -1281,8 +1278,7 @@
generations[i].threshold = generations[2].threshold;
}
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(gc_get_thresh__doc__,
diff --git a/Modules/md5module.c b/Modules/md5module.c
--- a/Modules/md5module.c
+++ b/Modules/md5module.c
@@ -416,8 +416,7 @@
md5_process(&self->hash_state, buf.buf, buf.len);
PyBuffer_Release(&buf);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyMethodDef MD5_methods[] = {
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -181,8 +181,7 @@
}
#endif
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
#ifdef MS_WINDOWS
@@ -415,8 +414,7 @@
if (self->pos < self->size) {
self->data[self->pos++] = value;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
else {
PyErr_SetString(PyExc_ValueError, "write byte out of range");
@@ -524,8 +522,7 @@
new_size);
if (self->data != NULL) {
self->size = new_size;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
} else {
dwErrCode = GetLastError();
CloseHandle(self->map_handle);
@@ -567,8 +564,7 @@
}
self->data = newmap;
self->size = new_size;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
#endif /* HAVE_MREMAP */
#endif /* UNIX */
}
@@ -644,8 +640,7 @@
if (where > self->size || where < 0)
goto onoutofrange;
self->pos = where;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
onoutofrange:
@@ -670,8 +665,7 @@
memmove(&self->data[dest], &self->data[src], cnt);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
bounds:
PyErr_SetString(PyExc_ValueError,
diff --git a/Modules/ossaudiodev.c b/Modules/ossaudiodev.c
--- a/Modules/ossaudiodev.c
+++ b/Modules/ossaudiodev.c
@@ -307,8 +307,7 @@
if (rv == -1)
return PyErr_SetFromErrno(PyExc_IOError);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
@@ -326,8 +325,7 @@
mode once we're in non-blocking mode! */
if (ioctl(self->fd, SNDCTL_DSP_NONBLOCK, NULL) == -1)
return PyErr_SetFromErrno(PyExc_IOError);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
@@ -514,8 +512,7 @@
cp += rv;
}
PyBuffer_Release(&data);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
@@ -527,8 +524,7 @@
Py_END_ALLOW_THREADS
self->fd = -1;
}
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
@@ -747,8 +743,7 @@
close(self->fd);
self->fd = -1;
}
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -91,8 +91,7 @@
PyObject *result = NULL, *w;
if (n == NULL) {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
if (ISNONTERMINAL(TYPE(n))) {
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1871,8 +1871,7 @@
/* Return old value */
return PyBool_FromLong(_stat_float_times);
_stat_float_times = newval;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *billion = NULL;
@@ -6194,8 +6193,7 @@
if (res == -1)
return PyErr_SetFromErrno(PyExc_OSError);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
#endif /* HAVE_INITGROUPS */
@@ -6258,8 +6256,7 @@
if (setpgrp() < 0)
#endif /* SETPGRP_HAVE_ARG */
return posix_error();
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
#endif /* HAVE_SETPGRP */
@@ -6585,8 +6582,7 @@
if (setreuid(ruid, euid) < 0) {
return posix_error();
} else {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
}
#endif /* HAVE_SETREUID */
@@ -6681,8 +6677,7 @@
if (setgroups(len, grouplist) < 0)
return posix_error();
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
#endif /* HAVE_SETGROUPS */
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -161,8 +161,7 @@
and hence in UTF-8. */
/* UTF-8 from Expat, Unicode desired */
if (str == NULL) {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
return PyUnicode_DecodeUTF8(str, strlen(str), "strict");
}
@@ -174,8 +173,7 @@
and hence in UTF-8. */
/* UTF-8 from Expat, Unicode desired */
if (str == NULL) {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
return PyUnicode_DecodeUTF8((const char *)str, len, "strict");
}
@@ -1030,8 +1028,7 @@
if (rc != XML_ERROR_NONE) {
return set_error(self, rc);
}
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
#endif
@@ -1322,8 +1319,7 @@
return get_pybool((long) self->specified_attributes);
if (_PyUnicode_EqualToASCIIString(nameobj, "intern")) {
if (self->intern == NULL) {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
else {
Py_INCREF(self->intern);
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -431,8 +431,7 @@
self->ufd_uptodate = 0;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(poll_modify_doc,
@@ -479,8 +478,7 @@
self->ufd_uptodate = 0;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
@@ -513,8 +511,7 @@
Py_DECREF(key);
self->ufd_uptodate = 0;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(poll_poll_doc,
diff --git a/Modules/sha1module.c b/Modules/sha1module.c
--- a/Modules/sha1module.c
+++ b/Modules/sha1module.c
@@ -393,8 +393,7 @@
sha1_process(&self->hash_state, buf.buf, buf.len);
PyBuffer_Release(&buf);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyMethodDef SHA1_methods[] = {
diff --git a/Modules/sha256module.c b/Modules/sha256module.c
--- a/Modules/sha256module.c
+++ b/Modules/sha256module.c
@@ -483,8 +483,7 @@
sha_update(self, buf.buf, buf.len);
PyBuffer_Release(&buf);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyMethodDef SHA_methods[] = {
diff --git a/Modules/sha512module.c b/Modules/sha512module.c
--- a/Modules/sha512module.c
+++ b/Modules/sha512module.c
@@ -548,8 +548,7 @@
sha512_update(self, buf.buf, buf.len);
PyBuffer_Release(&buf);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/*[clinic input]
dump buffer
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -1218,8 +1218,7 @@
{
if (addrlen == 0) {
/* No address -- may be recvfrom() from known socket */
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
switch (addr->sa_family) {
@@ -2540,8 +2539,7 @@
sock_gettimeout(PySocketSockObject *s)
{
if (s->sock_timeout < 0) {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
else {
double seconds = _PyTime_AsSecondsDouble(s->sock_timeout);
@@ -2701,8 +2699,7 @@
Py_END_ALLOW_THREADS
if (res < 0)
return s->errorhandler();
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(bind_doc,
@@ -2738,8 +2735,7 @@
return s->errorhandler();
}
}
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(close_doc,
@@ -2996,8 +2992,7 @@
Py_END_ALLOW_THREADS
if (res < 0)
return s->errorhandler();
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(listen_doc,
@@ -4363,8 +4358,7 @@
Py_END_ALLOW_THREADS
if (res < 0)
return s->errorhandler();
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(shutdown_doc,
@@ -6196,8 +6190,7 @@
socket_getdefaulttimeout(PyObject *self)
{
if (defaulttimeout < 0) {
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
else {
double seconds = _PyTime_AsSecondsDouble(defaulttimeout);
@@ -6222,8 +6215,7 @@
defaulttimeout = timeout;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(setdefaulttimeout_doc,
diff --git a/Modules/syslogmodule.c b/Modules/syslogmodule.c
--- a/Modules/syslogmodule.c
+++ b/Modules/syslogmodule.c
@@ -147,8 +147,7 @@
openlog(ident, logopt, facility);
S_log_open = 1;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
@@ -200,8 +199,7 @@
Py_CLEAR(S_ident_o);
S_log_open = 0;
}
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
diff --git a/Modules/termios.c b/Modules/termios.c
--- a/Modules/termios.c
+++ b/Modules/termios.c
@@ -194,8 +194,7 @@
if (tcsetattr(fd, when, &mode) == -1)
return PyErr_SetFromErrno(TermiosError);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(termios_tcsendbreak__doc__,
@@ -216,8 +215,7 @@
if (tcsendbreak(fd, duration) == -1)
return PyErr_SetFromErrno(TermiosError);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(termios_tcdrain__doc__,
@@ -236,8 +234,7 @@
if (tcdrain(fd) == -1)
return PyErr_SetFromErrno(TermiosError);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(termios_tcflush__doc__,
@@ -259,8 +256,7 @@
if (tcflush(fd, queue) == -1)
return PyErr_SetFromErrno(TermiosError);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(termios_tcflow__doc__,
@@ -282,8 +278,7 @@
if (tcflow(fd, action) == -1)
return PyErr_SetFromErrno(TermiosError);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyMethodDef termios_methods[] =
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -234,8 +234,7 @@
}
if (pysleep(secs) != 0)
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(sleep_doc,
@@ -879,8 +878,7 @@
if (PyErr_Occurred())
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(tzset_doc,
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -677,8 +677,7 @@
}
/* we have the module, but no source */
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(doc_find_module,
@@ -1284,8 +1283,7 @@
PySys_FormatStderr("# %R has bad magic\n",
pathname);
}
- Py_INCREF(Py_None);
- return Py_None; /* signal caller to try alternative */
+ Py_RETURN_NONE; /* signal caller to try alternative */
}
if (mtime != 0 && !eq_mtime(get_uint32(buf + 4), mtime)) {
@@ -1293,8 +1291,7 @@
PySys_FormatStderr("# %R has bad mtime\n",
pathname);
}
- Py_INCREF(Py_None);
- return Py_None; /* signal caller to try alternative */
+ Py_RETURN_NONE; /* signal caller to try alternative */
}
/* XXX the pyc's size field is ignored; timestamp collisions are probably
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -419,8 +419,7 @@
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 @@
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
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -184,8 +184,7 @@
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 @@
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
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -456,8 +456,7 @@
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
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -322,8 +322,7 @@
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 @@
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
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -402,8 +402,7 @@
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
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -2284,12 +2284,10 @@
/* 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
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -631,12 +631,10 @@
/* 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
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -140,8 +140,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -8254,9 +8254,7 @@
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;
}
diff --git a/PC/_msi.c b/PC/_msi.c
--- a/PC/_msi.c
+++ b/PC/_msi.c
@@ -262,8 +262,7 @@
if (!FCIDestroy(hfci))
goto err;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
err:
if(erf.fError)
PyErr_Format(PyExc_ValueError, "FCI error %d", erf.erfOper); /* XXX better error type */
@@ -291,8 +290,7 @@
{
MsiCloseHandle(msidb->h);
msidb->h = 0;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject*
@@ -401,8 +399,7 @@
if (status != ERROR_SUCCESS)
return msierror(status);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject*
@@ -418,8 +415,7 @@
if ((status = MsiRecordSetStringW(record->h, field, data)) != ERROR_SUCCESS)
return msierror(status);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject*
@@ -435,8 +431,7 @@
if ((status = MsiRecordSetStreamW(record->h, field, data)) != ERROR_SUCCESS)
return msierror(status);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject*
@@ -452,8 +447,7 @@
if ((status = MsiRecordSetInteger(record->h, field, data)) != ERROR_SUCCESS)
return msierror(status);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
@@ -617,8 +611,7 @@
if (status != ERROR_SUCCESS)
return msierror(status);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
@@ -630,8 +623,7 @@
status = MsiSummaryInfoPersist(si->h);
if (status != ERROR_SUCCESS)
return msierror(status);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyMethodDef summary_methods[] = {
@@ -714,8 +706,7 @@
if (status != ERROR_SUCCESS)
return msierror(status);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject*
@@ -764,8 +755,7 @@
if ((status = MsiViewModify(view->h, kind, ((msiobj*)data)->h)) != ERROR_SUCCESS)
return msierror(status);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject*
@@ -776,8 +766,7 @@
if ((status = MsiViewClose(view->h)) != ERROR_SUCCESS)
return msierror(status);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyMethodDef view_methods[] = {
@@ -872,8 +861,7 @@
if ((status = MsiDatabaseCommit(msidb->h)) != ERROR_SUCCESS)
return msierror(status);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject*
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -2583,8 +2583,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -1369,8 +1369,7 @@
{
if (PyObject_SetAttr(obj, name, value) != 0)
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
@@ -1392,8 +1391,7 @@
{
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
--- a/Python/import.c
+++ b/Python/import.c
@@ -260,8 +260,7 @@
#ifdef WITH_THREAD
_PyImport_AcquireLock();
#endif
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
/*[clinic input]
@@ -283,8 +282,7 @@
return NULL;
}
#endif
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
void
@@ -1853,8 +1851,7 @@
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
--- a/Python/modsupport.c
+++ b/Python/modsupport.c
@@ -514,8 +514,7 @@
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
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -179,8 +179,7 @@
/* 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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
}
Py_SetRecursionLimit(new_limit);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
static PyObject *
@@ -1032,8 +1024,7 @@
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 @@
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 */
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list