Skip to content

Commit e2197d1

Browse files
committed
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.
1 parent 1849d89 commit e2197d1

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

Lib/test/test_epoll.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ def test_create(self):
7676
self.assertRaises(ValueError, ep.fileno)
7777
if hasattr(select, "EPOLL_CLOEXEC"):
7878
select.epoll(select.EPOLL_CLOEXEC).close()
79+
select.epoll(flags=select.EPOLL_CLOEXEC).close()
80+
select.epoll(flags=0).close()
7981
self.assertRaises(OSError, select.epoll, flags=12356)
8082

8183
def test_badcreate(self):

Modules/selectmodule.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ pyepoll_internal_close(pyEpoll_Object *self)
12521252
}
12531253

12541254
static PyObject *
1255-
newPyEpoll_Object(PyTypeObject *type, int sizehint, int flags, SOCKET fd)
1255+
newPyEpoll_Object(PyTypeObject *type, int sizehint, SOCKET fd)
12561256
{
12571257
pyEpoll_Object *self;
12581258

@@ -1264,12 +1264,10 @@ newPyEpoll_Object(PyTypeObject *type, int sizehint, int flags, SOCKET fd)
12641264
if (fd == -1) {
12651265
Py_BEGIN_ALLOW_THREADS
12661266
#ifdef HAVE_EPOLL_CREATE1
1267-
flags |= EPOLL_CLOEXEC;
1268-
if (flags)
1269-
self->epfd = epoll_create1(flags);
1270-
else
1271-
#endif
1267+
self->epfd = epoll_create1(EPOLL_CLOEXEC);
1268+
#else
12721269
self->epfd = epoll_create(sizehint);
1270+
#endif
12731271
Py_END_ALLOW_THREADS
12741272
}
12751273
else {
@@ -1305,8 +1303,12 @@ pyepoll_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
13051303
PyErr_SetString(PyExc_ValueError, "negative sizehint");
13061304
return NULL;
13071305
}
1306+
if (flags && flags != EPOLL_CLOEXEC) {
1307+
PyErr_SetString(PyExc_OSError, "invalid flags");
1308+
return NULL;
1309+
}
13081310

1309-
return newPyEpoll_Object(type, sizehint, flags, -1);
1311+
return newPyEpoll_Object(type, sizehint, -1);
13101312
}
13111313

13121314

@@ -1364,7 +1366,7 @@ pyepoll_fromfd(PyObject *cls, PyObject *args)
13641366
if (!PyArg_ParseTuple(args, "i:fromfd", &fd))
13651367
return NULL;
13661368

1367-
return newPyEpoll_Object((PyTypeObject*)cls, FD_SETSIZE - 1, 0, fd);
1369+
return newPyEpoll_Object((PyTypeObject*)cls, FD_SETSIZE - 1, fd);
13681370
}
13691371

13701372
PyDoc_STRVAR(pyepoll_fromfd_doc,

0 commit comments

Comments
 (0)