You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ap...@apache.org on 2022/05/30 13:51:42 UTC
[arrow] branch master updated: ARROW-16617: [C++] Add support for multi-byte system error message on Windows
This is an automated email from the ASF dual-hosted git repository.
apitrou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new e19acbe9c6 ARROW-16617: [C++] Add support for multi-byte system error message on Windows
e19acbe9c6 is described below
commit e19acbe9c698699de6a24600060ef662316bdc2a
Author: Sutou Kouhei <ko...@clear-code.com>
AuthorDate: Mon May 30 15:51:31 2022 +0200
ARROW-16617: [C++] Add support for multi-byte system error message on Windows
Closes #13203 from kou/cpp-windows-message-unicode
Lead-authored-by: Sutou Kouhei <ko...@clear-code.com>
Co-authored-by: Sutou Kouhei <ko...@cozmixng.org>
Co-authored-by: Antoine Pitrou <pi...@free.fr>
Signed-off-by: Antoine Pitrou <an...@python.org>
---
cpp/src/arrow/util/io_util.cc | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/cpp/src/arrow/util/io_util.cc b/cpp/src/arrow/util/io_util.cc
index 53f8012e2b..c225656cb8 100644
--- a/cpp/src/arrow/util/io_util.cc
+++ b/cpp/src/arrow/util/io_util.cc
@@ -203,16 +203,26 @@ std::string ErrnoMessage(int errnum) { return std::strerror(errnum); }
#if _WIN32
std::string WinErrorMessage(int errnum) {
- char buf[1024];
- auto nchars = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, errnum, 0, buf, sizeof(buf), NULL);
- if (nchars == 0) {
+ constexpr DWORD max_n_chars = 1024;
+ WCHAR utf16_message[max_n_chars];
+ auto n_utf16_chars =
+ FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
+ errnum, 0, utf16_message, max_n_chars, NULL);
+ if (n_utf16_chars == 0) {
// Fallback
std::stringstream ss;
ss << "Windows error #" << errnum;
return ss.str();
}
- return std::string(buf, nchars);
+ auto utf8_message_result =
+ arrow::util::WideStringToUTF8(std::wstring(utf16_message, n_utf16_chars));
+ if (!utf8_message_result.ok()) {
+ std::stringstream ss;
+ ss << "Windows error #" << errnum;
+ ss << "; failed to convert error message to UTF-8: " << utf8_message_result.status();
+ return ss.str();
+ }
+ return *utf8_message_result;
}
#endif