[libcxx-commits] [PATCH] D146398: [libcxx] Fix using std::wcout/wcin on Windows with streams configured in wide mode

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue May 2 05:00:31 PDT 2023


mstorsjo updated this revision to Diff 518684.
mstorsjo added a comment.

Apply the simplifications suggested by @tahonermann.

Keep most of the codepaths as they were, doing conversions between wchar and char using codecvt. The main behaviour difference from git main is that we set `__always_noconv_` to true for the `__is_win32api_wide_char` case. If the user imbues a custom locale, that is used and `__always_noconv_` is updated based on that.

For the output case, this is mostly quite straightforward with just one small piece of Windows specific logic, to avoid using `fwrite()` for more than one `wchar_t` and fall back on repeated `fputwc()` instead. (`fputwc()` works in both the default and Unicode modes of stdout, while `fwrite()` with `wchar_t` only works if the stream has been changed to Unicode mode.)

For the input case, we have to restructure code to avoid truncating chars into an intermediate `char` buffer, for the `__always_noconv_` case. I'm not sure how well the testsuite covers the corner cases here; I've tried to retain the old existing logic through the refactoring.

I added testcases that imbue a custom locale with a custom codecvt on the wide streams, to make sure that case still works.

I added a mention of these corner cases in the UsingLibcxx document.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146398/new/

https://reviews.llvm.org/D146398

Files:
  libcxx/docs/UsingLibcxx.rst
  libcxx/src/std_stream.h
  libcxx/test/std/input.output/iostream.objects/wide.stream.objects/check-stderr.sh
  libcxx/test/std/input.output/iostream.objects/wide.stream.objects/check-stdout.sh
  libcxx/test/std/input.output/iostream.objects/wide.stream.objects/send-stdin.sh
  libcxx/test/std/input.output/iostream.objects/wide.stream.objects/test.dat
  libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcerr-imbue.sh.cpp
  libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcerr-wide-mode.sh.cpp
  libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcin-imbue.sh.cpp
  libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcin-wide-mode.sh.cpp
  libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcout-imbue.sh.cpp
  libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcout-wide-mode.sh.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146398.518684.patch
Type: text/x-patch
Size: 18282 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230502/75a2054a/attachment-0001.bin>


More information about the libcxx-commits mailing list