From f0a5059bdc748166fd871e272711ca6d309b4226 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Mon, 26 Sep 2016 23:30:41 +0300 Subject: Issue #20100: Simplify newPyEpoll_Object() EPOLL_CLOEXEC is the only value that can be passed to epoll_create1() and we are passing EPOLL_CLOEXEC unconditionally since Python 3.4. --- Modules/selectmodule.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'Modules/selectmodule.c') diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index 47da49399f..79cf1990d0 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -1252,7 +1252,7 @@ pyepoll_internal_close(pyEpoll_Object *self) } static PyObject * -newPyEpoll_Object(PyTypeObject *type, int sizehint, int flags, SOCKET fd) +newPyEpoll_Object(PyTypeObject *type, int sizehint, SOCKET fd) { pyEpoll_Object *self; @@ -1264,12 +1264,10 @@ newPyEpoll_Object(PyTypeObject *type, int sizehint, int flags, SOCKET fd) if (fd == -1) { Py_BEGIN_ALLOW_THREADS #ifdef HAVE_EPOLL_CREATE1 - flags |= EPOLL_CLOEXEC; - if (flags) - self->epfd = epoll_create1(flags); - else -#endif + self->epfd = epoll_create1(EPOLL_CLOEXEC); +#else self->epfd = epoll_create(sizehint); +#endif Py_END_ALLOW_THREADS } else { @@ -1305,8 +1303,12 @@ pyepoll_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PyErr_SetString(PyExc_ValueError, "negative sizehint"); return NULL; } + if (flags && flags != EPOLL_CLOEXEC) { + PyErr_SetString(PyExc_OSError, "invalid flags"); + return NULL; + } - return newPyEpoll_Object(type, sizehint, flags, -1); + return newPyEpoll_Object(type, sizehint, -1); } @@ -1364,7 +1366,7 @@ pyepoll_fromfd(PyObject *cls, PyObject *args) if (!PyArg_ParseTuple(args, "i:fromfd", &fd)) return NULL; - return newPyEpoll_Object((PyTypeObject*)cls, FD_SETSIZE - 1, 0, fd); + return newPyEpoll_Object((PyTypeObject*)cls, FD_SETSIZE - 1, fd); } PyDoc_STRVAR(pyepoll_fromfd_doc, -- cgit v1.2.1 From f22b56b777f7134b5c4e6c9caa9249e92c4f4fd9 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 16 Dec 2016 16:18:57 +0200 Subject: Issue #28959: Added private macro PyDict_GET_SIZE for retrieving the size of dict. --- Modules/selectmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Modules/selectmodule.c') diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index 79cf1990d0..0206651669 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -353,7 +353,7 @@ update_ufd_array(pollObject *self) PyObject *key, *value; struct pollfd *old_ufds = self->ufds; - self->ufd_len = PyDict_Size(self->dict); + self->ufd_len = PyDict_GET_SIZE(self->dict); PyMem_RESIZE(self->ufds, struct pollfd, self->ufd_len); if (self->ufds == NULL) { self->ufds = old_ufds; -- cgit v1.2.1 From bfeec6d871e3db2e0ddfdef01387913bc19cadd4 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 23 Jan 2017 09:47:21 +0200 Subject: Issue #28999: Use Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE wherever possible. Patch is writen with Coccinelle. --- Modules/selectmodule.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'Modules/selectmodule.c') diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index 0206651669..8bdf3359d4 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -431,8 +431,7 @@ poll_register(pollObject *self, PyObject *args) self->ufd_uptodate = 0; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } PyDoc_STRVAR(poll_modify_doc, @@ -479,8 +478,7 @@ poll_modify(pollObject *self, PyObject *args) self->ufd_uptodate = 0; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } @@ -513,8 +511,7 @@ poll_unregister(pollObject *self, PyObject *o) Py_DECREF(key); self->ufd_uptodate = 0; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } PyDoc_STRVAR(poll_poll_doc, -- cgit v1.2.1