Commits

mattip committed e2357d1

fix exception, add test that proves the exception cannot be raised without crashing pypy

Comments (0)

Files changed (2)

pypy/rlib/rwin32.py

         for name in """FORMAT_MESSAGE_ALLOCATE_BUFFER FORMAT_MESSAGE_FROM_SYSTEM
                        MAX_PATH
                        WAIT_OBJECT_0 WAIT_TIMEOUT INFINITE
+                       ERROR_INVALID_HANDLE
                     """.split():
             locals()[name] = rffi_platform.ConstantInteger(name)
 
         validate_fd(fd)
         handle = _get_osfhandle(fd)
         if handle == INVALID_HANDLE_VALUE:
-            raise WindowsError(errno.EBADF, "Invalid file handle")
+            raise WindowsError(ERROR_INVALID_HANDLE, "Invalid file handle")
         return handle
 
     def build_winerror_to_errno():

pypy/rlib/test/test_rwin32.py

+from pypy.rlib import rwin32
+from pypy.tool.udir import udir
+
+
+def test_get_osfhandle():
+    fid = open(str(udir.join('validate_test.txt')), 'w')
+    fd = fid.fileno()
+    rwin32.get_osfhandle(fd)
+    fid.close()
+    raises(OSError, rwin32.get_osfhandle, fd)
+    rwin32.get_osfhandle(0)
+
+def test_get_osfhandle_raising():
+    #try to test what kind of exception get_osfhandle raises w/out fd validation
+    skip('Crashes python')
+    fid = open(str(udir.join('validate_test.txt')), 'w')
+    fd = fid.fileno()
+    fid.close()
+    def validate_fd(fd):
+        return 1
+    _validate_fd = rwin32.validate_fd
+    rwin32.validate_fd = validate_fd
+    raises(WindowsError, rwin32.get_osfhandle, fd)
+    rwin32.validate_fd = _validate_fd
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.