Commit cc4710af authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari
Browse files

testsuite: Simplify kernel32 glue logic

On Windows the testsuite driver calls kernel32 to set the current
terminal codepage. The previous implementation of this was significantly
more complex than necessary, and was wrong in the case of MSYS2, which
requires that we explicitly load the library using the name of its
DLL, including its file extension.

Test Plan: Validate on Windows

Reviewers: austin, RyanGlScott, Phyx

Reviewed By: RyanGlScott, Phyx

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2641

GHC Trac Issues: #12661
parent 8a5960ad
......@@ -160,17 +160,18 @@ if windows:
if windows:
import ctypes
# Windows and mingw* Python provide windll, msys2 python provides cdll.
if hasattr(ctypes, 'windll'):
mydll = ctypes.windll
if hasattr(ctypes, 'WinDLL'):
mydll = ctypes.WinDLL
else:
mydll = ctypes.cdll
mydll = ctypes.CDLL
# This actually leaves the terminal in codepage 65001 (UTF8) even
# after python terminates. We ought really remember the old codepage
# and set it back.
if mydll.kernel32.SetConsoleCP(65001) == 0:
kernel32 = mydll('kernel32.dll')
if kernel32.SetConsoleCP(65001) == 0:
raise Exception("Failure calling SetConsoleCP(65001)")
if mydll.kernel32.SetConsoleOutputCP(65001) == 0:
if kernel32.SetConsoleOutputCP(65001) == 0:
raise Exception("Failure calling SetConsoleOutputCP(65001)")
else:
# Try and find a utf8 locale to use
......
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