From 0ba86c31f4eab05cb4a730fd549663fbf8b1ea9e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 16 Jun 2016 19:29:40 +0530 Subject: [PATCH] Use find_msvcrt() to load the CRT instead of globbing --- src/calibre/test_build.py | 7 +++++++ src/calibre/utils/terminal.py | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/calibre/test_build.py b/src/calibre/test_build.py index de3182bd8b..9453fc4319 100644 --- a/src/calibre/test_build.py +++ b/src/calibre/test_build.py @@ -274,6 +274,12 @@ def test_openssl(): raise ValueError('Mozilla CA certs not loaded') fprint('SSL OK!') +def test_crt(): + from ctypes.util import find_msvcrt + if not find_msvcrt(): + raise SystemExit('find_msvcrt() failed') + fprint('CRT OK!') + def test(): if iswindows: test_dlls() @@ -305,6 +311,7 @@ def test(): test_wpd() test_winutil() test_file_dialog_helper() + test_crt() else: test_terminal() if isosx: diff --git a/src/calibre/utils/terminal.py b/src/calibre/utils/terminal.py index 0632803e18..5581e6fcc8 100644 --- a/src/calibre/utils/terminal.py +++ b/src/calibre/utils/terminal.py @@ -158,9 +158,9 @@ def crt(): # We use the C runtime bundled with the calibre windows build global _crt if _crt is None: - import glob, ctypes - d = os.path.join(os.path.dirname(sys.executable), '*.CRT', 'msvcr*.dll') - _crt = ctypes.CDLL(glob.glob(d)[0]) + import ctypes + from ctypes.util import find_msvcrt + _crt = ctypes.CDLL(find_msvcrt()) return _crt class ColoredStream(Detect):