[pypy-svn] r77817 - in pypy/branch/fast-forward/pypy: module/_multiprocessing module/_multiprocessing/test rlib

afa at codespeak.net afa at codespeak.net
Tue Oct 12 11:27:47 CEST 2010


Author: afa
Date: Tue Oct 12 11:27:43 2010
New Revision: 77817

Modified:
   pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_connection.py
   pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_semaphore.py
   pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_win32.py
   pypy/branch/fast-forward/pypy/module/_multiprocessing/test/test_connection.py
   pypy/branch/fast-forward/pypy/rlib/rpoll.py
Log:
Improve tests, and fix.


Modified: pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_connection.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_connection.py	(original)
+++ pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_connection.py	Tue Oct 12 11:27:43 2010
@@ -300,12 +300,12 @@
             remaining -= count
             buffer = rffi.ptradd(buffer, count)
 
-    def do_poll(self, space):
+    def do_poll(self, space, timeout):
         # XXX Won't work on Windows
 
         from pypy.rlib import rpoll
         # just verify the fd
-        if self.fd < 0 or self.fd > FD_SETSIZE:
+        if self.fd < 0 or self.fd > rpoll.FD_SETSIZE:
             raise OperationError(space.w_IOError, space.wrap(
                 "handle out of range in select()"))
 
@@ -433,7 +433,7 @@
 
     def do_poll(self, space, timeout):
         from pypy.module._multiprocessing.interp_win32 import (
-            _PeekNamedPipe)
+            _PeekNamedPipe, _GetTickCount, _Sleep)
         from pypy.rlib import rwin32
         from pypy.interpreter.error import wrap_windowserror
         bytes_ptr = lltype.malloc(rffi.CArrayPtr(rwin32.DWORD).TO, 1,
@@ -455,11 +455,15 @@
         if not block:
             # XXX does not check for overflow
             deadline = _GetTickCount() + int(1000 * timeout + 0.5)
+        else:
+            deadline = 0
 
         _Sleep(0)
 
         delay = 1
         while True:
+            bytes_ptr = lltype.malloc(rffi.CArrayPtr(rwin32.DWORD).TO, 1,
+                                     flavor='raw')
             try:
                 if not _PeekNamedPipe(self.handle, rffi.NULL, 0,
                                       lltype.nullptr(rwin32.LPDWORD.TO),
@@ -474,17 +478,18 @@
                 return True
 
             if not block:
-                diff = deadline - _GetTickCount()
-                if diff < 0:
+                now = _GetTickCount()
+                if now > deadline:
                     return False
-                if delay > difference:
-                    delay = difference
+                diff = deadline - now
+                if delay > diff:
+                    delay = diff
             else:
                 delay += 1
 
             if delay >= 20:
                 delay = 20
-            Sleep(delay)
+            _Sleep(delay)
 
             # check for signals
             # PyErr_CheckSignals()

Modified: pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_semaphore.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_semaphore.py	(original)
+++ pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_semaphore.py	Tue Oct 12 11:27:43 2010
@@ -15,7 +15,8 @@
 if sys.platform == 'win32':
     from pypy.rlib import rwin32
     from pypy.interpreter.error import wrap_windowserror
-    from pypy.module._multiprocessing.interp_win32 import handle_w
+    from pypy.module._multiprocessing.interp_win32 import (
+        handle_w, _GetTickCount)
 
     SEM_VALUE_MAX = sys.maxint
 
@@ -25,8 +26,6 @@
     _ReleaseSemaphore = rwin32.winexternal(
         'ReleaseSemaphore', [rwin32.HANDLE, rffi.LONG, rffi.LONGP],
         rwin32.BOOL)
-    _GetTickCount = rwin32.winexternal(
-        'GetTickCount', [], rwin32.DWORD)
 
     CtrlHandler_type = lltype.Ptr(lltype.FuncType([], rwin32.BOOL))
     _CreateEvent = rwin32.winexternal(
@@ -68,7 +67,7 @@
 
     def ProcessingCtrlHandler():
         _SetEvent(globalState.sigint_event)
-        return False
+        return 0
 
     class GlobalState:
         def __init__(self):

Modified: pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_win32.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_win32.py	(original)
+++ pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_win32.py	Tue Oct 12 11:27:43 2010
@@ -82,6 +82,12 @@
 _ExitProcess = rwin32.winexternal(
     'ExitProcess', [rffi.UINT], lltype.Void)
 
+_GetTickCount = rwin32.winexternal(
+    'GetTickCount', [], rwin32.DWORD)
+
+_Sleep = rwin32.winexternal(
+    'Sleep', [rwin32.DWORD], lltype.Void)
+
 def CloseHandle(space, w_handle):
     handle = handle_w(space, w_handle)
     if not rwin32.CloseHandle(handle):
@@ -90,6 +96,9 @@
 def GetLastError(space):
     return space.wrap(rwin32.GetLastError())
 
+# __________________________________________________________
+# functions for the "win32" namespace
+
 @unwrap_spec(ObjSpace, str, r_uint, r_uint, r_uint, r_uint, r_uint, r_uint, W_Root)
 def CreateNamedPipe(space, name, openmode, pipemode, maxinstances,
                     outputsize, inputsize, timeout, w_security):

Modified: pypy/branch/fast-forward/pypy/module/_multiprocessing/test/test_connection.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_multiprocessing/test/test_connection.py	(original)
+++ pypy/branch/fast-forward/pypy/module/_multiprocessing/test/test_connection.py	Tue Oct 12 11:27:43 2010
@@ -19,11 +19,13 @@
     def test_poll(self):
         rhandle, whandle = self.make_pair()
 
-        assert rhandle.poll(0) == False
+        assert rhandle.poll() == False
+        assert rhandle.poll(1) == False
         whandle.send(1)
-        assert rhandle.poll(0) == True
+        assert rhandle.poll() == True
+        assert rhandle.poll(None) == True
         assert rhandle.recv() == 1
-        assert rhandle.poll(0) == False
+        assert rhandle.poll() == False
 
 class AppTestWinpipeConnection(BaseConnectionTest):
     def setup_class(cls):
@@ -64,4 +66,4 @@
 
     if sys.platform == "win32":
         def test_poll(self):
-            skip("poll does not accept file handles on Windows")
+            skip("poll() does not accept file handles on Windows")

Modified: pypy/branch/fast-forward/pypy/rlib/rpoll.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rlib/rpoll.py	(original)
+++ pypy/branch/fast-forward/pypy/rlib/rpoll.py	Tue Oct 12 11:27:43 2010
@@ -15,7 +15,8 @@
 # events
 #
 eventnames = '''POLLIN POLLPRI POLLOUT POLLERR POLLHUP POLLNVAL
-                POLLRDNORM POLLRDBAND POLLWRNORM POLLWEBAND POLLMSG'''.split()
+                POLLRDNORM POLLRDBAND POLLWRNORM POLLWEBAND POLLMSG
+                FD_SETSIZE'''.split()
 
 eventnames = [name for name in eventnames
                    if _c.constants.get(name) is not None]



More information about the Pypy-commit mailing list