[PATCH] D51558: [Windows] Convert from UTF-8 to UTF-16 when writing to a Windows console
Zachary Turner via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 31 14:21:10 PDT 2018
zturner added inline comments.
================
Comment at: llvm/lib/Support/raw_ostream.cpp:572
+#ifdef _WIN32
+ IsConsole = ::GetFileType((HANDLE)::_get_osfhandle(fd)) == FILE_TYPE_CHAR;
+#endif
----------------
You can use `llvm::sys::Process::FileDescriptorIsDisplayed(fd)` here. Also, no need to put it behind the `#ifdef`, the member variable can be set correctly regardless of platform.
================
Comment at: llvm/lib/Support/raw_ostream.cpp:632
+// probably the best compromise we can make.
+static bool write_console_impl(int FD, const char *Ptr, size_t Size) {
+ SmallVector<wchar_t, 256> WideText;
----------------
`StringRef Data`?
================
Comment at: llvm/lib/Support/raw_ostream.cpp:755-780
+#if defined(_WIN32)
+ // Disable buffering for console devices. Console output is re-encoded from
+ // UTF-8 to UTF-16 on Windows, and buffering it would require us to split the
+ // buffer on a valid UTF-8 codepoint boundary. Terminal buffering is disabled
+ // below on most other OSs, so do the same thing on Windows and avoid that
+ // complexity.
+ if (IsConsole)
----------------
Given that we already have this `IsConsole` variable, combined with my suggestion above to set the variable to a real value for every platform, can we re-write this entire function:
```
if (IsConsole)
return 0;
#if !defined(__minix)
struct stat statbuf;
if (fstat(FD, &statbuf) != 0)
return 0;
return statbuf.st_blksize.
#else
return raw_ostream::preferred_buffer_size();
#endif
```
https://reviews.llvm.org/D51558
More information about the llvm-commits
mailing list