]> git.proxmox.com Git - mirror_edk2.git/blobdiff - AppPkg/Applications/Python/Python-2.7.10/PyMod-2.7.10/Modules/selectmodule.c
edk2: Remove AppPkg, StdLib, StdLibPrivateInternalFiles
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.10 / PyMod-2.7.10 / Modules / selectmodule.c
diff --git a/AppPkg/Applications/Python/Python-2.7.10/PyMod-2.7.10/Modules/selectmodule.c b/AppPkg/Applications/Python/Python-2.7.10/PyMod-2.7.10/Modules/selectmodule.c
deleted file mode 100644 (file)
index a62774a..0000000
+++ /dev/null
@@ -1,1967 +0,0 @@
-/*  @file\r
-  select - Module containing unix select(2) call.\r
-  Under Unix, the file descriptors are small integers.\r
-  Under Win32, select only exists for sockets, and sockets may\r
-  have any value except INVALID_SOCKET.\r
-  Under BeOS, we suffer the same dichotomy as Win32; sockets can be anything\r
-  >= 0.\r
-\r
-  Copyright (c) 2015, Daryl McDaniel. All rights reserved.<BR>\r
-  Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials are licensed and made available under\r
-  the terms and conditions of the BSD License that accompanies this distribution.\r
-  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-*/\r
-\r
-#include "Python.h"\r
-#include <structmember.h>\r
-\r
-#ifdef __APPLE__\r
-    /* Perform runtime testing for a broken poll on OSX to make it easier\r
-     * to use the same binary on multiple releases of the OS.\r
-     */\r
-#undef HAVE_BROKEN_POLL\r
-#endif\r
-\r
-/* Windows #defines FD_SETSIZE to 64 if FD_SETSIZE isn't already defined.\r
-   64 is too small (too many people have bumped into that limit).\r
-   Here we boost it.\r
-   Users who want even more than the boosted limit should #define\r
-   FD_SETSIZE higher before this; e.g., via compiler /D switch.\r
-*/\r
-#if defined(MS_WINDOWS) && !defined(FD_SETSIZE)\r
-#define FD_SETSIZE 512\r
-#endif\r
-\r
-#if defined(HAVE_POLL_H)\r
-#include <poll.h>\r
-#elif defined(HAVE_SYS_POLL_H)\r
-#include <sys/poll.h>\r
-#endif\r
-\r
-#ifdef __sgi\r
-/* This is missing from unistd.h */\r
-extern void bzero(void *, int);\r
-#endif\r
-\r
-#ifdef HAVE_SYS_TYPES_H\r
-#include <sys/types.h>\r
-#endif\r
-\r
-#if defined(PYOS_OS2) && !defined(PYCC_GCC)\r
-#include <sys/time.h>\r
-#include <utils.h>\r
-#endif\r
-\r
-#ifdef MS_WINDOWS\r
-#  include <winsock2.h>\r
-#else\r
-#  define SOCKET int\r
-#  ifdef __BEOS__\r
-#    include <net/socket.h>\r
-#  elif defined(__VMS)\r
-#    include <socket.h>\r
-#  endif\r
-#endif\r
-\r
-static PyObject *SelectError;\r
-\r
-/* list of Python objects and their file descriptor */\r
-typedef struct {\r
-    PyObject *obj;                           /* owned reference */\r
-    SOCKET fd;\r
-    int sentinel;                            /* -1 == sentinel */\r
-} pylist;\r
-\r
-static void\r
-reap_obj(pylist fd2obj[FD_SETSIZE + 1])\r
-{\r
-    int i;\r
-    for (i = 0; i < FD_SETSIZE + 1 && fd2obj[i].sentinel >= 0; i++) {\r
-        Py_CLEAR(fd2obj[i].obj);\r
-    }\r
-    fd2obj[0].sentinel = -1;\r
-}\r
-\r
-\r
-/* returns -1 and sets the Python exception if an error occurred, otherwise\r
-   returns a number >= 0\r
-*/\r
-static int\r
-seq2set(PyObject *seq, fd_set *set, pylist fd2obj[FD_SETSIZE + 1])\r
-{\r
-    int i;\r
-    int max = -1;\r
-    int index = 0;\r
-    PyObject* fast_seq = NULL;\r
-    PyObject* o = NULL;\r
-\r
-    fd2obj[0].obj = (PyObject*)0;            /* set list to zero size */\r
-    FD_ZERO(set);\r
-\r
-    fast_seq = PySequence_Fast(seq, "arguments 1-3 must be sequences");\r
-    if (!fast_seq)\r
-        return -1;\r
-\r
-    for (i = 0; i < PySequence_Fast_GET_SIZE(fast_seq); i++)  {\r
-        SOCKET v;\r
-\r
-        /* any intervening fileno() calls could decr this refcnt */\r
-        if (!(o = PySequence_Fast_GET_ITEM(fast_seq, i)))\r
-            return -1;\r
-\r
-        Py_INCREF(o);\r
-        v = PyObject_AsFileDescriptor( o );\r
-        if (v == -1) goto finally;\r
-\r
-#if defined(_MSC_VER) && !defined(UEFI_C_SOURCE)\r
-        max = 0;                             /* not used for Win32 */\r
-#else  /* !_MSC_VER */\r
-        if (!_PyIsSelectable_fd(v)) {\r
-            PyErr_SetString(PyExc_ValueError,\r
-                        "filedescriptor out of range in select()");\r
-            goto finally;\r
-        }\r
-        if (v > max)\r
-            max = v;\r
-#endif /* _MSC_VER */\r
-        FD_SET(v, set);\r
-\r
-        /* add object and its file descriptor to the list */\r
-        if (index >= FD_SETSIZE) {\r
-            PyErr_SetString(PyExc_ValueError,\r
-                          "too many file descriptors in select()");\r
-            goto finally;\r
-        }\r
-        fd2obj[index].obj = o;\r
-        fd2obj[index].fd = v;\r
-        fd2obj[index].sentinel = 0;\r
-        fd2obj[++index].sentinel = -1;\r
-    }\r
-    Py_DECREF(fast_seq);\r
-    return max+1;\r
-\r
-  finally:\r
-    Py_XDECREF(o);\r
-    Py_DECREF(fast_seq);\r
-    return -1;\r
-}\r
-\r
-/* returns NULL and sets the Python exception if an error occurred */\r
-static PyObject *\r
-set2list(fd_set *set, pylist fd2obj[FD_SETSIZE + 1])\r
-{\r
-    int i, j, count=0;\r
-    PyObject *list, *o;\r
-    SOCKET fd;\r
-\r
-    for (j = 0; fd2obj[j].sentinel >= 0; j++) {\r
-        if (FD_ISSET(fd2obj[j].fd, set))\r
-            count++;\r
-    }\r
-    list = PyList_New(count);\r
-    if (!list)\r
-        return NULL;\r
-\r
-    i = 0;\r
-    for (j = 0; fd2obj[j].sentinel >= 0; j++) {\r
-        fd = fd2obj[j].fd;\r
-        if (FD_ISSET(fd, set)) {\r
-            o = fd2obj[j].obj;\r
-            fd2obj[j].obj = NULL;\r
-            /* transfer ownership */\r
-            if (PyList_SetItem(list, i, o) < 0)\r
-                goto finally;\r
-\r
-            i++;\r
-        }\r
-    }\r
-    return list;\r
-  finally:\r
-    Py_DECREF(list);\r
-    return NULL;\r
-}\r
-\r
-#undef SELECT_USES_HEAP\r
-#if FD_SETSIZE > 1024\r
-#define SELECT_USES_HEAP\r
-#endif /* FD_SETSIZE > 1024 */\r
-\r
-static PyObject *\r
-select_select(PyObject *self, PyObject *args)\r
-{\r
-#ifdef SELECT_USES_HEAP\r
-    pylist *rfd2obj, *wfd2obj, *efd2obj;\r
-#else  /* !SELECT_USES_HEAP */\r
-    /* XXX: All this should probably be implemented as follows:\r
-     * - find the highest descriptor we're interested in\r
-     * - add one\r
-     * - that's the size\r
-     * See: Stevens, APitUE, $12.5.1\r
-     */\r
-    pylist rfd2obj[FD_SETSIZE + 1];\r
-    pylist wfd2obj[FD_SETSIZE + 1];\r
-    pylist efd2obj[FD_SETSIZE + 1];\r
-#endif /* SELECT_USES_HEAP */\r
-    PyObject *ifdlist, *ofdlist, *efdlist;\r
-    PyObject *ret = NULL;\r
-    PyObject *tout = Py_None;\r
-    fd_set ifdset, ofdset, efdset;\r
-    double timeout;\r
-    struct timeval tv, *tvp;\r
-    long seconds;\r
-    int imax, omax, emax, max;\r
-    int n;\r
-\r
-    /* convert arguments */\r
-    if (!PyArg_UnpackTuple(args, "select", 3, 4,\r
-                          &ifdlist, &ofdlist, &efdlist, &tout))\r
-        return NULL;\r
-\r
-    if (tout == Py_None)\r
-        tvp = (struct timeval *)0;\r
-    else if (!PyNumber_Check(tout)) {\r
-        PyErr_SetString(PyExc_TypeError,\r
-                        "timeout must be a float or None");\r
-        return NULL;\r
-    }\r
-    else {\r
-        timeout = PyFloat_AsDouble(tout);\r
-        if (timeout == -1 && PyErr_Occurred())\r
-            return NULL;\r
-        if (timeout > (double)LONG_MAX) {\r
-            PyErr_SetString(PyExc_OverflowError,\r
-                            "timeout period too long");\r
-            return NULL;\r
-        }\r
-        seconds = (long)timeout;\r
-        timeout = timeout - (double)seconds;\r
-        tv.tv_sec = seconds;\r
-        tv.tv_usec = (long)(timeout * 1E6);\r
-        tvp = &tv;\r
-    }\r
-\r
-\r
-#ifdef SELECT_USES_HEAP\r
-    /* Allocate memory for the lists */\r
-    rfd2obj = PyMem_NEW(pylist, FD_SETSIZE + 1);\r
-    wfd2obj = PyMem_NEW(pylist, FD_SETSIZE + 1);\r
-    efd2obj = PyMem_NEW(pylist, FD_SETSIZE + 1);\r
-    if (rfd2obj == NULL || wfd2obj == NULL || efd2obj == NULL) {\r
-        if (rfd2obj) PyMem_DEL(rfd2obj);\r
-        if (wfd2obj) PyMem_DEL(wfd2obj);\r
-        if (efd2obj) PyMem_DEL(efd2obj);\r
-        return PyErr_NoMemory();\r
-    }\r
-#endif /* SELECT_USES_HEAP */\r
-    /* Convert sequences to fd_sets, and get maximum fd number\r
-     * propagates the Python exception set in seq2set()\r
-     */\r
-    rfd2obj[0].sentinel = -1;\r
-    wfd2obj[0].sentinel = -1;\r
-    efd2obj[0].sentinel = -1;\r
-    if ((imax=seq2set(ifdlist, &ifdset, rfd2obj)) < 0)\r
-        goto finally;\r
-    if ((omax=seq2set(ofdlist, &ofdset, wfd2obj)) < 0)\r
-        goto finally;\r
-    if ((emax=seq2set(efdlist, &efdset, efd2obj)) < 0)\r
-        goto finally;\r
-    max = imax;\r
-    if (omax > max) max = omax;\r
-    if (emax > max) max = emax;\r
-\r
-    Py_BEGIN_ALLOW_THREADS\r
-    n = select(max, &ifdset, &ofdset, &efdset, tvp);\r
-    Py_END_ALLOW_THREADS\r
-\r
-#ifdef MS_WINDOWS\r
-    if (n == SOCKET_ERROR) {\r
-        PyErr_SetExcFromWindowsErr(SelectError, WSAGetLastError());\r
-    }\r
-#else\r
-    if (n < 0) {\r
-        PyErr_SetFromErrno(SelectError);\r
-    }\r
-#endif\r
-    else {\r
-        /* any of these three calls can raise an exception.  it's more\r
-           convenient to test for this after all three calls... but\r
-           is that acceptable?\r
-        */\r
-        ifdlist = set2list(&ifdset, rfd2obj);\r
-        ofdlist = set2list(&ofdset, wfd2obj);\r
-        efdlist = set2list(&efdset, efd2obj);\r
-        if (PyErr_Occurred())\r
-            ret = NULL;\r
-        else\r
-            ret = PyTuple_Pack(3, ifdlist, ofdlist, efdlist);\r
-\r
-        Py_DECREF(ifdlist);\r
-        Py_DECREF(ofdlist);\r
-        Py_DECREF(efdlist);\r
-    }\r
-\r
-  finally:\r
-    reap_obj(rfd2obj);\r
-    reap_obj(wfd2obj);\r
-    reap_obj(efd2obj);\r
-#ifdef SELECT_USES_HEAP\r
-    PyMem_DEL(rfd2obj);\r
-    PyMem_DEL(wfd2obj);\r
-    PyMem_DEL(efd2obj);\r
-#endif /* SELECT_USES_HEAP */\r
-    return ret;\r
-}\r
-\r
-#if defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)\r
-/*\r
- * poll() support\r
- */\r
-\r
-typedef struct {\r
-    PyObject_HEAD\r
-    PyObject *dict;\r
-    int ufd_uptodate;\r
-    int ufd_len;\r
-    struct pollfd *ufds;\r
-    int poll_running;\r
-} pollObject;\r
-\r
-static PyTypeObject poll_Type;\r
-\r
-/* Update the malloc'ed array of pollfds to match the dictionary\r
-   contained within a pollObject.  Return 1 on success, 0 on an error.\r
-*/\r
-\r
-static int\r
-update_ufd_array(pollObject *self)\r
-{\r
-    Py_ssize_t i, pos;\r
-    PyObject *key, *value;\r
-    struct pollfd *old_ufds = self->ufds;\r
-\r
-    self->ufd_len = PyDict_Size(self->dict);\r
-    PyMem_RESIZE(self->ufds, struct pollfd, self->ufd_len);\r
-    if (self->ufds == NULL) {\r
-        self->ufds = old_ufds;\r
-        PyErr_NoMemory();\r
-        return 0;\r
-    }\r
-\r
-    i = pos = 0;\r
-    while (PyDict_Next(self->dict, &pos, &key, &value)) {\r
-        assert(i < self->ufd_len);\r
-        /* Never overflow */\r
-        self->ufds[i].fd = (int)PyInt_AsLong(key);\r
-        self->ufds[i].events = (short)(unsigned short)PyInt_AsLong(value);\r
-        i++;\r
-    }\r
-    assert(i == self->ufd_len);\r
-    self->ufd_uptodate = 1;\r
-    return 1;\r
-}\r
-\r
-static int\r
-ushort_converter(PyObject *obj, void *ptr)\r
-{\r
-    unsigned long uval;\r
-\r
-    uval = PyLong_AsUnsignedLong(obj);\r
-    if (uval == (unsigned long)-1 && PyErr_Occurred())\r
-        return 0;\r
-    if (uval > USHRT_MAX) {\r
-        PyErr_SetString(PyExc_OverflowError,\r
-                        "Python int too large for C unsigned short");\r
-        return 0;\r
-    }\r
-\r
-    *(unsigned short *)ptr = Py_SAFE_DOWNCAST(uval, unsigned long, unsigned short);\r
-    return 1;\r
-}\r
-\r
-PyDoc_STRVAR(poll_register_doc,\r
-"register(fd [, eventmask] ) -> None\n\n\\r
-Register a file descriptor with the polling object.\n\\r
-fd -- either an integer, or an object with a fileno() method returning an\n\\r
-      int.\n\\r
-events -- an optional bitmask describing the type of events to check for");\r
-\r
-static PyObject *\r
-poll_register(pollObject *self, PyObject *args)\r
-{\r
-    PyObject *o, *key, *value;\r
-    int fd;\r
-    unsigned short events = POLLIN | POLLPRI | POLLOUT;\r
-    int err;\r
-\r
-    if (!PyArg_ParseTuple(args, "O|O&:register", &o, ushort_converter, &events))\r
-        return NULL;\r
-\r
-    fd = PyObject_AsFileDescriptor(o);\r
-    if (fd == -1) return NULL;\r
-\r
-    /* Add entry to the internal dictionary: the key is the\r
-       file descriptor, and the value is the event mask. */\r
-    key = PyInt_FromLong(fd);\r
-    if (key == NULL)\r
-        return NULL;\r
-    value = PyInt_FromLong(events);\r
-    if (value == NULL) {\r
-        Py_DECREF(key);\r
-        return NULL;\r
-    }\r
-    err = PyDict_SetItem(self->dict, key, value);\r
-    Py_DECREF(key);\r
-    Py_DECREF(value);\r
-    if (err < 0)\r
-        return NULL;\r
-\r
-    self->ufd_uptodate = 0;\r
-\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-\r
-PyDoc_STRVAR(poll_modify_doc,\r
-"modify(fd, eventmask) -> None\n\n\\r
-Modify an already registered file descriptor.\n\\r
-fd -- either an integer, or an object with a fileno() method returning an\n\\r
-      int.\n\\r
-events -- an optional bitmask describing the type of events to check for");\r
-\r
-static PyObject *\r
-poll_modify(pollObject *self, PyObject *args)\r
-{\r
-    PyObject *o, *key, *value;\r
-    int fd;\r
-    unsigned short events;\r
-    int err;\r
-\r
-    if (!PyArg_ParseTuple(args, "OO&:modify", &o, ushort_converter, &events))\r
-        return NULL;\r
-\r
-    fd = PyObject_AsFileDescriptor(o);\r
-    if (fd == -1) return NULL;\r
-\r
-    /* Modify registered fd */\r
-    key = PyInt_FromLong(fd);\r
-    if (key == NULL)\r
-        return NULL;\r
-    if (PyDict_GetItem(self->dict, key) == NULL) {\r
-        errno = ENOENT;\r
-        PyErr_SetFromErrno(PyExc_IOError);\r
-        return NULL;\r
-    }\r
-    value = PyInt_FromLong(events);\r
-    if (value == NULL) {\r
-        Py_DECREF(key);\r
-        return NULL;\r
-    }\r
-    err = PyDict_SetItem(self->dict, key, value);\r
-    Py_DECREF(key);\r
-    Py_DECREF(value);\r
-    if (err < 0)\r
-        return NULL;\r
-\r
-    self->ufd_uptodate = 0;\r
-\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-\r
-\r
-PyDoc_STRVAR(poll_unregister_doc,\r
-"unregister(fd) -> None\n\n\\r
-Remove a file descriptor being tracked by the polling object.");\r
-\r
-static PyObject *\r
-poll_unregister(pollObject *self, PyObject *o)\r
-{\r
-    PyObject *key;\r
-    int fd;\r
-\r
-    fd = PyObject_AsFileDescriptor( o );\r
-    if (fd == -1)\r
-        return NULL;\r
-\r
-    /* Check whether the fd is already in the array */\r
-    key = PyInt_FromLong(fd);\r
-    if (key == NULL)\r
-        return NULL;\r
-\r
-    if (PyDict_DelItem(self->dict, key) == -1) {\r
-        Py_DECREF(key);\r
-        /* This will simply raise the KeyError set by PyDict_DelItem\r
-           if the file descriptor isn't registered. */\r
-        return NULL;\r
-    }\r
-\r
-    Py_DECREF(key);\r
-    self->ufd_uptodate = 0;\r
-\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-\r
-PyDoc_STRVAR(poll_poll_doc,\r
-"poll( [timeout] ) -> list of (fd, event) 2-tuples\n\n\\r
-Polls the set of registered file descriptors, returning a list containing \n\\r
-any descriptors that have events or errors to report.");\r
-\r
-static PyObject *\r
-poll_poll(pollObject *self, PyObject *args)\r
-{\r
-    PyObject *result_list = NULL, *tout = NULL;\r
-    int timeout = 0, poll_result, i, j;\r
-    PyObject *value = NULL, *num = NULL;\r
-\r
-    if (!PyArg_UnpackTuple(args, "poll", 0, 1, &tout)) {\r
-        return NULL;\r
-    }\r
-\r
-    /* Check values for timeout */\r
-    if (tout == NULL || tout == Py_None)\r
-        timeout = -1;\r
-    else if (!PyNumber_Check(tout)) {\r
-        PyErr_SetString(PyExc_TypeError,\r
-                        "timeout must be an integer or None");\r
-        return NULL;\r
-    }\r
-    else {\r
-        tout = PyNumber_Int(tout);\r
-        if (!tout)\r
-            return NULL;\r
-        timeout = _PyInt_AsInt(tout);\r
-        Py_DECREF(tout);\r
-        if (timeout == -1 && PyErr_Occurred())\r
-            return NULL;\r
-    }\r
-\r
-    /* Avoid concurrent poll() invocation, issue 8865 */\r
-    if (self->poll_running) {\r
-        PyErr_SetString(PyExc_RuntimeError,\r
-                        "concurrent poll() invocation");\r
-        return NULL;\r
-    }\r
-\r
-    /* Ensure the ufd array is up to date */\r
-    if (!self->ufd_uptodate)\r
-        if (update_ufd_array(self) == 0)\r
-            return NULL;\r
-\r
-    self->poll_running = 1;\r
-\r
-    /* call poll() */\r
-    Py_BEGIN_ALLOW_THREADS\r
-    poll_result = poll(self->ufds, self->ufd_len, timeout);\r
-    Py_END_ALLOW_THREADS\r
-\r
-    self->poll_running = 0;\r
-\r
-    if (poll_result < 0) {\r
-        PyErr_SetFromErrno(SelectError);\r
-        return NULL;\r
-    }\r
-\r
-    /* build the result list */\r
-\r
-    result_list = PyList_New(poll_result);\r
-    if (!result_list)\r
-        return NULL;\r
-    else {\r
-        for (i = 0, j = 0; j < poll_result; j++) {\r
-            /* skip to the next fired descriptor */\r
-            while (!self->ufds[i].revents) {\r
-                i++;\r
-            }\r
-            /* if we hit a NULL return, set value to NULL\r
-               and break out of loop; code at end will\r
-               clean up result_list */\r
-            value = PyTuple_New(2);\r
-            if (value == NULL)\r
-                goto error;\r
-            num = PyInt_FromLong(self->ufds[i].fd);\r
-            if (num == NULL) {\r
-                Py_DECREF(value);\r
-                goto error;\r
-            }\r
-            PyTuple_SET_ITEM(value, 0, num);\r
-\r
-            /* The &0xffff is a workaround for AIX.  'revents'\r
-               is a 16-bit short, and IBM assigned POLLNVAL\r
-               to be 0x8000, so the conversion to int results\r
-               in a negative number. See SF bug #923315. */\r
-            num = PyInt_FromLong(self->ufds[i].revents & 0xffff);\r
-            if (num == NULL) {\r
-                Py_DECREF(value);\r
-                goto error;\r
-            }\r
-            PyTuple_SET_ITEM(value, 1, num);\r
-            if ((PyList_SetItem(result_list, j, value)) == -1) {\r
-                Py_DECREF(value);\r
-                goto error;\r
-            }\r
-            i++;\r
-        }\r
-    }\r
-    return result_list;\r
-\r
-  error:\r
-    Py_DECREF(result_list);\r
-    return NULL;\r
-}\r
-\r
-static PyMethodDef poll_methods[] = {\r
-    {"register",        (PyCFunction)poll_register,\r
-     METH_VARARGS,  poll_register_doc},\r
-    {"modify",          (PyCFunction)poll_modify,\r
-     METH_VARARGS,  poll_modify_doc},\r
-    {"unregister",      (PyCFunction)poll_unregister,\r
-     METH_O,        poll_unregister_doc},\r
-    {"poll",            (PyCFunction)poll_poll,\r
-     METH_VARARGS,  poll_poll_doc},\r
-    {NULL,              NULL}           /* sentinel */\r
-};\r
-\r
-static pollObject *\r
-newPollObject(void)\r
-{\r
-    pollObject *self;\r
-    self = PyObject_New(pollObject, &poll_Type);\r
-    if (self == NULL)\r
-        return NULL;\r
-    /* ufd_uptodate is a Boolean, denoting whether the\r
-       array pointed to by ufds matches the contents of the dictionary. */\r
-    self->ufd_uptodate = 0;\r
-    self->ufds = NULL;\r
-    self->poll_running = 0;\r
-    self->dict = PyDict_New();\r
-    if (self->dict == NULL) {\r
-        Py_DECREF(self);\r
-        return NULL;\r
-    }\r
-    return self;\r
-}\r
-\r
-static void\r
-poll_dealloc(pollObject *self)\r
-{\r
-    if (self->ufds != NULL)\r
-        PyMem_DEL(self->ufds);\r
-    Py_XDECREF(self->dict);\r
-    PyObject_Del(self);\r
-}\r
-\r
-static PyObject *\r
-poll_getattr(pollObject *self, char *name)\r
-{\r
-    return Py_FindMethod(poll_methods, (PyObject *)self, name);\r
-}\r
-\r
-static PyTypeObject poll_Type = {\r
-    /* The ob_type field must be initialized in the module init function\r
-     * to be portable to Windows without using C++. */\r
-    PyVarObject_HEAD_INIT(NULL, 0)\r
-    "select.poll",              /*tp_name*/\r
-    sizeof(pollObject),         /*tp_basicsize*/\r
-    0,                          /*tp_itemsize*/\r
-    /* methods */\r
-    (destructor)poll_dealloc, /*tp_dealloc*/\r
-    0,                          /*tp_print*/\r
-    (getattrfunc)poll_getattr, /*tp_getattr*/\r
-    0,                      /*tp_setattr*/\r
-    0,                          /*tp_compare*/\r
-    0,                          /*tp_repr*/\r
-    0,                          /*tp_as_number*/\r
-    0,                          /*tp_as_sequence*/\r
-    0,                          /*tp_as_mapping*/\r
-    0,                          /*tp_hash*/\r
-};\r
-\r
-PyDoc_STRVAR(poll_doc,\r
-"Returns a polling object, which supports registering and\n\\r
-unregistering file descriptors, and then polling them for I/O events.");\r
-\r
-static PyObject *\r
-select_poll(PyObject *self, PyObject *unused)\r
-{\r
-    return (PyObject *)newPollObject();\r
-}\r
-\r
-#ifdef __APPLE__\r
-/*\r
- * On some systems poll() sets errno on invalid file descriptors. We test\r
- * for this at runtime because this bug may be fixed or introduced between\r
- * OS releases.\r
- */\r
-static int select_have_broken_poll(void)\r
-{\r
-    int poll_test;\r
-    int filedes[2];\r
-\r
-    struct pollfd poll_struct = { 0, POLLIN|POLLPRI|POLLOUT, 0 };\r
-\r
-    /* Create a file descriptor to make invalid */\r
-    if (pipe(filedes) < 0) {\r
-        return 1;\r
-    }\r
-    poll_struct.fd = filedes[0];\r
-    close(filedes[0]);\r
-    close(filedes[1]);\r
-    poll_test = poll(&poll_struct, 1, 0);\r
-    if (poll_test < 0) {\r
-        return 1;\r
-    } else if (poll_test == 0 && poll_struct.revents != POLLNVAL) {\r
-        return 1;\r
-    }\r
-    return 0;\r
-}\r
-#endif /* __APPLE__ */\r
-\r
-#endif /* HAVE_POLL */\r
-\r
-#ifdef HAVE_EPOLL\r
-/* **************************************************************************\r
- *                      epoll interface for Linux 2.6\r
- *\r
- * Written by Christian Heimes\r
- * Inspired by Twisted's _epoll.pyx and select.poll()\r
- */\r
-\r
-#ifdef HAVE_SYS_EPOLL_H\r
-#include <sys/epoll.h>\r
-#endif\r
-\r
-typedef struct {\r
-    PyObject_HEAD\r
-    SOCKET epfd;                        /* epoll control file descriptor */\r
-} pyEpoll_Object;\r
-\r
-static PyTypeObject pyEpoll_Type;\r
-#define pyepoll_CHECK(op) (PyObject_TypeCheck((op), &pyEpoll_Type))\r
-\r
-static PyObject *\r
-pyepoll_err_closed(void)\r
-{\r
-    PyErr_SetString(PyExc_ValueError, "I/O operation on closed epoll fd");\r
-    return NULL;\r
-}\r
-\r
-static int\r
-pyepoll_internal_close(pyEpoll_Object *self)\r
-{\r
-    int save_errno = 0;\r
-    if (self->epfd >= 0) {\r
-        int epfd = self->epfd;\r
-        self->epfd = -1;\r
-        Py_BEGIN_ALLOW_THREADS\r
-        if (close(epfd) < 0)\r
-            save_errno = errno;\r
-        Py_END_ALLOW_THREADS\r
-    }\r
-    return save_errno;\r
-}\r
-\r
-static PyObject *\r
-newPyEpoll_Object(PyTypeObject *type, int sizehint, SOCKET fd)\r
-{\r
-    pyEpoll_Object *self;\r
-\r
-    if (sizehint == -1) {\r
-        sizehint = FD_SETSIZE-1;\r
-    }\r
-    else if (sizehint < 1) {\r
-        PyErr_Format(PyExc_ValueError,\r
-                     "sizehint must be greater zero, got %d",\r
-                     sizehint);\r
-        return NULL;\r
-    }\r
-\r
-    assert(type != NULL && type->tp_alloc != NULL);\r
-    self = (pyEpoll_Object *) type->tp_alloc(type, 0);\r
-    if (self == NULL)\r
-        return NULL;\r
-\r
-    if (fd == -1) {\r
-        Py_BEGIN_ALLOW_THREADS\r
-        self->epfd = epoll_create(sizehint);\r
-        Py_END_ALLOW_THREADS\r
-    }\r
-    else {\r
-        self->epfd = fd;\r
-    }\r
-    if (self->epfd < 0) {\r
-        Py_DECREF(self);\r
-        PyErr_SetFromErrno(PyExc_IOError);\r
-        return NULL;\r
-    }\r
-    return (PyObject *)self;\r
-}\r
-\r
-\r
-static PyObject *\r
-pyepoll_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\r
-{\r
-    int sizehint = -1;\r
-    static char *kwlist[] = {"sizehint", NULL};\r
-\r
-    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:epoll", kwlist,\r
-                                     &sizehint))\r
-        return NULL;\r
-\r
-    return newPyEpoll_Object(type, sizehint, -1);\r
-}\r
-\r
-\r
-static void\r
-pyepoll_dealloc(pyEpoll_Object *self)\r
-{\r
-    (void)pyepoll_internal_close(self);\r
-    Py_TYPE(self)->tp_free(self);\r
-}\r
-\r
-static PyObject*\r
-pyepoll_close(pyEpoll_Object *self)\r
-{\r
-    errno = pyepoll_internal_close(self);\r
-    if (errno < 0) {\r
-        PyErr_SetFromErrno(PyExc_IOError);\r
-        return NULL;\r
-    }\r
-    Py_RETURN_NONE;\r
-}\r
-\r
-PyDoc_STRVAR(pyepoll_close_doc,\r
-"close() -> None\n\\r
-\n\\r
-Close the epoll control file descriptor. Further operations on the epoll\n\\r
-object will raise an exception.");\r
-\r
-static PyObject*\r
-pyepoll_get_closed(pyEpoll_Object *self)\r
-{\r
-    if (self->epfd < 0)\r
-        Py_RETURN_TRUE;\r
-    else\r
-        Py_RETURN_FALSE;\r
-}\r
-\r
-static PyObject*\r
-pyepoll_fileno(pyEpoll_Object *self)\r
-{\r
-    if (self->epfd < 0)\r
-        return pyepoll_err_closed();\r
-    return PyInt_FromLong(self->epfd);\r
-}\r
-\r
-PyDoc_STRVAR(pyepoll_fileno_doc,\r
-"fileno() -> int\n\\r
-\n\\r
-Return the epoll control file descriptor.");\r
-\r
-static PyObject*\r
-pyepoll_fromfd(PyObject *cls, PyObject *args)\r
-{\r
-    SOCKET fd;\r
-\r
-    if (!PyArg_ParseTuple(args, "i:fromfd", &fd))\r
-        return NULL;\r
-\r
-    return newPyEpoll_Object((PyTypeObject*)cls, -1, fd);\r
-}\r
-\r
-PyDoc_STRVAR(pyepoll_fromfd_doc,\r
-"fromfd(fd) -> epoll\n\\r
-\n\\r
-Create an epoll object from a given control fd.");\r
-\r
-static PyObject *\r
-pyepoll_internal_ctl(int epfd, int op, PyObject *pfd, unsigned int events)\r
-{\r
-    struct epoll_event ev;\r
-    int result;\r
-    int fd;\r
-\r
-    if (epfd < 0)\r
-        return pyepoll_err_closed();\r
-\r
-    fd = PyObject_AsFileDescriptor(pfd);\r
-    if (fd == -1) {\r
-        return NULL;\r
-    }\r
-\r
-    switch(op) {\r
-        case EPOLL_CTL_ADD:\r
-        case EPOLL_CTL_MOD:\r
-        ev.events = events;\r
-        ev.data.fd = fd;\r
-        Py_BEGIN_ALLOW_THREADS\r
-        result = epoll_ctl(epfd, op, fd, &ev);\r
-        Py_END_ALLOW_THREADS\r
-        break;\r
-        case EPOLL_CTL_DEL:\r
-        /* In kernel versions before 2.6.9, the EPOLL_CTL_DEL\r
-         * operation required a non-NULL pointer in event, even\r
-         * though this argument is ignored. */\r
-        Py_BEGIN_ALLOW_THREADS\r
-        result = epoll_ctl(epfd, op, fd, &ev);\r
-        if (errno == EBADF) {\r
-            /* fd already closed */\r
-            result = 0;\r
-            errno = 0;\r
-        }\r
-        Py_END_ALLOW_THREADS\r
-        break;\r
-        default:\r
-        result = -1;\r
-        errno = EINVAL;\r
-    }\r
-\r
-    if (result < 0) {\r
-        PyErr_SetFromErrno(PyExc_IOError);\r
-        return NULL;\r
-    }\r
-    Py_RETURN_NONE;\r
-}\r
-\r
-static PyObject *\r
-pyepoll_register(pyEpoll_Object *self, PyObject *args, PyObject *kwds)\r
-{\r
-    PyObject *pfd;\r
-    unsigned int events = EPOLLIN | EPOLLOUT | EPOLLPRI;\r
-    static char *kwlist[] = {"fd", "eventmask", NULL};\r
-\r
-    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|I:register", kwlist,\r
-                                     &pfd, &events)) {\r
-        return NULL;\r
-    }\r
-\r
-    return pyepoll_internal_ctl(self->epfd, EPOLL_CTL_ADD, pfd, events);\r
-}\r
-\r
-PyDoc_STRVAR(pyepoll_register_doc,\r
-"register(fd[, eventmask]) -> None\n\\r
-\n\\r
-Registers a new fd or raises an IOError if the fd is already registered.\n\\r
-fd is the target file descriptor of the operation.\n\\r
-events is a bit set composed of the various EPOLL constants; the default\n\\r
-is EPOLL_IN | EPOLL_OUT | EPOLL_PRI.\n\\r
-\n\\r
-The epoll interface supports all file descriptors that support poll.");\r
-\r
-static PyObject *\r
-pyepoll_modify(pyEpoll_Object *self, PyObject *args, PyObject *kwds)\r
-{\r
-    PyObject *pfd;\r
-    unsigned int events;\r
-    static char *kwlist[] = {"fd", "eventmask", NULL};\r
-\r
-    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OI:modify", kwlist,\r
-                                     &pfd, &events)) {\r
-        return NULL;\r
-    }\r
-\r
-    return pyepoll_internal_ctl(self->epfd, EPOLL_CTL_MOD, pfd, events);\r
-}\r
-\r
-PyDoc_STRVAR(pyepoll_modify_doc,\r
-"modify(fd, eventmask) -> None\n\\r
-\n\\r
-fd is the target file descriptor of the operation\n\\r
-events is a bit set composed of the various EPOLL constants");\r
-\r
-static PyObject *\r
-pyepoll_unregister(pyEpoll_Object *self, PyObject *args, PyObject *kwds)\r
-{\r
-    PyObject *pfd;\r
-    static char *kwlist[] = {"fd", NULL};\r
-\r
-    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:unregister", kwlist,\r
-                                     &pfd)) {\r
-        return NULL;\r
-    }\r
-\r
-    return pyepoll_internal_ctl(self->epfd, EPOLL_CTL_DEL, pfd, 0);\r
-}\r
-\r
-PyDoc_STRVAR(pyepoll_unregister_doc,\r
-"unregister(fd) -> None\n\\r
-\n\\r
-fd is the target file descriptor of the operation.");\r
-\r
-static PyObject *\r
-pyepoll_poll(pyEpoll_Object *self, PyObject *args, PyObject *kwds)\r
-{\r
-    double dtimeout = -1.;\r
-    int timeout;\r
-    int maxevents = -1;\r
-    int nfds, i;\r
-    PyObject *elist = NULL, *etuple = NULL;\r
-    struct epoll_event *evs = NULL;\r
-    static char *kwlist[] = {"timeout", "maxevents", NULL};\r
-\r
-    if (self->epfd < 0)\r
-        return pyepoll_err_closed();\r
-\r
-    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|di:poll", kwlist,\r
-                                     &dtimeout, &maxevents)) {\r
-        return NULL;\r
-    }\r
-\r
-    if (dtimeout < 0) {\r
-        timeout = -1;\r
-    }\r
-    else if (dtimeout * 1000.0 > INT_MAX) {\r
-        PyErr_SetString(PyExc_OverflowError,\r
-                        "timeout is too large");\r
-        return NULL;\r
-    }\r
-    else {\r
-        timeout = (int)(dtimeout * 1000.0);\r
-    }\r
-\r
-    if (maxevents == -1) {\r
-        maxevents = FD_SETSIZE-1;\r
-    }\r
-    else if (maxevents < 1) {\r
-        PyErr_Format(PyExc_ValueError,\r
-                     "maxevents must be greater than 0, got %d",\r
-                     maxevents);\r
-        return NULL;\r
-    }\r
-\r
-    evs = PyMem_New(struct epoll_event, maxevents);\r
-    if (evs == NULL) {\r
-        Py_DECREF(self);\r
-        PyErr_NoMemory();\r
-        return NULL;\r
-    }\r
-\r
-    Py_BEGIN_ALLOW_THREADS\r
-    nfds = epoll_wait(self->epfd, evs, maxevents, timeout);\r
-    Py_END_ALLOW_THREADS\r
-    if (nfds < 0) {\r
-        PyErr_SetFromErrno(PyExc_IOError);\r
-        goto error;\r
-    }\r
-\r
-    elist = PyList_New(nfds);\r
-    if (elist == NULL) {\r
-        goto error;\r
-    }\r
-\r
-    for (i = 0; i < nfds; i++) {\r
-        etuple = Py_BuildValue("iI", evs[i].data.fd, evs[i].events);\r
-        if (etuple == NULL) {\r
-            Py_CLEAR(elist);\r
-            goto error;\r
-        }\r
-        PyList_SET_ITEM(elist, i, etuple);\r
-    }\r
-\r
-    error:\r
-    PyMem_Free(evs);\r
-    return elist;\r
-}\r
-\r
-PyDoc_STRVAR(pyepoll_poll_doc,\r
-"poll([timeout=-1[, maxevents=-1]]) -> [(fd, events), (...)]\n\\r
-\n\\r
-Wait for events on the epoll file descriptor for a maximum time of timeout\n\\r
-in seconds (as float). -1 makes poll wait indefinitely.\n\\r
-Up to maxevents are returned to the caller.");\r
-\r
-static PyMethodDef pyepoll_methods[] = {\r
-    {"fromfd",          (PyCFunction)pyepoll_fromfd,\r
-     METH_VARARGS | METH_CLASS, pyepoll_fromfd_doc},\r
-    {"close",           (PyCFunction)pyepoll_close,     METH_NOARGS,\r
-     pyepoll_close_doc},\r
-    {"fileno",          (PyCFunction)pyepoll_fileno,    METH_NOARGS,\r
-     pyepoll_fileno_doc},\r
-    {"modify",          (PyCFunction)pyepoll_modify,\r
-     METH_VARARGS | METH_KEYWORDS,      pyepoll_modify_doc},\r
-    {"register",        (PyCFunction)pyepoll_register,\r
-     METH_VARARGS | METH_KEYWORDS,      pyepoll_register_doc},\r
-    {"unregister",      (PyCFunction)pyepoll_unregister,\r
-     METH_VARARGS | METH_KEYWORDS,      pyepoll_unregister_doc},\r
-    {"poll",            (PyCFunction)pyepoll_poll,\r
-     METH_VARARGS | METH_KEYWORDS,      pyepoll_poll_doc},\r
-    {NULL,      NULL},\r
-};\r
-\r
-static PyGetSetDef pyepoll_getsetlist[] = {\r
-    {"closed", (getter)pyepoll_get_closed, NULL,\r
-     "True if the epoll handler is closed"},\r
-    {0},\r
-};\r
-\r
-PyDoc_STRVAR(pyepoll_doc,\r
-"select.epoll([sizehint=-1])\n\\r
-\n\\r
-Returns an epolling object\n\\r
-\n\\r
-sizehint must be a positive integer or -1 for the default size. The\n\\r
-sizehint is used to optimize internal data structures. It doesn't limit\n\\r
-the maximum number of monitored events.");\r
-\r
-static PyTypeObject pyEpoll_Type = {\r
-    PyVarObject_HEAD_INIT(NULL, 0)\r
-    "select.epoll",                                     /* tp_name */\r
-    sizeof(pyEpoll_Object),                             /* tp_basicsize */\r
-    0,                                                  /* tp_itemsize */\r
-    (destructor)pyepoll_dealloc,                        /* tp_dealloc */\r
-    0,                                                  /* tp_print */\r
-    0,                                                  /* tp_getattr */\r
-    0,                                                  /* tp_setattr */\r
-    0,                                                  /* tp_compare */\r
-    0,                                                  /* tp_repr */\r
-    0,                                                  /* tp_as_number */\r
-    0,                                                  /* tp_as_sequence */\r
-    0,                                                  /* tp_as_mapping */\r
-    0,                                                  /* tp_hash */\r
-    0,                                                  /* tp_call */\r
-    0,                                                  /* tp_str */\r
-    PyObject_GenericGetAttr,                            /* tp_getattro */\r
-    0,                                                  /* tp_setattro */\r
-    0,                                                  /* tp_as_buffer */\r
-    Py_TPFLAGS_DEFAULT,                                 /* tp_flags */\r
-    pyepoll_doc,                                        /* tp_doc */\r
-    0,                                                  /* tp_traverse */\r
-    0,                                                  /* tp_clear */\r
-    0,                                                  /* tp_richcompare */\r
-    0,                                                  /* tp_weaklistoffset */\r
-    0,                                                  /* tp_iter */\r
-    0,                                                  /* tp_iternext */\r
-    pyepoll_methods,                                    /* tp_methods */\r
-    0,                                                  /* tp_members */\r
-    pyepoll_getsetlist,                                 /* tp_getset */\r
-    0,                                                  /* tp_base */\r
-    0,                                                  /* tp_dict */\r
-    0,                                                  /* tp_descr_get */\r
-    0,                                                  /* tp_descr_set */\r
-    0,                                                  /* tp_dictoffset */\r
-    0,                                                  /* tp_init */\r
-    0,                                                  /* tp_alloc */\r
-    pyepoll_new,                                        /* tp_new */\r
-    0,                                                  /* tp_free */\r
-};\r
-\r
-#endif /* HAVE_EPOLL */\r
-\r
-#ifdef HAVE_KQUEUE\r
-/* **************************************************************************\r
- *                      kqueue interface for BSD\r
- *\r
- * Copyright (c) 2000 Doug White, 2006 James Knight, 2007 Christian Heimes\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * 1. Redistributions of source code must retain the above copyright\r
- *    notice, this list of conditions and the following disclaimer.\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- *    notice, this list of conditions and the following disclaimer in the\r
- *    documentation and/or other materials provided with the distribution.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
- * SUCH DAMAGE.\r
- */\r
-\r
-#ifdef HAVE_SYS_EVENT_H\r
-#include <sys/event.h>\r
-#endif\r
-\r
-PyDoc_STRVAR(kqueue_event_doc,\r
-"kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)\n\\r
-\n\\r
-This object is the equivalent of the struct kevent for the C API.\n\\r
-\n\\r
-See the kqueue manpage for more detailed information about the meaning\n\\r
-of the arguments.\n\\r
-\n\\r
-One minor note: while you might hope that udata could store a\n\\r
-reference to a python object, it cannot, because it is impossible to\n\\r
-keep a proper reference count of the object once it's passed into the\n\\r
-kernel. Therefore, I have restricted it to only storing an integer.  I\n\\r
-recommend ignoring it and simply using the 'ident' field to key off\n\\r
-of. You could also set up a dictionary on the python side to store a\n\\r
-udata->object mapping.");\r
-\r
-typedef struct {\r
-    PyObject_HEAD\r
-    struct kevent e;\r
-} kqueue_event_Object;\r
-\r
-static PyTypeObject kqueue_event_Type;\r
-\r
-#define kqueue_event_Check(op) (PyObject_TypeCheck((op), &kqueue_event_Type))\r
-\r
-typedef struct {\r
-    PyObject_HEAD\r
-    SOCKET kqfd;                /* kqueue control fd */\r
-} kqueue_queue_Object;\r
-\r
-static PyTypeObject kqueue_queue_Type;\r
-\r
-#define kqueue_queue_Check(op) (PyObject_TypeCheck((op), &kqueue_queue_Type))\r
-\r
-#if (SIZEOF_UINTPTR_T != SIZEOF_VOID_P)\r
-#   error uintptr_t does not match void *!\r
-#elif (SIZEOF_UINTPTR_T == SIZEOF_LONG_LONG)\r
-#   define T_UINTPTRT         T_ULONGLONG\r
-#   define T_INTPTRT          T_LONGLONG\r
-#   define PyLong_AsUintptr_t PyLong_AsUnsignedLongLong\r
-#   define UINTPTRT_FMT_UNIT  "K"\r
-#   define INTPTRT_FMT_UNIT   "L"\r
-#elif (SIZEOF_UINTPTR_T == SIZEOF_LONG)\r
-#   define T_UINTPTRT         T_ULONG\r
-#   define T_INTPTRT          T_LONG\r
-#   define PyLong_AsUintptr_t PyLong_AsUnsignedLong\r
-#   define UINTPTRT_FMT_UNIT  "k"\r
-#   define INTPTRT_FMT_UNIT   "l"\r
-#elif (SIZEOF_UINTPTR_T == SIZEOF_INT)\r
-#   define T_UINTPTRT         T_UINT\r
-#   define T_INTPTRT          T_INT\r
-#   define PyLong_AsUintptr_t PyLong_AsUnsignedLong\r
-#   define UINTPTRT_FMT_UNIT  "I"\r
-#   define INTPTRT_FMT_UNIT   "i"\r
-#else\r
-#   error uintptr_t does not match int, long, or long long!\r
-#endif\r
-\r
-/*\r
- * kevent is not standard and its members vary across BSDs.\r
- */\r
-#if !defined(__OpenBSD__)\r
-#   define IDENT_TYPE T_UINTPTRT\r
-#   define IDENT_CAST Py_intptr_t\r
-#   define DATA_TYPE  T_INTPTRT\r
-#   define DATA_FMT_UNIT INTPTRT_FMT_UNIT\r
-#   define IDENT_AsType PyLong_AsUintptr_t\r
-#else\r
-#   define IDENT_TYPE T_UINT\r
-#   define IDENT_CAST int\r
-#   define DATA_TYPE  T_INT\r
-#   define DATA_FMT_UNIT "i"\r
-#   define IDENT_AsType PyLong_AsUnsignedLong\r
-#endif\r
-\r
-/* Unfortunately, we can't store python objects in udata, because\r
- * kevents in the kernel can be removed without warning, which would\r
- * forever lose the refcount on the object stored with it.\r
- */\r
-\r
-#define KQ_OFF(x) offsetof(kqueue_event_Object, x)\r
-static struct PyMemberDef kqueue_event_members[] = {\r
-    {"ident",           IDENT_TYPE,     KQ_OFF(e.ident)},\r
-    {"filter",          T_SHORT,        KQ_OFF(e.filter)},\r
-    {"flags",           T_USHORT,       KQ_OFF(e.flags)},\r
-    {"fflags",          T_UINT,         KQ_OFF(e.fflags)},\r
-    {"data",            DATA_TYPE,      KQ_OFF(e.data)},\r
-    {"udata",           T_UINTPTRT,     KQ_OFF(e.udata)},\r
-    {NULL} /* Sentinel */\r
-};\r
-#undef KQ_OFF\r
-\r
-static PyObject *\r
-\r
-kqueue_event_repr(kqueue_event_Object *s)\r
-{\r
-    char buf[1024];\r
-    PyOS_snprintf(\r
-        buf, sizeof(buf),\r
-        "<select.kevent ident=%zu filter=%d flags=0x%x fflags=0x%x "\r
-        "data=0x%zd udata=%p>",\r
-        (size_t)(s->e.ident), s->e.filter, s->e.flags,\r
-        s->e.fflags, (Py_ssize_t)(s->e.data), s->e.udata);\r
-    return PyString_FromString(buf);\r
-}\r
-\r
-static int\r
-kqueue_event_init(kqueue_event_Object *self, PyObject *args, PyObject *kwds)\r
-{\r
-    PyObject *pfd;\r
-    static char *kwlist[] = {"ident", "filter", "flags", "fflags",\r
-                             "data", "udata", NULL};\r
-    static char *fmt = "O|hHI" DATA_FMT_UNIT UINTPTRT_FMT_UNIT ":kevent";\r
-\r
-    EV_SET(&(self->e), 0, EVFILT_READ, EV_ADD, 0, 0, 0); /* defaults */\r
-\r
-    if (!PyArg_ParseTupleAndKeywords(args, kwds, fmt, kwlist,\r
-        &pfd, &(self->e.filter), &(self->e.flags),\r
-        &(self->e.fflags), &(self->e.data), &(self->e.udata))) {\r
-        return -1;\r
-    }\r
-\r
-    if (PyLong_Check(pfd)\r
-#if IDENT_TYPE == T_UINT\r
-  && PyLong_AsUnsignedLong(pfd) <= UINT_MAX\r
-#endif\r
-    ) {\r
-        self->e.ident = IDENT_AsType(pfd);\r
-    }\r
-    else {\r
-        self->e.ident = PyObject_AsFileDescriptor(pfd);\r
-    }\r
-    if (PyErr_Occurred()) {\r
-        return -1;\r
-    }\r
-    return 0;\r
-}\r
-\r
-static PyObject *\r
-kqueue_event_richcompare(kqueue_event_Object *s, kqueue_event_Object *o,\r
-                         int op)\r
-{\r
-    Py_intptr_t result = 0;\r
-\r
-    if (!kqueue_event_Check(o)) {\r
-        if (op == Py_EQ || op == Py_NE) {\r
-            PyObject *res = op == Py_EQ ? Py_False : Py_True;\r
-            Py_INCREF(res);\r
-            return res;\r
-        }\r
-        PyErr_Format(PyExc_TypeError,\r
-            "can't compare %.200s to %.200s",\r
-            Py_TYPE(s)->tp_name, Py_TYPE(o)->tp_name);\r
-        return NULL;\r
-    }\r
-    if (((result = (IDENT_CAST)(s->e.ident - o->e.ident)) == 0) &&\r
-        ((result = s->e.filter - o->e.filter) == 0) &&\r
-        ((result = s->e.flags - o->e.flags) == 0) &&\r
-        ((result = (int)(s->e.fflags - o->e.fflags)) == 0) &&\r
-        ((result = s->e.data - o->e.data) == 0) &&\r
-        ((result = s->e.udata - o->e.udata) == 0)\r
-       ) {\r
-        result = 0;\r
-    }\r
-\r
-    switch (op) {\r
-        case Py_EQ:\r
-        result = (result == 0);\r
-        break;\r
-        case Py_NE:\r
-        result = (result != 0);\r
-        break;\r
-        case Py_LE:\r
-        result = (result <= 0);\r
-        break;\r
-        case Py_GE:\r
-        result = (result >= 0);\r
-        break;\r
-        case Py_LT:\r
-        result = (result < 0);\r
-        break;\r
-        case Py_GT:\r
-        result = (result > 0);\r
-        break;\r
-    }\r
-    return PyBool_FromLong((long)result);\r
-}\r
-\r
-static PyTypeObject kqueue_event_Type = {\r
-    PyVarObject_HEAD_INIT(NULL, 0)\r
-    "select.kevent",                                    /* tp_name */\r
-    sizeof(kqueue_event_Object),                        /* tp_basicsize */\r
-    0,                                                  /* tp_itemsize */\r
-    0,                                                  /* tp_dealloc */\r
-    0,                                                  /* tp_print */\r
-    0,                                                  /* tp_getattr */\r
-    0,                                                  /* tp_setattr */\r
-    0,                                                  /* tp_compare */\r
-    (reprfunc)kqueue_event_repr,                        /* tp_repr */\r
-    0,                                                  /* tp_as_number */\r
-    0,                                                  /* tp_as_sequence */\r
-    0,                                                  /* tp_as_mapping */\r
-    0,                                                  /* tp_hash */\r
-    0,                                                  /* tp_call */\r
-    0,                                                  /* tp_str */\r
-    0,                                                  /* tp_getattro */\r
-    0,                                                  /* tp_setattro */\r
-    0,                                                  /* tp_as_buffer */\r
-    Py_TPFLAGS_DEFAULT,                                 /* tp_flags */\r
-    kqueue_event_doc,                                   /* tp_doc */\r
-    0,                                                  /* tp_traverse */\r
-    0,                                                  /* tp_clear */\r
-    (richcmpfunc)kqueue_event_richcompare,              /* tp_richcompare */\r
-    0,                                                  /* tp_weaklistoffset */\r
-    0,                                                  /* tp_iter */\r
-    0,                                                  /* tp_iternext */\r
-    0,                                                  /* tp_methods */\r
-    kqueue_event_members,                               /* tp_members */\r
-    0,                                                  /* tp_getset */\r
-    0,                                                  /* tp_base */\r
-    0,                                                  /* tp_dict */\r
-    0,                                                  /* tp_descr_get */\r
-    0,                                                  /* tp_descr_set */\r
-    0,                                                  /* tp_dictoffset */\r
-    (initproc)kqueue_event_init,                        /* tp_init */\r
-    0,                                                  /* tp_alloc */\r
-    0,                                                  /* tp_new */\r
-    0,                                                  /* tp_free */\r
-};\r
-\r
-static PyObject *\r
-kqueue_queue_err_closed(void)\r
-{\r
-    PyErr_SetString(PyExc_ValueError, "I/O operation on closed kqueue fd");\r
-    return NULL;\r
-}\r
-\r
-static int\r
-kqueue_queue_internal_close(kqueue_queue_Object *self)\r
-{\r
-    int save_errno = 0;\r
-    if (self->kqfd >= 0) {\r
-        int kqfd = self->kqfd;\r
-        self->kqfd = -1;\r
-        Py_BEGIN_ALLOW_THREADS\r
-        if (close(kqfd) < 0)\r
-            save_errno = errno;\r
-        Py_END_ALLOW_THREADS\r
-    }\r
-    return save_errno;\r
-}\r
-\r
-static PyObject *\r
-newKqueue_Object(PyTypeObject *type, SOCKET fd)\r
-{\r
-    kqueue_queue_Object *self;\r
-    assert(type != NULL && type->tp_alloc != NULL);\r
-    self = (kqueue_queue_Object *) type->tp_alloc(type, 0);\r
-    if (self == NULL) {\r
-        return NULL;\r
-    }\r
-\r
-    if (fd == -1) {\r
-        Py_BEGIN_ALLOW_THREADS\r
-        self->kqfd = kqueue();\r
-        Py_END_ALLOW_THREADS\r
-    }\r
-    else {\r
-        self->kqfd = fd;\r
-    }\r
-    if (self->kqfd < 0) {\r
-        Py_DECREF(self);\r
-        PyErr_SetFromErrno(PyExc_IOError);\r
-        return NULL;\r
-    }\r
-    return (PyObject *)self;\r
-}\r
-\r
-static PyObject *\r
-kqueue_queue_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\r
-{\r
-\r
-    if ((args != NULL && PyObject_Size(args)) ||\r
-                    (kwds != NULL && PyObject_Size(kwds))) {\r
-        PyErr_SetString(PyExc_ValueError,\r
-                        "select.kqueue doesn't accept arguments");\r
-        return NULL;\r
-    }\r
-\r
-    return newKqueue_Object(type, -1);\r
-}\r
-\r
-static void\r
-kqueue_queue_dealloc(kqueue_queue_Object *self)\r
-{\r
-    kqueue_queue_internal_close(self);\r
-    Py_TYPE(self)->tp_free(self);\r
-}\r
-\r
-static PyObject*\r
-kqueue_queue_close(kqueue_queue_Object *self)\r
-{\r
-    errno = kqueue_queue_internal_close(self);\r
-    if (errno < 0) {\r
-        PyErr_SetFromErrno(PyExc_IOError);\r
-        return NULL;\r
-    }\r
-    Py_RETURN_NONE;\r
-}\r
-\r
-PyDoc_STRVAR(kqueue_queue_close_doc,\r
-"close() -> None\n\\r
-\n\\r
-Close the kqueue control file descriptor. Further operations on the kqueue\n\\r
-object will raise an exception.");\r
-\r
-static PyObject*\r
-kqueue_queue_get_closed(kqueue_queue_Object *self)\r
-{\r
-    if (self->kqfd < 0)\r
-        Py_RETURN_TRUE;\r
-    else\r
-        Py_RETURN_FALSE;\r
-}\r
-\r
-static PyObject*\r
-kqueue_queue_fileno(kqueue_queue_Object *self)\r
-{\r
-    if (self->kqfd < 0)\r
-        return kqueue_queue_err_closed();\r
-    return PyInt_FromLong(self->kqfd);\r
-}\r
-\r
-PyDoc_STRVAR(kqueue_queue_fileno_doc,\r
-"fileno() -> int\n\\r
-\n\\r
-Return the kqueue control file descriptor.");\r
-\r
-static PyObject*\r
-kqueue_queue_fromfd(PyObject *cls, PyObject *args)\r
-{\r
-    SOCKET fd;\r
-\r
-    if (!PyArg_ParseTuple(args, "i:fromfd", &fd))\r
-        return NULL;\r
-\r
-    return newKqueue_Object((PyTypeObject*)cls, fd);\r
-}\r
-\r
-PyDoc_STRVAR(kqueue_queue_fromfd_doc,\r
-"fromfd(fd) -> kqueue\n\\r
-\n\\r
-Create a kqueue object from a given control fd.");\r
-\r
-static PyObject *\r
-kqueue_queue_control(kqueue_queue_Object *self, PyObject *args)\r
-{\r
-    int nevents = 0;\r
-    int gotevents = 0;\r
-    int nchanges = 0;\r
-    int i = 0;\r
-    PyObject *otimeout = NULL;\r
-    PyObject *ch = NULL;\r
-    PyObject *it = NULL, *ei = NULL;\r
-    PyObject *result = NULL;\r
-    struct kevent *evl = NULL;\r
-    struct kevent *chl = NULL;\r
-    struct timespec timeoutspec;\r
-    struct timespec *ptimeoutspec;\r
-\r
-    if (self->kqfd < 0)\r
-        return kqueue_queue_err_closed();\r
-\r
-    if (!PyArg_ParseTuple(args, "Oi|O:control", &ch, &nevents, &otimeout))\r
-        return NULL;\r
-\r
-    if (nevents < 0) {\r
-        PyErr_Format(PyExc_ValueError,\r
-            "Length of eventlist must be 0 or positive, got %d",\r
-            nevents);\r
-        return NULL;\r
-    }\r
-\r
-    if (otimeout == Py_None || otimeout == NULL) {\r
-        ptimeoutspec = NULL;\r
-    }\r
-    else if (PyNumber_Check(otimeout)) {\r
-        double timeout;\r
-        long seconds;\r
-\r
-        timeout = PyFloat_AsDouble(otimeout);\r
-        if (timeout == -1 && PyErr_Occurred())\r
-            return NULL;\r
-        if (timeout > (double)LONG_MAX) {\r
-            PyErr_SetString(PyExc_OverflowError,\r
-                            "timeout period too long");\r
-            return NULL;\r
-        }\r
-        if (timeout < 0) {\r
-            PyErr_SetString(PyExc_ValueError,\r
-                            "timeout must be positive or None");\r
-            return NULL;\r
-        }\r
-\r
-        seconds = (long)timeout;\r
-        timeout = timeout - (double)seconds;\r
-        timeoutspec.tv_sec = seconds;\r
-        timeoutspec.tv_nsec = (long)(timeout * 1E9);\r
-        ptimeoutspec = &timeoutspec;\r
-    }\r
-    else {\r
-        PyErr_Format(PyExc_TypeError,\r
-            "timeout argument must be an number "\r
-            "or None, got %.200s",\r
-            Py_TYPE(otimeout)->tp_name);\r
-        return NULL;\r
-    }\r
-\r
-    if (ch != NULL && ch != Py_None) {\r
-        it = PyObject_GetIter(ch);\r
-        if (it == NULL) {\r
-            PyErr_SetString(PyExc_TypeError,\r
-                            "changelist is not iterable");\r
-            return NULL;\r
-        }\r
-        nchanges = PyObject_Size(ch);\r
-        if (nchanges < 0) {\r
-            goto error;\r
-        }\r
-\r
-        chl = PyMem_New(struct kevent, nchanges);\r
-        if (chl == NULL) {\r
-            PyErr_NoMemory();\r
-            goto error;\r
-        }\r
-        i = 0;\r
-        while ((ei = PyIter_Next(it)) != NULL) {\r
-            if (!kqueue_event_Check(ei)) {\r
-                Py_DECREF(ei);\r
-                PyErr_SetString(PyExc_TypeError,\r
-                    "changelist must be an iterable of "\r
-                    "select.kevent objects");\r
-                goto error;\r
-            } else {\r
-                chl[i++] = ((kqueue_event_Object *)ei)->e;\r
-            }\r
-            Py_DECREF(ei);\r
-        }\r
-    }\r
-    Py_CLEAR(it);\r
-\r
-    /* event list */\r
-    if (nevents) {\r
-        evl = PyMem_New(struct kevent, nevents);\r
-        if (evl == NULL) {\r
-            PyErr_NoMemory();\r
-            goto error;\r
-        }\r
-    }\r
-\r
-    Py_BEGIN_ALLOW_THREADS\r
-    gotevents = kevent(self->kqfd, chl, nchanges,\r
-                       evl, nevents, ptimeoutspec);\r
-    Py_END_ALLOW_THREADS\r
-\r
-    if (gotevents == -1) {\r
-        PyErr_SetFromErrno(PyExc_OSError);\r
-        goto error;\r
-    }\r
-\r
-    result = PyList_New(gotevents);\r
-    if (result == NULL) {\r
-        goto error;\r
-    }\r
-\r
-    for (i = 0; i < gotevents; i++) {\r
-        kqueue_event_Object *ch;\r
-\r
-        ch = PyObject_New(kqueue_event_Object, &kqueue_event_Type);\r
-        if (ch == NULL) {\r
-            goto error;\r
-        }\r
-        ch->e = evl[i];\r
-        PyList_SET_ITEM(result, i, (PyObject *)ch);\r
-    }\r
-    PyMem_Free(chl);\r
-    PyMem_Free(evl);\r
-    return result;\r
-\r
-    error:\r
-    PyMem_Free(chl);\r
-    PyMem_Free(evl);\r
-    Py_XDECREF(result);\r
-    Py_XDECREF(it);\r
-    return NULL;\r
-}\r
-\r
-PyDoc_STRVAR(kqueue_queue_control_doc,\r
-"control(changelist, max_events[, timeout=None]) -> eventlist\n\\r
-\n\\r
-Calls the kernel kevent function.\n\\r
-- changelist must be a list of kevent objects describing the changes\n\\r
-  to be made to the kernel's watch list or None.\n\\r
-- max_events lets you specify the maximum number of events that the\n\\r
-  kernel will return.\n\\r
-- timeout is the maximum time to wait in seconds, or else None,\n\\r
-  to wait forever. timeout accepts floats for smaller timeouts, too.");\r
-\r
-\r
-static PyMethodDef kqueue_queue_methods[] = {\r
-    {"fromfd",          (PyCFunction)kqueue_queue_fromfd,\r
-     METH_VARARGS | METH_CLASS, kqueue_queue_fromfd_doc},\r
-    {"close",           (PyCFunction)kqueue_queue_close,        METH_NOARGS,\r
-     kqueue_queue_close_doc},\r
-    {"fileno",          (PyCFunction)kqueue_queue_fileno,       METH_NOARGS,\r
-     kqueue_queue_fileno_doc},\r
-    {"control",         (PyCFunction)kqueue_queue_control,\r
-     METH_VARARGS ,     kqueue_queue_control_doc},\r
-    {NULL,      NULL},\r
-};\r
-\r
-static PyGetSetDef kqueue_queue_getsetlist[] = {\r
-    {"closed", (getter)kqueue_queue_get_closed, NULL,\r
-     "True if the kqueue handler is closed"},\r
-    {0},\r
-};\r
-\r
-PyDoc_STRVAR(kqueue_queue_doc,\r
-"Kqueue syscall wrapper.\n\\r
-\n\\r
-For example, to start watching a socket for input:\n\\r
->>> kq = kqueue()\n\\r
->>> sock = socket()\n\\r
->>> sock.connect((host, port))\n\\r
->>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_ADD)], 0)\n\\r
-\n\\r
-To wait one second for it to become writeable:\n\\r
->>> kq.control(None, 1, 1000)\n\\r
-\n\\r
-To stop listening:\n\\r
->>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)");\r
-\r
-static PyTypeObject kqueue_queue_Type = {\r
-    PyVarObject_HEAD_INIT(NULL, 0)\r
-    "select.kqueue",                                    /* tp_name */\r
-    sizeof(kqueue_queue_Object),                        /* tp_basicsize */\r
-    0,                                                  /* tp_itemsize */\r
-    (destructor)kqueue_queue_dealloc,                   /* tp_dealloc */\r
-    0,                                                  /* tp_print */\r
-    0,                                                  /* tp_getattr */\r
-    0,                                                  /* tp_setattr */\r
-    0,                                                  /* tp_compare */\r
-    0,                                                  /* tp_repr */\r
-    0,                                                  /* tp_as_number */\r
-    0,                                                  /* tp_as_sequence */\r
-    0,                                                  /* tp_as_mapping */\r
-    0,                                                  /* tp_hash */\r
-    0,                                                  /* tp_call */\r
-    0,                                                  /* tp_str */\r
-    0,                                                  /* tp_getattro */\r
-    0,                                                  /* tp_setattro */\r
-    0,                                                  /* tp_as_buffer */\r
-    Py_TPFLAGS_DEFAULT,                                 /* tp_flags */\r
-    kqueue_queue_doc,                                   /* tp_doc */\r
-    0,                                                  /* tp_traverse */\r
-    0,                                                  /* tp_clear */\r
-    0,                                                  /* tp_richcompare */\r
-    0,                                                  /* tp_weaklistoffset */\r
-    0,                                                  /* tp_iter */\r
-    0,                                                  /* tp_iternext */\r
-    kqueue_queue_methods,                               /* tp_methods */\r
-    0,                                                  /* tp_members */\r
-    kqueue_queue_getsetlist,                            /* tp_getset */\r
-    0,                                                  /* tp_base */\r
-    0,                                                  /* tp_dict */\r
-    0,                                                  /* tp_descr_get */\r
-    0,                                                  /* tp_descr_set */\r
-    0,                                                  /* tp_dictoffset */\r
-    0,                                                  /* tp_init */\r
-    0,                                                  /* tp_alloc */\r
-    kqueue_queue_new,                                   /* tp_new */\r
-    0,                                                  /* tp_free */\r
-};\r
-\r
-#endif /* HAVE_KQUEUE */\r
-/* ************************************************************************ */\r
-\r
-PyDoc_STRVAR(select_doc,\r
-"select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\\r
-\n\\r
-Wait until one or more file descriptors are ready for some kind of I/O.\n\\r
-The first three arguments are sequences of file descriptors to be waited for:\n\\r
-rlist -- wait until ready for reading\n\\r
-wlist -- wait until ready for writing\n\\r
-xlist -- wait for an ``exceptional condition''\n\\r
-If only one kind of condition is required, pass [] for the other lists.\n\\r
-A file descriptor is either a socket or file object, or a small integer\n\\r
-gotten from a fileno() method call on one of those.\n\\r
-\n\\r
-The optional 4th argument specifies a timeout in seconds; it may be\n\\r
-a floating point number to specify fractions of seconds.  If it is absent\n\\r
-or None, the call will never time out.\n\\r
-\n\\r
-The return value is a tuple of three lists corresponding to the first three\n\\r
-arguments; each contains the subset of the corresponding file descriptors\n\\r
-that are ready.\n\\r
-\n\\r
-*** IMPORTANT NOTICE ***\n\\r
-On Windows and OpenVMS, only sockets are supported; on Unix, all file\n\\r
-descriptors can be used.");\r
-\r
-static PyMethodDef select_methods[] = {\r
-    {"select",          select_select,  METH_VARARGS,   select_doc},\r
-#if defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)\r
-    {"poll",            select_poll,    METH_NOARGS,    poll_doc},\r
-#endif /* HAVE_POLL */\r
-    {0,         0},     /* sentinel */\r
-};\r
-\r
-PyDoc_STRVAR(module_doc,\r
-"This module supports asynchronous I/O on multiple file descriptors.\n\\r
-\n\\r
-*** IMPORTANT NOTICE ***\n\\r
-On Windows and OpenVMS, only sockets are supported; on Unix, all file descriptors.");\r
-\r
-PyMODINIT_FUNC\r
-initselect(void)\r
-{\r
-    PyObject *m;\r
-    m = Py_InitModule3("select", select_methods, module_doc);\r
-    if (m == NULL)\r
-        return;\r
-\r
-    SelectError = PyErr_NewException("select.error", NULL, NULL);\r
-    Py_INCREF(SelectError);\r
-    PyModule_AddObject(m, "error", SelectError);\r
-\r
-#ifdef PIPE_BUF\r
-#ifdef HAVE_BROKEN_PIPE_BUF\r
-#undef PIPE_BUF\r
-#define PIPE_BUF 512\r
-#endif\r
-    PyModule_AddIntConstant(m, "PIPE_BUF", PIPE_BUF);\r
-#endif\r
-\r
-#if defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)\r
-#ifdef __APPLE__\r
-    if (select_have_broken_poll()) {\r
-        if (PyObject_DelAttrString(m, "poll") == -1) {\r
-            PyErr_Clear();\r
-        }\r
-    } else {\r
-#else\r
-    {\r
-#endif\r
-        Py_TYPE(&poll_Type) = &PyType_Type;\r
-        PyModule_AddIntConstant(m, "POLLIN", POLLIN);\r
-        PyModule_AddIntConstant(m, "POLLPRI", POLLPRI);\r
-        PyModule_AddIntConstant(m, "POLLOUT", POLLOUT);\r
-        PyModule_AddIntConstant(m, "POLLERR", POLLERR);\r
-        PyModule_AddIntConstant(m, "POLLHUP", POLLHUP);\r
-        PyModule_AddIntConstant(m, "POLLNVAL", POLLNVAL);\r
-\r
-#ifdef POLLRDNORM\r
-        PyModule_AddIntConstant(m, "POLLRDNORM", POLLRDNORM);\r
-#endif\r
-#ifdef POLLRDBAND\r
-        PyModule_AddIntConstant(m, "POLLRDBAND", POLLRDBAND);\r
-#endif\r
-#ifdef POLLWRNORM\r
-        PyModule_AddIntConstant(m, "POLLWRNORM", POLLWRNORM);\r
-#endif\r
-#ifdef POLLWRBAND\r
-        PyModule_AddIntConstant(m, "POLLWRBAND", POLLWRBAND);\r
-#endif\r
-#ifdef POLLMSG\r
-        PyModule_AddIntConstant(m, "POLLMSG", POLLMSG);\r
-#endif\r
-    }\r
-#endif /* HAVE_POLL */\r
-\r
-#ifdef HAVE_EPOLL\r
-    Py_TYPE(&pyEpoll_Type) = &PyType_Type;\r
-    if (PyType_Ready(&pyEpoll_Type) < 0)\r
-        return;\r
-\r
-    Py_INCREF(&pyEpoll_Type);\r
-    PyModule_AddObject(m, "epoll", (PyObject *) &pyEpoll_Type);\r
-\r
-    PyModule_AddIntConstant(m, "EPOLLIN", EPOLLIN);\r
-    PyModule_AddIntConstant(m, "EPOLLOUT", EPOLLOUT);\r
-    PyModule_AddIntConstant(m, "EPOLLPRI", EPOLLPRI);\r
-    PyModule_AddIntConstant(m, "EPOLLERR", EPOLLERR);\r
-    PyModule_AddIntConstant(m, "EPOLLHUP", EPOLLHUP);\r
-    PyModule_AddIntConstant(m, "EPOLLET", EPOLLET);\r
-#ifdef EPOLLONESHOT\r
-    /* Kernel 2.6.2+ */\r
-    PyModule_AddIntConstant(m, "EPOLLONESHOT", EPOLLONESHOT);\r
-#endif\r
-    /* PyModule_AddIntConstant(m, "EPOLL_RDHUP", EPOLLRDHUP); */\r
-    PyModule_AddIntConstant(m, "EPOLLRDNORM", EPOLLRDNORM);\r
-    PyModule_AddIntConstant(m, "EPOLLRDBAND", EPOLLRDBAND);\r
-    PyModule_AddIntConstant(m, "EPOLLWRNORM", EPOLLWRNORM);\r
-    PyModule_AddIntConstant(m, "EPOLLWRBAND", EPOLLWRBAND);\r
-    PyModule_AddIntConstant(m, "EPOLLMSG", EPOLLMSG);\r
-#endif /* HAVE_EPOLL */\r
-\r
-#ifdef HAVE_KQUEUE\r
-    kqueue_event_Type.tp_new = PyType_GenericNew;\r
-    Py_TYPE(&kqueue_event_Type) = &PyType_Type;\r
-    if(PyType_Ready(&kqueue_event_Type) < 0)\r
-        return;\r
-\r
-    Py_INCREF(&kqueue_event_Type);\r
-    PyModule_AddObject(m, "kevent", (PyObject *)&kqueue_event_Type);\r
-\r
-    Py_TYPE(&kqueue_queue_Type) = &PyType_Type;\r
-    if(PyType_Ready(&kqueue_queue_Type) < 0)\r
-        return;\r
-    Py_INCREF(&kqueue_queue_Type);\r
-    PyModule_AddObject(m, "kqueue", (PyObject *)&kqueue_queue_Type);\r
-\r
-    /* event filters */\r
-    PyModule_AddIntConstant(m, "KQ_FILTER_READ", EVFILT_READ);\r
-    PyModule_AddIntConstant(m, "KQ_FILTER_WRITE", EVFILT_WRITE);\r
-    PyModule_AddIntConstant(m, "KQ_FILTER_AIO", EVFILT_AIO);\r
-    PyModule_AddIntConstant(m, "KQ_FILTER_VNODE", EVFILT_VNODE);\r
-    PyModule_AddIntConstant(m, "KQ_FILTER_PROC", EVFILT_PROC);\r
-#ifdef EVFILT_NETDEV\r
-    PyModule_AddIntConstant(m, "KQ_FILTER_NETDEV", EVFILT_NETDEV);\r
-#endif\r
-    PyModule_AddIntConstant(m, "KQ_FILTER_SIGNAL", EVFILT_SIGNAL);\r
-    PyModule_AddIntConstant(m, "KQ_FILTER_TIMER", EVFILT_TIMER);\r
-\r
-    /* event flags */\r
-    PyModule_AddIntConstant(m, "KQ_EV_ADD", EV_ADD);\r
-    PyModule_AddIntConstant(m, "KQ_EV_DELETE", EV_DELETE);\r
-    PyModule_AddIntConstant(m, "KQ_EV_ENABLE", EV_ENABLE);\r
-    PyModule_AddIntConstant(m, "KQ_EV_DISABLE", EV_DISABLE);\r
-    PyModule_AddIntConstant(m, "KQ_EV_ONESHOT", EV_ONESHOT);\r
-    PyModule_AddIntConstant(m, "KQ_EV_CLEAR", EV_CLEAR);\r
-\r
-    PyModule_AddIntConstant(m, "KQ_EV_SYSFLAGS", EV_SYSFLAGS);\r
-    PyModule_AddIntConstant(m, "KQ_EV_FLAG1", EV_FLAG1);\r
-\r
-    PyModule_AddIntConstant(m, "KQ_EV_EOF", EV_EOF);\r
-    PyModule_AddIntConstant(m, "KQ_EV_ERROR", EV_ERROR);\r
-\r
-    /* READ WRITE filter flag */\r
-    PyModule_AddIntConstant(m, "KQ_NOTE_LOWAT", NOTE_LOWAT);\r
-\r
-    /* VNODE filter flags  */\r
-    PyModule_AddIntConstant(m, "KQ_NOTE_DELETE", NOTE_DELETE);\r
-    PyModule_AddIntConstant(m, "KQ_NOTE_WRITE", NOTE_WRITE);\r
-    PyModule_AddIntConstant(m, "KQ_NOTE_EXTEND", NOTE_EXTEND);\r
-    PyModule_AddIntConstant(m, "KQ_NOTE_ATTRIB", NOTE_ATTRIB);\r
-    PyModule_AddIntConstant(m, "KQ_NOTE_LINK", NOTE_LINK);\r
-    PyModule_AddIntConstant(m, "KQ_NOTE_RENAME", NOTE_RENAME);\r
-    PyModule_AddIntConstant(m, "KQ_NOTE_REVOKE", NOTE_REVOKE);\r
-\r
-    /* PROC filter flags  */\r
-    PyModule_AddIntConstant(m, "KQ_NOTE_EXIT", NOTE_EXIT);\r
-    PyModule_AddIntConstant(m, "KQ_NOTE_FORK", NOTE_FORK);\r
-    PyModule_AddIntConstant(m, "KQ_NOTE_EXEC", NOTE_EXEC);\r
-    PyModule_AddIntConstant(m, "KQ_NOTE_PCTRLMASK", NOTE_PCTRLMASK);\r
-    PyModule_AddIntConstant(m, "KQ_NOTE_PDATAMASK", NOTE_PDATAMASK);\r
-\r
-    PyModule_AddIntConstant(m, "KQ_NOTE_TRACK", NOTE_TRACK);\r
-    PyModule_AddIntConstant(m, "KQ_NOTE_CHILD", NOTE_CHILD);\r
-    PyModule_AddIntConstant(m, "KQ_NOTE_TRACKERR", NOTE_TRACKERR);\r
-\r
-    /* NETDEV filter flags */\r
-#ifdef EVFILT_NETDEV\r
-    PyModule_AddIntConstant(m, "KQ_NOTE_LINKUP", NOTE_LINKUP);\r
-    PyModule_AddIntConstant(m, "KQ_NOTE_LINKDOWN", NOTE_LINKDOWN);\r
-    PyModule_AddIntConstant(m, "KQ_NOTE_LINKINV", NOTE_LINKINV);\r
-#endif\r
-\r
-#endif /* HAVE_KQUEUE */\r
-}\r