boost/ocaml/python - all NON-WORKING at the moment.
[fedora-mingw.git] / python / python-2.5.2-set_wakeup_fd4.patch
1 diff -ru Python-2.5.2-orig/Modules/signalmodule.c Python-2.5.2/Modules/signalmodule.c
2 --- Python-2.5.2-orig/Modules/signalmodule.c    2007-12-10 18:03:55.000000000 -0500
3 +++ Python-2.5.2/Modules/signalmodule.c 2008-09-24 17:32:45.000000000 -0400
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 @@
14          PyObject *func;
15  } Handlers[NSIG];
16  
17 +static int wakeup_fd = -1;
18 +
19  /* Speed up sigcheck() when none tripped */
20  static volatile sig_atomic_t is_tripped = 0;
21  
22 @@ -113,6 +117,7 @@
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 @@ -128,6 +133,8 @@
31                     cleared in PyErr_CheckSignals() before .tripped. */
32                 is_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 @@ -267,6 +274,39 @@
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 @@ -274,6 +314,7 @@
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},