Commit f41f8f99 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #22977: Fixed formatting Windows error messages on Wine.

Patch by Martin Panter.
parent a7eaf56a
...@@ -6,10 +6,11 @@ import unittest ...@@ -6,10 +6,11 @@ import unittest
import pickle import pickle
import weakref import weakref
import errno import errno
import ctypes
from test.support import (TESTFN, captured_output, check_impl_detail, from test.support import (TESTFN, captured_output, check_impl_detail,
check_warnings, cpython_only, gc_collect, run_unittest, check_warnings, cpython_only, gc_collect, run_unittest,
no_tracing, unlink) no_tracing, unlink, get_attribute)
class NaiveException(Exception): class NaiveException(Exception):
def __init__(self, x): def __init__(self, x):
...@@ -245,6 +246,13 @@ class ExceptionTests(unittest.TestCase): ...@@ -245,6 +246,13 @@ class ExceptionTests(unittest.TestCase):
self.assertEqual(w.strerror, 'foo') self.assertEqual(w.strerror, 'foo')
self.assertEqual(w.filename, None) self.assertEqual(w.filename, None)
def test_windows_message(self):
"""Should fill in unknown error code in Windows error message"""
windll = get_attribute(ctypes, "windll")
code = int.from_bytes(b"\xE0msc", "big")
with self.assertRaisesRegex(OSError, hex(code)):
windll.kernel32.RaiseException(code, 0, 0, None)
def testAttributes(self): def testAttributes(self):
# test that exception attributes are happy # test that exception attributes are happy
......
...@@ -10,6 +10,9 @@ Release date: tba ...@@ -10,6 +10,9 @@ Release date: tba
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #22977: Fixed formatting Windows error messages on Wine.
Patch by Martin Panter.
- Issue #23803: Fixed str.partition() and str.rpartition() when a separator - Issue #23803: Fixed str.partition() and str.rpartition() when a separator
is wider then partitioned string. is wider then partitioned string.
......
...@@ -491,7 +491,7 @@ PyErr_SetFromErrnoWithFilenameObjects(PyObject *exc, PyObject *filenameObject, P ...@@ -491,7 +491,7 @@ PyErr_SetFromErrnoWithFilenameObjects(PyObject *exc, PyObject *filenameObject, P
/* Only ever seen this in out-of-mem /* Only ever seen this in out-of-mem
situations */ situations */
s_buf = NULL; s_buf = NULL;
message = PyUnicode_FromFormat("Windows Error 0x%X", i); message = PyUnicode_FromFormat("Windows Error 0x%x", i);
} else { } else {
/* remove trailing cr/lf and dots */ /* remove trailing cr/lf and dots */
while (len > 0 && (s_buf[len-1] <= L' ' || s_buf[len-1] == L'.')) while (len > 0 && (s_buf[len-1] <= L' ' || s_buf[len-1] == L'.'))
...@@ -600,7 +600,7 @@ PyObject *PyErr_SetExcFromWindowsErrWithFilenameObjects( ...@@ -600,7 +600,7 @@ PyObject *PyErr_SetExcFromWindowsErrWithFilenameObjects(
NULL); /* no args */ NULL); /* no args */
if (len==0) { if (len==0) {
/* Only seen this in out of mem situations */ /* Only seen this in out of mem situations */
message = PyUnicode_FromFormat("Windows Error 0x%X", err); message = PyUnicode_FromFormat("Windows Error 0x%x", err);
s_buf = NULL; s_buf = NULL;
} else { } else {
/* remove trailing cr/lf and dots */ /* remove trailing cr/lf and dots */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment