]> granicus.if.org Git - python/commitdiff
Issue #16169: Fix ctypes.WinError()'s confusion between errno and winerror
authorRichard Oudkerk <shibturn@gmail.com>
Tue, 9 Oct 2012 12:28:10 +0000 (13:28 +0100)
committerRichard Oudkerk <shibturn@gmail.com>
Tue, 9 Oct 2012 12:28:10 +0000 (13:28 +0100)
Lib/ctypes/__init__.py
Lib/ctypes/test/test_win32.py
Misc/NEWS

index f0bd66a17c86c92e1983d06b8d4fde4643c05ac1..c92e130976bc88bb308604e105fb02db01ae6b63 100644 (file)
@@ -456,7 +456,7 @@ if _os.name in ("nt", "ce"):
             code = GetLastError()
         if descr is None:
             descr = FormatError(code).strip()
-        return WindowsError(code, descr)
+        return WindowsError(None, descr, None, code)
 
 if sizeof(c_uint) == sizeof(c_void_p):
     c_size_t = c_uint
index 2534a748cd95562a8fc56635173d25fa73d77110..128914ea2daf1c2620287f9b96b9a00b91d482b3 100644 (file)
@@ -67,6 +67,28 @@ if sys.platform == "win32":
             self.assertEqual(ex.text, "text")
             self.assertEqual(ex.details, ("details",))
 
+    class TestWinError(unittest.TestCase):
+        def test_winerror(self):
+            # see Issue 16169
+            import errno
+            ERROR_INVALID_PARAMETER = 87
+            msg = FormatError(ERROR_INVALID_PARAMETER).strip()
+            args = (errno.EINVAL, msg, None, ERROR_INVALID_PARAMETER)
+
+            e = WinError(ERROR_INVALID_PARAMETER)
+            self.assertEqual(e.args, args)
+            self.assertEqual(e.errno, errno.EINVAL)
+            self.assertEqual(e.winerror, ERROR_INVALID_PARAMETER)
+
+            windll.kernel32.SetLastError(ERROR_INVALID_PARAMETER)
+            try:
+                raise WinError()
+            except OSError as exc:
+                e = exc
+            self.assertEqual(e.args, args)
+            self.assertEqual(e.errno, errno.EINVAL)
+            self.assertEqual(e.winerror, ERROR_INVALID_PARAMETER)
+
 class Structures(unittest.TestCase):
 
     def test_struct_by_value(self):
index 184932fd4cadbd71a7d6e97fba64fd6d60b3c900..de9c37c6d3d6fb2796c45b983862d37a08890923 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -37,6 +37,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #16169: Fix ctypes.WinError()'s confusion between errno and winerror.
+
 - Issue #16089: Allow ElementTree.TreeBuilder to work again with a non-Element
   element_factory (fixes a regression in SimpleTAL).