Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3.3
Changeset: r75236:bd0bc88bec39
Date: 2015-01-04 22:17 +0100
http://bitbucket.org/pypy/pypy/changeset/bd0bc88bec39/

Log:    The wakeup_fd() file now receives the signal number (instead of \0)
        Write it carefully so that rpython/ can still be shared with
        pypy2.7.

diff --git a/pypy/module/signal/interp_signal.py 
b/pypy/module/signal/interp_signal.py
--- a/pypy/module/signal/interp_signal.py
+++ b/pypy/module/signal/interp_signal.py
@@ -232,7 +232,7 @@
 @jit.dont_look_inside
 @unwrap_spec(fd=int)
 def set_wakeup_fd(space, fd):
-    """Sets the fd to be written to (with '\0') when a signal
+    """Sets the fd to be written to (with the signal number) when a signal
     comes in.  Returns the old fd.  A library can use this to
     wakeup select or poll.  The previous fd is returned.
 
@@ -249,7 +249,7 @@
         except OSError, e:
             if e.errno == errno.EBADF:
                 raise OperationError(space.w_ValueError, space.wrap("invalid 
fd"))
-    old_fd = pypysig_set_wakeup_fd(fd)
+    old_fd = pypysig_set_wakeup_fd(fd, False)
     return space.wrap(intmask(old_fd))
 
 
diff --git a/pypy/module/signal/test/test_signal.py 
b/pypy/module/signal/test/test_signal.py
--- a/pypy/module/signal/test/test_signal.py
+++ b/pypy/module/signal/test/test_signal.py
@@ -214,7 +214,7 @@
             cannot_read()
             posix.kill(posix.getpid(), signal.SIGINT)
             res = posix.read(fd_read, 1)
-            assert res == b'\x00'
+            assert res == bytes([signal.SIGINT])
             cannot_read()
         finally:
             old_wakeup = signal.set_wakeup_fd(old_wakeup)
diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py
--- a/pypy/objspace/fake/objspace.py
+++ b/pypy/objspace/fake/objspace.py
@@ -114,7 +114,7 @@
 
 BUILTIN_TYPES = ['int', 'str', 'float', 'tuple', 'list', 'dict', 'bytes',
                  'unicode', 'complex', 'slice', 'bool', 'text', 'object',
-                 'bytearray', 'memoryview']
+                 'set', 'bytearray', 'memoryview']
 
 class FakeObjSpace(ObjSpace):
     def __init__(self, config=None):
diff --git a/rpython/rlib/rsignal.py b/rpython/rlib/rsignal.py
--- a/rpython/rlib/rsignal.py
+++ b/rpython/rlib/rsignal.py
@@ -73,7 +73,8 @@
 pypysig_default = external('pypysig_default', [rffi.INT], lltype.Void)
 pypysig_setflag = external('pypysig_setflag', [rffi.INT], lltype.Void)
 pypysig_reinstall = external('pypysig_reinstall', [rffi.INT], lltype.Void)
-pypysig_set_wakeup_fd = external('pypysig_set_wakeup_fd', [rffi.INT], rffi.INT)
+pypysig_set_wakeup_fd = external('pypysig_set_wakeup_fd',
+                                 [rffi.INT, rffi.INT], rffi.INT)
 pypysig_poll = external('pypysig_poll', [], rffi.INT, releasegil=False)
 # don't bother releasing the GIL around a call to pypysig_poll: it's
 # pointless and a performance issue
diff --git a/rpython/translator/c/src/signals.c 
b/rpython/translator/c/src/signals.c
--- a/rpython/translator/c/src/signals.c
+++ b/rpython/translator/c/src/signals.c
@@ -36,6 +36,7 @@
 /* pypysig_occurred is only an optimization: it tells if any
    pypysig_flags could be set. */
 static int wakeup_fd = -1;
+static int wakeup_with_nul_byte = 1;
 
 #undef pypysig_getaddr_occurred
 void *pypysig_getaddr_occurred(void)
@@ -92,7 +93,14 @@
 #else
         int res;
 #endif
-        res = write(wakeup_fd, "\0", 1);
+       if (wakeup_with_nul_byte)
+       {
+           res = write(wakeup_fd, "\0", 1);    
+       } else {
+           unsigned char byte = (unsigned char)signum;
+           res = write(wakeup_fd, &byte, 1);   
+       }
+        
         /* the return value is ignored here */
       }
 }
@@ -143,9 +151,10 @@
   return -1;  /* no pending signal */
 }
 
-int pypysig_set_wakeup_fd(int fd)
+int pypysig_set_wakeup_fd(int fd, int with_nul_byte)
 {
   int old_fd = wakeup_fd;
   wakeup_fd = fd;
+  wakeup_with_nul_byte = with_nul_byte;
   return old_fd;
 }
diff --git a/rpython/translator/c/src/signals.h 
b/rpython/translator/c/src/signals.h
--- a/rpython/translator/c/src/signals.h
+++ b/rpython/translator/c/src/signals.h
@@ -15,7 +15,7 @@
 RPY_EXTERN
 void pypysig_reinstall(int signum);
 RPY_EXTERN
-int pypysig_set_wakeup_fd(int fd);
+int pypysig_set_wakeup_fd(int fd, int with_nul_byte);
 
 /* utility to poll for signals that arrived */
 RPY_EXTERN
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to