Commit 949c4d27 by kice Committed by Tianqi Chen

Some Windows and MSVC fixes (#4569)

* fix python exception creation in Windows

* better string conversion for msvc

* fix cpp style issue
parent e91cc5ab
...@@ -35,8 +35,13 @@ if sys.version_info[0] == 3: ...@@ -35,8 +35,13 @@ if sys.version_info[0] == 3:
# this function is needed for python3 # this function is needed for python3
# to convert ctypes.char_p .value back to python str # to convert ctypes.char_p .value back to python str
if sys.platform == "win32": if sys.platform == "win32":
encoding = 'cp' + str(ctypes.cdll.kernel32.GetACP()) def _py_str(x):
py_str = lambda x: x.decode(encoding) try:
return x.decode('utf-8')
except UnicodeDecodeError:
encoding = 'cp' + str(ctypes.cdll.kernel32.GetACP())
return x.decode(encoding)
py_str = _py_str
else: else:
py_str = lambda x: x.decode('utf-8') py_str = lambda x: x.decode('utf-8')
else: else:
......
...@@ -235,7 +235,14 @@ std::string NormalizeError(std::string err_msg) { ...@@ -235,7 +235,14 @@ std::string NormalizeError(std::string err_msg) {
if (!(is >> line)) return false; if (!(is >> line)) return false;
// get filename // get filename
while (is.peek() == ' ') is.get(); 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; if (!getline(is, file_name, ':')) return false;
file_name = drive + ":" + file_name;
#else
if (!getline(is, file_name, ':')) return false;
#endif
// get line number // get line number
if (!(is >> line_number)) return false; if (!(is >> line_number)) return false;
// get rest of the message. // get rest of the message.
......
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