summaryrefslogtreecommitdiff
path: root/Modules/selectmodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/selectmodule.c')
-rw-r--r--Modules/selectmodule.c66
1 files changed, 52 insertions, 14 deletions
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 022c099ae3..5192ce74cf 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -47,7 +47,7 @@ extern void bzero(void *, int);
#endif
#ifdef MS_WINDOWS
-# include <winsock.h>
+# include <winsock2.h>
#else
# define SOCKET int
# ifdef __BEOS__
@@ -94,7 +94,7 @@ seq2set(PyObject *seq, fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
fd2obj[0].obj = (PyObject*)0; /* set list to zero size */
FD_ZERO(set);
- fast_seq=PySequence_Fast(seq, "arguments 1-3 must be sequences");
+ fast_seq = PySequence_Fast(seq, "arguments 1-3 must be sequences");
if (!fast_seq)
return -1;
@@ -1185,6 +1185,30 @@ static PyTypeObject kqueue_queue_Type;
#define kqueue_queue_Check(op) (PyObject_TypeCheck((op), &kqueue_queue_Type))
+#if (SIZEOF_UINTPTR_T != SIZEOF_VOID_P)
+# error uintptr_t does not match void *!
+#elif (SIZEOF_UINTPTR_T == SIZEOF_LONG_LONG)
+# define T_UINTPTRT T_ULONGLONG
+# define T_INTPTRT T_LONGLONG
+# define PyLong_AsUintptr_t PyLong_AsUnsignedLongLong
+# define UINTPTRT_FMT_UNIT "K"
+# define INTPTRT_FMT_UNIT "L"
+#elif (SIZEOF_UINTPTR_T == SIZEOF_LONG)
+# define T_UINTPTRT T_ULONG
+# define T_INTPTRT T_LONG
+# define PyLong_AsUintptr_t PyLong_AsUnsignedLong
+# define UINTPTRT_FMT_UNIT "k"
+# define INTPTRT_FMT_UNIT "l"
+#elif (SIZEOF_UINTPTR_T == SIZEOF_INT)
+# define T_UINTPTRT T_UINT
+# define T_INTPTRT T_INT
+# define PyLong_AsUintptr_t PyLong_AsUnsignedLong
+# define UINTPTRT_FMT_UNIT "I"
+# define INTPTRT_FMT_UNIT "i"
+#else
+# error uintptr_t does not match int, long, or long long!
+#endif
+
/* Unfortunately, we can't store python objects in udata, because
* kevents in the kernel can be removed without warning, which would
* forever lose the refcount on the object stored with it.
@@ -1192,12 +1216,12 @@ static PyTypeObject kqueue_queue_Type;
#define KQ_OFF(x) offsetof(kqueue_event_Object, x)
static struct PyMemberDef kqueue_event_members[] = {
- {"ident", T_UINT, KQ_OFF(e.ident)},
+ {"ident", T_UINTPTRT, KQ_OFF(e.ident)},
{"filter", T_SHORT, KQ_OFF(e.filter)},
{"flags", T_USHORT, KQ_OFF(e.flags)},
{"fflags", T_UINT, KQ_OFF(e.fflags)},
- {"data", T_INT, KQ_OFF(e.data)},
- {"udata", T_INT, KQ_OFF(e.udata)},
+ {"data", T_INTPTRT, KQ_OFF(e.data)},
+ {"udata", T_UINTPTRT, KQ_OFF(e.udata)},
{NULL} /* Sentinel */
};
#undef KQ_OFF
@@ -1209,10 +1233,10 @@ kqueue_event_repr(kqueue_event_Object *s)
char buf[1024];
PyOS_snprintf(
buf, sizeof(buf),
- "<select.kevent ident=%lu filter=%d flags=0x%x fflags=0x%x "
- "data=0x%lx udata=%p>",
- (unsigned long)(s->e.ident), s->e.filter, s->e.flags,
- s->e.fflags, (long)(s->e.data), s->e.udata);
+ "<select.kevent ident=%zu filter=%d flags=0x%x fflags=0x%x "
+ "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);
}
@@ -1222,17 +1246,23 @@ kqueue_event_init(kqueue_event_Object *self, PyObject *args, PyObject *kwds)
PyObject *pfd;
static char *kwlist[] = {"ident", "filter", "flags", "fflags",
"data", "udata", NULL};
+ static char *fmt = "O|hhi" INTPTRT_FMT_UNIT UINTPTRT_FMT_UNIT ":kevent";
EV_SET(&(self->e), 0, EVFILT_READ, EV_ADD, 0, 0, 0); /* defaults */
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|hhiii:kevent", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, fmt, kwlist,
&pfd, &(self->e.filter), &(self->e.flags),
&(self->e.fflags), &(self->e.data), &(self->e.udata))) {
return -1;
}
- self->e.ident = PyObject_AsFileDescriptor(pfd);
- if (self->e.ident == -1) {
+ if (PyLong_Check(pfd)) {
+ self->e.ident = PyLong_AsUintptr_t(pfd);
+ }
+ else {
+ self->e.ident = PyObject_AsFileDescriptor(pfd);
+ }
+ if (PyErr_Occurred()) {
return -1;
}
return 0;
@@ -1242,7 +1272,7 @@ static PyObject *
kqueue_event_richcompare(kqueue_event_Object *s, kqueue_event_Object *o,
int op)
{
- int result = 0;
+ Py_intptr_t result = 0;
if (!kqueue_event_Check(o)) {
if (op == Py_EQ || op == Py_NE) {
@@ -1285,7 +1315,7 @@ kqueue_event_richcompare(kqueue_event_Object *s, kqueue_event_Object *o,
result = (result > 0);
break;
}
- return PyBool_FromLong(result);
+ return PyBool_FromLong((long)result);
}
static PyTypeObject kqueue_event_Type = {
@@ -1737,6 +1767,14 @@ initselect(void)
Py_INCREF(SelectError);
PyModule_AddObject(m, "error", SelectError);
+#ifdef PIPE_BUF
+#ifdef HAVE_BROKEN_PIPE_BUF
+#undef PIPE_BUF
+#define PIPE_BUF 512
+#endif
+ PyModule_AddIntConstant(m, "PIPE_BUF", PIPE_BUF);
+#endif
+
#if defined(HAVE_POLL)
#ifdef __APPLE__
if (select_have_broken_poll()) {