Commits

Philip Jenvey committed 300bcb7 Merge

Merged in andrewsmedina/numpypy/stdlib-2.7.4-poll-fix (pull request #182)

fixed support for select.poll in stdlib 2.7.4

Comments (0)

Files changed (2)

pypy/module/select/interp_select.py

 
     @unwrap_spec(events=int)
     def register(self, space, w_fd, events=defaultevents):
+        if events > 32767:
+            msg = "signed short integer is greater than maximum"
+            raise OperationError(space.w_OverflowError, space.wrap(msg))
         fd = space.c_filedescriptor_w(w_fd)
         self.fddict[fd] = events
 
                 raise OperationError(space.w_ValueError,
                                      space.wrap("math range error"))
 
+        if timeout > 2147483647:
+            msg = "Python int too large to convert to C int"
+            raise OperationError(space.w_OverflowError, space.wrap(msg))
+
         try:
             retval = rpoll.poll(self.fddict, timeout)
         except rpoll.PollError, e:

pypy/module/select/test/test_select.py

             readend.close()
             writeend.close()
 
+    def test_poll_int_overflow(self):
+        import select
+
+        pollster = select.poll()
+        pollster.register(1)
+
+        raises(OverflowError, pollster.poll, 1L << 64)
+
+        pollster = select.poll()
+        raises(OverflowError, pollster.register, 0, 32768) # SHRT_MAX + 1
+        raises(OverflowError, pollster.register, 0, 65535) # USHRT_MAX + 1
+        raises(OverflowError, pollster.poll, 2147483648) # INT_MAX +  1
+        raises(OverflowError, pollster.poll, 4294967296) # UINT_MAX + 1
+
 
 class AppTestSelectWithPipes(_AppTestSelect):
     "Use a pipe to get pairs of file descriptors"