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 /Modules/_ctypes | |
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 'Modules/_ctypes')
-rw-r--r-- | Modules/_ctypes/_ctypes.c | 30 | ||||
-rw-r--r-- | Modules/_ctypes/_ctypes_test.c | 6 | ||||
-rw-r--r-- | Modules/_ctypes/callproc.c | 12 | ||||
-rw-r--r-- | Modules/_ctypes/cfield.c | 15 |
4 files changed, 21 insertions, 42 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index 4908dde..833749a 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -156,8 +156,7 @@ _DictRemover_call(PyObject *myself, PyObject *args, PyObject *kw) 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 @@ PyCPointerType_set_type(PyTypeObject *self, PyObject *type) 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 @@ c_wchar_p_from_param(PyObject *type, PyObject *value) 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 @@ c_char_p_from_param(PyObject *type, PyObject *value) 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 @@ c_void_p_from_param(PyObject *type, PyObject *value) /* 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 @@ PyCData_setstate(PyObject *myself, PyObject *args) Py_DECREF(mydict); if (res == -1) return NULL; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /* @@ -2825,8 +2819,7 @@ _PyCData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value, 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 @@ PyCFuncPtr_get_errcheck(PyCFuncPtrObject *self) Py_INCREF(self->errcheck); return self->errcheck; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static int @@ -3019,8 +3011,7 @@ PyCFuncPtr_get_restype(PyCFuncPtrObject *self) Py_INCREF(dict->restype); return dict->restype; } else { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } } @@ -3057,8 +3048,7 @@ PyCFuncPtr_get_argtypes(PyCFuncPtrObject *self) 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 index 629ddf6..92b5adb 100644 --- a/Modules/_ctypes/_ctypes_test.c +++ b/Modules/_ctypes/_ctypes_test.c @@ -363,8 +363,7 @@ PyObject *py_func_si(PyObject *self, PyObject *args) 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 @@ EXPORT(void) _py_func_si(char *s, int i) 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 index f408fd3..9b368ca 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -892,8 +892,7 @@ static PyObject *GetResult(PyObject *restype, void *result, PyObject *checker) 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 @@ static PyObject *free_library(PyObject *self, PyObject *args) 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 @@ static PyObject *py_dl_close(PyObject *self, PyObject *args) 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 @@ resize(PyObject *self, PyObject *args) 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 index a43585f..ec30b8c 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -1337,8 +1337,7 @@ z_get(void *ptr, Py_ssize_t size) return PyBytes_FromStringAndSize(*(char **)ptr, strlen(*(char **)ptr)); } else { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } } @@ -1360,8 +1359,7 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size) #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 @@ Z_get(void *ptr, Py_ssize_t size) if (p) { return PyUnicode_FromWideChar(p, wcslen(p)); } else { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } } #endif @@ -1452,8 +1449,7 @@ BSTR_get(void *ptr, Py_ssize_t size) /* 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 @@ static PyObject * 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); } |