Author: Matti Picus <matti.pi...@gmail.com>
Branch: win32-cleanup2
Changeset: r54489:e2357d1f1715
Date: 2012-04-18 00:34 +0300
http://bitbucket.org/pypy/pypy/changeset/e2357d1f1715/

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

diff --git a/pypy/rlib/rwin32.py b/pypy/rlib/rwin32.py
--- a/pypy/rlib/rwin32.py
+++ b/pypy/rlib/rwin32.py
@@ -79,6 +79,7 @@
         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)
 
@@ -131,7 +132,7 @@
         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():
diff --git a/pypy/rlib/test/test_rwin32.py b/pypy/rlib/test/test_rwin32.py
new file mode 100644
--- /dev/null
+++ b/pypy/rlib/test/test_rwin32.py
@@ -0,0 +1,24 @@
+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
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to