[Python-checkins] cpython (3.3): Issue #16169: Fix ctypes.WinError()'s confusion between errno and winerror
richard.oudkerk
python-checkins at python.org
Tue Oct 9 14:55:28 CEST 2012
http://hg.python.org/cpython/rev/a3d65edc3b04
changeset: 79619:a3d65edc3b04
branch: 3.3
parent: 79617:f02974773a71
user: Richard Oudkerk <shibturn at gmail.com>
date: Tue Oct 09 13:28:10 2012 +0100
summary:
Issue #16169: Fix ctypes.WinError()'s confusion between errno and winerror
files:
Lib/ctypes/__init__.py | 2 +-
Lib/ctypes/test/test_win32.py | 22 ++++++++++++++++++++++
Misc/NEWS | 2 ++
3 files changed, 25 insertions(+), 1 deletions(-)
diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py
--- a/Lib/ctypes/__init__.py
+++ b/Lib/ctypes/__init__.py
@@ -456,7 +456,7 @@
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
diff --git a/Lib/ctypes/test/test_win32.py b/Lib/ctypes/test/test_win32.py
--- a/Lib/ctypes/test/test_win32.py
+++ b/Lib/ctypes/test/test_win32.py
@@ -67,6 +67,28 @@
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):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -37,6 +37,8 @@
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).
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list