aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Modules/selectmodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/selectmodule.c')
-rw-r--r--Modules/selectmodule.c101
1 files changed, 61 insertions, 40 deletions
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index b95b2cedc17..0736215972d 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -2,8 +2,6 @@
Under Unix, the file descriptors are small integers.
Under Win32, select only exists for sockets, and sockets may
have any value except INVALID_SOCKET.
- Under BeOS, we suffer the same dichotomy as Win32; sockets can be anything
- >= 0.
*/
#include "Python.h"
@@ -47,12 +45,11 @@ extern void bzero(void *, int);
#endif
#ifdef MS_WINDOWS
-# include <winsock2.h>
+# define WIN32_LEAN_AND_MEAN
+# include <winsock.h>
#else
# define SOCKET int
-# ifdef __BEOS__
-# include <net/socket.h>
-# elif defined(__VMS)
+# if defined(__VMS)
# include <socket.h>
# endif
#endif
@@ -84,9 +81,9 @@ reap_obj(pylist fd2obj[FD_SETSIZE + 1])
static int
seq2set(PyObject *seq, fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
{
- int i;
int max = -1;
int index = 0;
+ Py_ssize_t i;
PyObject* fast_seq = NULL;
PyObject* o = NULL;
@@ -102,7 +99,7 @@ seq2set(PyObject *seq, fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
/* any intervening fileno() calls could decr this refcnt */
if (!(o = PySequence_Fast_GET_ITEM(fast_seq, i)))
- return -1;
+ goto finally;
Py_INCREF(o);
v = PyObject_AsFileDescriptor( o );
@@ -343,8 +340,8 @@ update_ufd_array(pollObject *self)
i = pos = 0;
while (PyDict_Next(self->dict, &pos, &key, &value)) {
- self->ufds[i].fd = PyInt_AsLong(key);
- self->ufds[i].events = (short)PyInt_AsLong(value);
+ self->ufds[i].fd = PyLong_AsLong(key);
+ self->ufds[i].events = (short)PyLong_AsLong(value);
i++;
}
self->ufd_uptodate = 1;
@@ -374,10 +371,10 @@ poll_register(pollObject *self, PyObject *args)
/* Add entry to the internal dictionary: the key is the
file descriptor, and the value is the event mask. */
- key = PyInt_FromLong(fd);
+ key = PyLong_FromLong(fd);
if (key == NULL)
return NULL;
- value = PyInt_FromLong(events);
+ value = PyLong_FromLong(events);
if (value == NULL) {
Py_DECREF(key);
return NULL;
@@ -416,15 +413,16 @@ poll_modify(pollObject *self, PyObject *args)
if (fd == -1) return NULL;
/* Modify registered fd */
- key = PyInt_FromLong(fd);
+ key = PyLong_FromLong(fd);
if (key == NULL)
return NULL;
if (PyDict_GetItem(self->dict, key) == NULL) {
errno = ENOENT;
PyErr_SetFromErrno(PyExc_IOError);
+ Py_DECREF(key);
return NULL;
}
- value = PyInt_FromLong(events);
+ value = PyLong_FromLong(events);
if (value == NULL) {
Py_DECREF(key);
return NULL;
@@ -457,7 +455,7 @@ poll_unregister(pollObject *self, PyObject *o)
return NULL;
/* Check whether the fd is already in the array */
- key = PyInt_FromLong(fd);
+ key = PyLong_FromLong(fd);
if (key == NULL)
return NULL;
@@ -500,10 +498,10 @@ poll_poll(pollObject *self, PyObject *args)
return NULL;
}
else {
- tout = PyNumber_Int(tout);
+ tout = PyNumber_Long(tout);
if (!tout)
return NULL;
- timeout = PyInt_AsLong(tout);
+ timeout = PyLong_AsLong(tout);
Py_DECREF(tout);
if (timeout == -1 && PyErr_Occurred())
return NULL;
@@ -541,7 +539,7 @@ poll_poll(pollObject *self, PyObject *args)
value = PyTuple_New(2);
if (value == NULL)
goto error;
- num = PyInt_FromLong(self->ufds[i].fd);
+ num = PyLong_FromLong(self->ufds[i].fd);
if (num == NULL) {
Py_DECREF(value);
goto error;
@@ -552,7 +550,7 @@ poll_poll(pollObject *self, PyObject *args)
is a 16-bit short, and IBM assigned POLLNVAL
to be 0x8000, so the conversion to int results
in a negative number. See SF bug #923315. */
- num = PyInt_FromLong(self->ufds[i].revents & 0xffff);
+ num = PyLong_FromLong(self->ufds[i].revents & 0xffff);
if (num == NULL) {
Py_DECREF(value);
goto error;
@@ -612,12 +610,6 @@ poll_dealloc(pollObject *self)
PyObject_Del(self);
}
-static PyObject *
-poll_getattr(pollObject *self, char *name)
-{
- return Py_FindMethod(poll_methods, (PyObject *)self, name);
-}
-
static PyTypeObject poll_Type = {
/* The ob_type field must be initialized in the module init function
* to be portable to Windows without using C++. */
@@ -628,14 +620,28 @@ static PyTypeObject poll_Type = {
/* methods */
(destructor)poll_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- (getattrfunc)poll_getattr, /*tp_getattr*/
+ 0, /*tp_getattr*/
0, /*tp_setattr*/
- 0, /*tp_compare*/
+ 0, /*tp_reserved*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT, /*tp_flags*/
+ 0, /*tp_doc*/
+ 0, /*tp_traverse*/
+ 0, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ poll_methods, /*tp_methods*/
};
PyDoc_STRVAR(poll_doc,
@@ -811,7 +817,7 @@ pyepoll_fileno(pyEpoll_Object *self)
{
if (self->epfd < 0)
return pyepoll_err_closed();
- return PyInt_FromLong(self->epfd);
+ return PyLong_FromLong(self->epfd);
}
PyDoc_STRVAR(pyepoll_fileno_doc,
@@ -1073,7 +1079,7 @@ static PyTypeObject pyEpoll_Type = {
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
- 0, /* tp_compare */
+ 0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
@@ -1227,7 +1233,7 @@ kqueue_event_repr(kqueue_event_Object *s)
"data=0x%zd udata=%p>",
(size_t)(s->e.ident), s->e.filter, s->e.flags,
s->e.fflags, (Py_ssize_t)(s->e.data), s->e.udata);
- return PyString_FromString(buf);
+ return PyUnicode_FromString(buf);
}
static int
@@ -1317,7 +1323,7 @@ static PyTypeObject kqueue_event_Type = {
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
- 0, /* tp_compare */
+ 0, /* tp_reserved */
(reprfunc)kqueue_event_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
@@ -1450,7 +1456,7 @@ kqueue_queue_fileno(kqueue_queue_Object *self)
{
if (self->kqfd < 0)
return kqueue_queue_err_closed();
- return PyInt_FromLong(self->kqfd);
+ return PyLong_FromLong(self->kqfd);
}
PyDoc_STRVAR(kqueue_queue_fileno_doc,
@@ -1671,7 +1677,7 @@ static PyTypeObject kqueue_queue_Type = {
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
- 0, /* tp_compare */
+ 0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
@@ -1745,13 +1751,26 @@ PyDoc_STRVAR(module_doc,
*** IMPORTANT NOTICE ***\n\
On Windows and OpenVMS, only sockets are supported; on Unix, all file descriptors.");
+
+static struct PyModuleDef selectmodule = {
+ PyModuleDef_HEAD_INIT,
+ "select",
+ module_doc,
+ -1,
+ select_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initselect(void)
+PyInit_select(void)
{
PyObject *m;
- m = Py_InitModule3("select", select_methods, module_doc);
+ m = PyModule_Create(&selectmodule);
if (m == NULL)
- return;
+ return NULL;
SelectError = PyErr_NewException("select.error", NULL, NULL);
Py_INCREF(SelectError);
@@ -1775,7 +1794,8 @@ initselect(void)
#else
{
#endif
- Py_TYPE(&poll_Type) = &PyType_Type;
+ if (PyType_Ready(&poll_Type) < 0)
+ return NULL;
PyModule_AddIntConstant(m, "POLLIN", POLLIN);
PyModule_AddIntConstant(m, "POLLPRI", POLLPRI);
PyModule_AddIntConstant(m, "POLLOUT", POLLOUT);
@@ -1804,7 +1824,7 @@ initselect(void)
#ifdef HAVE_EPOLL
Py_TYPE(&pyEpoll_Type) = &PyType_Type;
if (PyType_Ready(&pyEpoll_Type) < 0)
- return;
+ return NULL;
Py_INCREF(&pyEpoll_Type);
PyModule_AddObject(m, "epoll", (PyObject *) &pyEpoll_Type);
@@ -1831,14 +1851,14 @@ initselect(void)
kqueue_event_Type.tp_new = PyType_GenericNew;
Py_TYPE(&kqueue_event_Type) = &PyType_Type;
if(PyType_Ready(&kqueue_event_Type) < 0)
- return;
+ return NULL;
Py_INCREF(&kqueue_event_Type);
PyModule_AddObject(m, "kevent", (PyObject *)&kqueue_event_Type);
Py_TYPE(&kqueue_queue_Type) = &PyType_Type;
if(PyType_Ready(&kqueue_queue_Type) < 0)
- return;
+ return NULL;
Py_INCREF(&kqueue_queue_Type);
PyModule_AddObject(m, "kqueue", (PyObject *)&kqueue_queue_Type);
@@ -1899,4 +1919,5 @@ initselect(void)
#endif
#endif /* HAVE_KQUEUE */
+ return m;
}