[PATCH] D51558: [Windows] Convert from UTF-8 to UTF-16 when writing to a Windows console

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 4 14:04:46 PDT 2018


rnk added inline comments.


================
Comment at: llvm/lib/Support/raw_ostream.cpp:650-652
+    bool Success = ::WriteConsoleW((HANDLE)::_get_osfhandle(FD), &WideText[0],
+                                   WCharsToWrite, &ActuallyWritten,
+                                   /*Reserved=*/nullptr);
----------------
zturner wrote:
> rnk wrote:
> > rnk wrote:
> > > rsmith wrote:
> > > > zturner wrote:
> > > > > Can you test this with the following?
> > > > > 
> > > > > ```
> > > > > outs() << "Test\nTest2";
> > > > > ```
> > > > > 
> > > > > I'm wondering if the LF will be handled properly.  I think part of what `::write` does is to transcode LF to CRLF.  So if we're directly calling `WriteConsole`, we might not get this for free anymore.
> > > > I think you want `&WideText[WCharWritten]` here.
> > > Thanks. Unfortunately, this isn't testable without faking up some kind of console.
> > I think the Windows console doesn't care if it gets \r\n or \n at this point. I don't think there's a way I can observe a difference in behavior now, since I can't WriteConsole to a pipe. =/
> Just put some code in `main` that calls the above with your change and run the program.  See what it outputs?
Right, I compiled and ran a program that does `outs() << "Test\nTest2";` and the newlines show up. The Windows console doesn't need CRLF, it treats LF as implicitly returning the cursor to the beginning of the next line.


https://reviews.llvm.org/D51558





More information about the llvm-commits mailing list