Fix generic changelog entry.
[fedora-mingw.git] / python / python2.6-set_wakeup_fd4.patch
1 diff -rup Python-2.5.1-orig/Modules/signalmodule.c Python-2.5.1/Modules/signalmodule.c
2 --- Python-2.5.1-orig/Modules/signalmodule.c    2006-01-19 01:09:39.000000000 -0500
3 +++ Python-2.5.1/Modules/signalmodule.c 2008-01-07 12:32:00.000000000 -0500
4 @@ -12,6 +12,8 @@
5  
6  #include <signal.h>
7  
8 +#include <sys/stat.h>
9 +
10  #ifndef SIG_ERR
11  #define SIG_ERR ((PyOS_sighandler_t)(-1))
12  #endif
13 @@ -75,6 +77,8 @@ static struct {
14          PyObject *func;
15  } Handlers[NSIG];
16  
17 +static int wakeup_fd = -1;
18 +
19  static int is_tripped = 0; /* Speed up sigcheck() when none tripped */
20  
21  static PyObject *DefaultHandler;
22 @@ -112,6 +116,7 @@ checksignals_witharg(void * unused)
23  static void
24  signal_handler(int sig_num)
25  {
26 +       const char dummy_byte = '\0';
27  #ifdef WITH_THREAD
28  #ifdef WITH_PTH
29         if (PyThread_get_thread_ident() != main_thread) {
30 @@ -125,6 +130,8 @@ signal_handler(int sig_num)
31                 is_tripped++;
32                 Handlers[sig_num].tripped = 1;
33                 Py_AddPendingCall(checksignals_witharg, NULL);
34 +               if (wakeup_fd != -1)
35 +                       write(wakeup_fd, &dummy_byte, 1);
36  #ifdef WITH_THREAD
37         }
38  #endif
39 @@ -264,6 +271,39 @@ None -- if an unknown handler is in effe
40  anything else -- the callable Python object used as a handler");
41  
42  
43 +static PyObject *
44 +signal_set_wakeup_fd(PyObject *self, PyObject *args)
45 +{
46 +       struct stat buf;
47 +       int fd, old_fd;
48 +       if (!PyArg_ParseTuple(args, "i:set_wakeup_fd", &fd))
49 +               return NULL;
50 +#ifdef WITH_THREAD
51 +       if (PyThread_get_thread_ident() != main_thread) {
52 +               PyErr_SetString(PyExc_ValueError,
53 +                               "set_wakeup_fd only works in main thread");
54 +               return NULL;
55 +       }
56 +#endif
57 +       if (fd != -1 && fstat(fd, &buf) != 0) {
58 +               PyErr_SetString(PyExc_ValueError, "invalid fd");
59 +               return NULL;
60 +       }
61 +       old_fd = wakeup_fd;
62 +       wakeup_fd = fd;
63 +       return PyLong_FromLong(old_fd);
64 +}
65 +
66 +PyDoc_STRVAR(set_wakeup_fd_doc,
67 +"set_wakeup_fd(fd) -> fd\n\
68 +\n\
69 +Sets the fd to be written to (with '\\0') when a signal\n\
70 +comes in.  A library can use this to wakeup select or poll.\n\
71 +The previous fd is returned.\n\
72 +\n\
73 +The fd must be non-blocking.");
74 +
75 +
76  /* List of functions defined in the module */
77  static PyMethodDef signal_methods[] = {
78  #ifdef HAVE_ALARM
79 @@ -271,6 +311,7 @@ static PyMethodDef signal_methods[] = {
80  #endif
81         {"signal",              signal_signal, METH_VARARGS, signal_doc},
82         {"getsignal",           signal_getsignal, METH_VARARGS, getsignal_doc},
83 +       {"set_wakeup_fd",       signal_set_wakeup_fd, METH_VARARGS, set_wakeup_fd_doc},
84  #ifdef HAVE_PAUSE
85         {"pause",               (PyCFunction)signal_pause,
86          METH_NOARGS,pause_doc},