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.
This commit is contained in:
parent
1849d894d5
commit
e2197d1312
|
@ -76,6 +76,8 @@ class TestEPoll(unittest.TestCase):
|
||||||
self.assertRaises(ValueError, ep.fileno)
|
self.assertRaises(ValueError, ep.fileno)
|
||||||
if hasattr(select, "EPOLL_CLOEXEC"):
|
if hasattr(select, "EPOLL_CLOEXEC"):
|
||||||
select.epoll(select.EPOLL_CLOEXEC).close()
|
select.epoll(select.EPOLL_CLOEXEC).close()
|
||||||
|
select.epoll(flags=select.EPOLL_CLOEXEC).close()
|
||||||
|
select.epoll(flags=0).close()
|
||||||
self.assertRaises(OSError, select.epoll, flags=12356)
|
self.assertRaises(OSError, select.epoll, flags=12356)
|
||||||
|
|
||||||
def test_badcreate(self):
|
def test_badcreate(self):
|
||||||
|
|
|
@ -1252,7 +1252,7 @@ pyepoll_internal_close(pyEpoll_Object *self)
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
newPyEpoll_Object(PyTypeObject *type, int sizehint, int flags, SOCKET fd)
|
newPyEpoll_Object(PyTypeObject *type, int sizehint, SOCKET fd)
|
||||||
{
|
{
|
||||||
pyEpoll_Object *self;
|
pyEpoll_Object *self;
|
||||||
|
|
||||||
|
@ -1264,12 +1264,10 @@ newPyEpoll_Object(PyTypeObject *type, int sizehint, int flags, SOCKET fd)
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
#ifdef HAVE_EPOLL_CREATE1
|
#ifdef HAVE_EPOLL_CREATE1
|
||||||
flags |= EPOLL_CLOEXEC;
|
self->epfd = epoll_create1(EPOLL_CLOEXEC);
|
||||||
if (flags)
|
#else
|
||||||
self->epfd = epoll_create1(flags);
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
self->epfd = epoll_create(sizehint);
|
self->epfd = epoll_create(sizehint);
|
||||||
|
#endif
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1305,8 +1303,12 @@ pyepoll_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
PyErr_SetString(PyExc_ValueError, "negative sizehint");
|
PyErr_SetString(PyExc_ValueError, "negative sizehint");
|
||||||
return NULL;
|
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))
|
if (!PyArg_ParseTuple(args, "i:fromfd", &fd))
|
||||||
return NULL;
|
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,
|
PyDoc_STRVAR(pyepoll_fromfd_doc,
|
||||||
|
|
Loading…
Reference in New Issue