[std] Fix unicode passed through stdout/stderr #917
[std] Fix unicode passed through stdout/stderr #917yuxiaomao merged 2 commits intoHaxeFoundation:masterfrom
Conversation
The windows builtin w-string functions don't produce actual utf-8, so it's better to use hashlink's implementations. This allows us to print directly without windows converting the buffer contents. Setting the locale interferes with printf which breaks unicode IPC, so we also need to remove that.
This _setmode method used to be used for print, but it was disabled by default due to threading issues: 9d21b13 Using fwrite avoids the utf8 bytes being converted to a different encoding by windows.
|
Does the unit tests actually test writing on stdout/stderr with sys.io.File.stdout().write ? Because the code you are removing is intended for that. Also does it work with a not Unicode terminal like |
Yes, it is tested in these cases: Without this file_write change, it writes garbled text to stderr/stdout.
Note, hl_sys_print used to use a similar thing but it caused issues so it got disabled already: 9d21b13
I don't think this fixes how unicode is displayed on the console, it only makes sure that the correct utf-8 bytes are put into the buffer (so piping to a file or another process should work). For displaying it in cmd or powershell, that is a different issue and will probably require a fix like hxcpp: HaxeFoundation/hxcpp#1307
This should work, I will double check this. |
function main() {
trace("Hello world!");
Sys.println("éá🙄🦉");
Sys.stdout().writeString("éá🙄🦉");
}Without this patch With this patch |
|
I need this fix, and I confirm that it fix the described bug. Utf-8 text are displayed correcly in git-bash (not in cwd, as expected). |
These patches are needed to restore ipc sys tests in the haxe repo.