From 4ea7732e8f9b43e8314626dae054c695a313d7cf Mon Sep 17 00:00:00 2001 From: kice Date: Sun, 22 Dec 2019 21:02:33 -0500 Subject: [PATCH 1/3] fix python exception creation in Windows --- src/runtime/c_runtime_api.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/runtime/c_runtime_api.cc b/src/runtime/c_runtime_api.cc index 3608fcea4aa1..2d6f62d46e3c 100644 --- a/src/runtime/c_runtime_api.cc +++ b/src/runtime/c_runtime_api.cc @@ -235,7 +235,14 @@ std::string NormalizeError(std::string err_msg) { if (!(is >> line)) return false; // get filename while (is.peek() == ' ') is.get(); +#ifdef _MSC_VER // handle volume separator ":" in Windows path + std::string drive; + if (!getline(is, drive, ':')) return false; if (!getline(is, file_name, ':')) return false; + file_name = drive + ":" + file_name; +#else + if (!getline(is, file_name, ':')) return false; +#endif // get line number if (!(is >> line_number)) return false; // get rest of the message. From 0e818bf3bb05b2a1e6eb956473717e635cea6008 Mon Sep 17 00:00:00 2001 From: kice Date: Sun, 22 Dec 2019 21:05:19 -0500 Subject: [PATCH 2/3] better string conversion for msvc --- python/tvm/_ffi/base.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/python/tvm/_ffi/base.py b/python/tvm/_ffi/base.py index 6e7c8f9f3824..716091e96ed0 100644 --- a/python/tvm/_ffi/base.py +++ b/python/tvm/_ffi/base.py @@ -35,8 +35,13 @@ # this function is needed for python3 # to convert ctypes.char_p .value back to python str if sys.platform == "win32": - encoding = 'cp' + str(ctypes.cdll.kernel32.GetACP()) - py_str = lambda x: x.decode(encoding) + def _py_str(x): + try: + return x.decode('utf-8') + except UnicodeDecodeError: + encoding = 'cp' + str(ctypes.cdll.kernel32.GetACP()) + return x.decode(encoding) + py_str = _py_str else: py_str = lambda x: x.decode('utf-8') else: From d0865fe265217927e389c464006355869b515014 Mon Sep 17 00:00:00 2001 From: kice Date: Sun, 22 Dec 2019 21:08:16 -0500 Subject: [PATCH 3/3] fix cpp style issue --- src/runtime/c_runtime_api.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/c_runtime_api.cc b/src/runtime/c_runtime_api.cc index 2d6f62d46e3c..f1d543537e19 100644 --- a/src/runtime/c_runtime_api.cc +++ b/src/runtime/c_runtime_api.cc @@ -235,7 +235,7 @@ std::string NormalizeError(std::string err_msg) { if (!(is >> line)) return false; // get filename while (is.peek() == ' ') is.get(); -#ifdef _MSC_VER // handle volume separator ":" in Windows path +#ifdef _MSC_VER // handle volume separator ":" in Windows path std::string drive; if (!getline(is, drive, ':')) return false; if (!getline(is, file_name, ':')) return false;