[Lldb-commits] [PATCH] D105779: RFC: [lldb] Fix editline unicode on Linux

Jan Kratochvil via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Jul 12 13:18:07 PDT 2021


jankratochvil marked an inline comment as done.
jankratochvil added inline comments.


================
Comment at: lldb/tools/driver/Driver.cpp:871
 int main(int argc, char const *argv[]) {
+  ::setlocale(LC_ALL, "");
+  ::setlocale(LC_CTYPE, "");
----------------
teemperor wrote:
> Can you make this `std::setlocale`?
OK, I see <clocale> is for `std::setlocale`.


================
Comment at: lldb/tools/driver/Driver.cpp:872
+  ::setlocale(LC_ALL, "");
+  ::setlocale(LC_CTYPE, "");
+
----------------
teemperor wrote:
> I don't think we need this if we set `LC_ALL`?
Originally I have just copy-pasted it. But when testing it more now I think it makes some sense:
```
#include <locale.h>
#include <stdio.h>
#include <wctype.h>
int main(void) {
  printf("setlocale(LC_ALL  )=%s\n",setlocale(LC_ALL  ,""));
  printf("iswprint(0x17e)=%d\n",iswprint(0x17e));
  printf("setlocale(LC_CTYPE):%s\n",setlocale(LC_CTYPE,""));
  printf("iswprint(0x17e)=%d\n",iswprint(0x17e));
  return 0;
}
$ LANG=C LC_NAME=foobar LC_CTYPE=en_US.UTF-8 ./setlocale
setlocale(LC_ALL  )=(null)
iswprint(0x17e)=0
setlocale(LC_CTYPE):en_US.UTF-8
iswprint(0x17e)=1
```
Because: [[ https://pubs.opengroup.org/onlinepubs/009695399/functions/setlocale.html | Setting all of the categories of the locale of the process is similar to successively setting each individual category of the locale of the process, except that all error checking is done before any actions are performed. ]]


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105779



More information about the lldb-commits mailing list