[pypy-svn] r78647 - in pypy/branch/fast-forward/pypy/module/_multiprocessing: . test

afa at codespeak.net afa at codespeak.net
Tue Nov 2 19:15:10 CET 2010


Author: afa
Date: Tue Nov  2 19:15:09 2010
New Revision: 78647

Modified:
   pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_connection.py
   pypy/branch/fast-forward/pypy/module/_multiprocessing/test/test_connection.py
Log:
Test and fix for the size of receiving buffer.


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 Nov  2 19:15:09 2010
@@ -42,7 +42,7 @@
         return False
     def do_send_string(self, space, buffer, offset, size):
         raise NotImplementedError
-    def do_recv_string(self, space, maxlength):
+    def do_recv_string(self, space, buflength, maxlength):
         raise NotImplementedError
 
     def close(self):
@@ -93,7 +93,8 @@
             raise OperationError(space.w_ValueError,
                                  space.wrap("maxlength < 0"))
 
-        res, newbuf = self.do_recv_string(space, maxlength)
+        res, newbuf = self.do_recv_string(
+            space, self.BUFFER_SIZE, maxlength)
         res = intmask(res) # XXX why?
         try:
             if newbuf:
@@ -109,7 +110,8 @@
         rwbuffer = space.rwbuffer_w(w_buffer)
         length = rwbuffer.getlength()
 
-        res, newbuf = self.do_recv_string(space, length - offset)
+        res, newbuf = self.do_recv_string(
+            space, length - offset, PY_SSIZE_T_MAX)
         res = intmask(res) # XXX why?
         try:
             if newbuf:
@@ -141,7 +143,8 @@
     def recv(self, space):
         self._check_readable(space)
 
-        res, newbuf = self.do_recv_string(space, PY_SSIZE_T_MAX)
+        res, newbuf = self.do_recv_string(
+            space, self.BUFFER_SIZE, PY_SSIZE_T_MAX)
         res = intmask(res) # XXX why?
         try:
             if newbuf:
@@ -226,7 +229,7 @@
         finally:
             lltype.free(message, flavor='raw')
 
-    def do_recv_string(self, space, maxlength):
+    def do_recv_string(self, space, buflength, maxlength):
         length_ptr = lltype.malloc(rffi.CArrayPtr(rffi.UINT).TO, 1,
                                    flavor='raw')
         self._recvall(space, rffi.cast(rffi.CCHARP, length_ptr), 4)
@@ -238,7 +241,7 @@
             raise OperationError(space.w_IOError, space.wrap(
                 "bad message length"))
 
-        if length <= self.BUFFER_SIZE:
+        if length <= buflength:
             self._recvall(space, self.buffer, length)
             return length, lltype.nullptr(rffi.CCHARP.TO)
         else:
@@ -359,7 +362,7 @@
             rffi.free_charp(charp)
             lltype.free(written_ptr, flavor='raw')
 
-    def do_recv_string(self, space, maxlength):
+    def do_recv_string(self, space, buflength, maxlength):
         from pypy.module._multiprocessing.interp_win32 import (
             _ReadFile, _PeekNamedPipe, ERROR_BROKEN_PIPE, ERROR_MORE_DATA)
         from pypy.rlib import rwin32
@@ -371,7 +374,7 @@
                                  flavor='raw')
         try:
             result = _ReadFile(self.handle,
-                               self.buffer, min(self.BUFFER_SIZE, maxlength),
+                               self.buffer, min(self.BUFFER_SIZE, buflength),
                                read_ptr, rffi.NULL)
             if result:
                 return read_ptr[0], lltype.nullptr(rffi.CCHARP.TO)
@@ -394,8 +397,8 @@
                 self.flags &= ~READABLE
                 if self.flags == 0:
                     self.close()
-                    raise OperationError(space.w_IOError, space.wrap(
-                        "bad message length"))
+                raise OperationError(space.w_IOError, space.wrap(
+                    "bad message length"))
 
             newbuf = lltype.malloc(rffi.CCHARP.TO, length + 1, flavor='raw')
             for i in range(read_ptr[0]):

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 Nov  2 19:15:09 2010
@@ -53,6 +53,16 @@
         assert rhandle.recv() == 1
         assert rhandle.poll() == False
 
+    def test_read_into(self):
+        import array, multiprocessing
+        rhandle, whandle = self.make_pair()
+
+        obj = [1, 2.0, "hello"]
+        whandle.send(obj)
+        buffer = array.array('b', [0]*10)
+        raises(multiprocessing.BufferTooShort, rhandle.recv_bytes_into, buffer)
+        assert rhandle.readable
+
 class AppTestWinpipeConnection(BaseConnectionTest):
     def setup_class(cls):
         if sys.platform != "win32":



More information about the Pypy-commit mailing list