Does not accept unicode file path #293
Labels
No labels
announcement
bug
build
CI
dependencies
documentation
duplicate
enhancement
experience feedback
feature request
github_actions
help wanted
install
invalid
Long-term
optimization
portability
question
target-specific
test issue
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-Cyan4973/xxHash#293
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Does not accept unicode file path, for example:
Unfortunately, the code handling file names does nothing special, and relies entirely on standard C
fopen().I have no idea how
fopen()behaves with unicode characters. This may be system dependent.I presume the issue happens on Windows ?
Yes, the problem is in Windows, checked on 2 systems:
Windows Server 2008 R2
Windows 7
Maybe fopen () has options for working correctly with unicode, or use another function that can correctly handle such names?
How was the binary produced ?
Did you compiled it using Visual Studio ?
I used your latest compiled version from here: https://github.com/Cyan4973/xxHash/releases/download/v0.7.2/xxhsum_win64_0_7_2_avx2.zip
Oof, this will be fun.
fopenon Windows uses ANSI encoding, while files are stored in UTF-16.I might take a look into this when I get a chance. It might be as simple as
_wfopenwith ambtowc, but maybe not.Hi, I've made small code which introduces UTF-8 compatibility for Windows+MSVC build.
@easyaspi314 since I don't test this code much, I don't send PR so far. But hope it helps.
Here's some notes.
(1) We can safely use UTF-8 to represent Unicode filename for modern systems (except Windows).
Nowadays as for modern Linux, *NIX and OS X systems, basically we can say all possible filenames are sequence of
chars. So in these systems,fopen()is fine for Unicode filenames.Some OS X file system/API has Unicode normalization issues and it may cause issue of interoperability of
xxhsum -c. But I think we can address this problem later.(2) I believe "UTF-8 Everywhere" is good approach.
For
xxhsum, I mean that almost all part of program should think about and be written for UTF-8. And only input/output functions are taking care about other encodings.(3) I'd like to avoid to use low level WIN32 API such as
GetCommandLineW()orCommandLineToArgvW().For example, Microsoft's ucrt has wildcard expansion in its startup routine (see
argv_parsing.cppin Windows Kits). To support these functions, it'd be nice to avoid to use low level APIs.(4) New entry point should be
wmain().Since mapping between Unicode and MBCS isn't perfect, MBCS may introduce other problem. So, I strongly recommend to use Unicode directly.
One possible idea is that redefine
mainasmain_utf8by macro.wmain()receives UTF-16argv[], convert them to UTF-8 and passes UTF-8argv[]tomain_utf8().(5) For stdout and stderr,
_setmode(x, _O_U8TEXT)looks promising.But according to the document, there're many restrictions. One of the biggest restriction is:
Here, "Unicode mode" includes UTF-8 (
_O_U8TEXT). Therefore, we must usewprintf()family which only accepts UTF-16 string. So, we must convert UTF-8 to UTF-16 to output UTF-8!Other restriction is it doesn't allow to use narrow print functions such as
printf(). If we use narrow print function, program crashes immediately. Forxxhsumit means we should keep usingDISPLAY()macro family.(6) Windows Powershell has problematic default encoding method for redirection.
You can't redirect UTF-8 encoding stdout/stderr with default settings of the Windows PowerShell. Please read this Q&A at StackOverflow: Displaying Unicode in Powershell.
As this answer shows, you can use UTF-8 encoding in redirection by the following command:
Windows 7, CHCP set to 65001.
0.7.0 outputs привет.txt, whereas 0.7.1+ outputs ������.txt
0.7.0 doesn't seem to work, at least not in MinGW64:
wmaincauses a linker error on MinGW, but I think I found a solution.There has to be a better way to do this, though.
This should be fixed by #304.
@easyaspi314, err… where is a Windows binary to verify the fix?
Here are a few binaries for the people who are too lazy to compile their own code (jk):
xxhsum-windows-binaries-eba72be9.zip
At least on my PC, Windows 10, they all pass the Unicode test I made, even if the terminal/font cannot display it:
@KonstantinMogilev @t-mat @sergeevabc When you get a chance, can you check to make sure this works on your machines?
@easyaspi314, that version is still better as its output is consistent no matter what code page is, i.e.
whereas your approach outputs
I honestly don't understand why 0.7.0 works — AFAICT, nothing changed that would cause it to work, and also, I am pretty sure I tried compiling 0.7.0 and it did not work.
OK, I think I see the difference.
I analyzed the binary, and it looks like the 0.7.0 binary was compiled by MSYS2 instead of MinGW or MSVC.
MSYS2 and Cygwin both use a wrapper which handles everything UTF-8 automagically.
Well, strangely, I thought that all Windows binaries provided in the release section were compiled using
mingw64frommsys2environment. Maybe I missed or confused something...The difference between MinGW and MSYS2/Cygwin is that MinGW basically compiles entirely against the MSVC CRT and acts like Windows, but MSYS2/Cygwin try to emulate a POSIX system, which requires many wrappers. It basically hijacks MSVC CRT and replaces it with its own Newlib libc.
Command line conversion is done here:
github.com/msys2/Cygwin@bede85ba6d/winsup/cygwin/dcrt0.cc (L947)Btw, I don't see a
v0.7.0Windows binary in the release section ...Weird. Maybe it was a test binary.
Anyway, is there a preferred environment for the production of next version of Windows binaries ?
xxhsum-i686-mingw32-test.zip
New test based more off of @t-mat's code
Compiled on classic MinGW-w32, which links directly to
msvcrt.dllwhich is system specific.@sergeevabc can you please test this on your Windows 7 machine?
Also, if anyone has XP installed for some reason, I'd like to know if it works too, out of curiosity.
@Cyan4973 @KonstantinMogilev This should be completely solved by #323.
@Cyan4973 Uh, well MSVC sucks
at XXH3, so I'm guessing eitherclang-clormingw-w64.@easyaspi314, about XP… it works here, but in a peculiar way.
Thanks!
That is actually a crash. On most Windows terminals, when a console program crashes, the last line is blanked out and the program exits silently. If you watch in slow motion, the first bit of the hash is displayed:

I'd kill for the helpful
Segmentation faultorAbortedmessages on Linux, or at least an error message box.This blankout doesn't happen when redirecting the output to a file, which is why you see that.
We don't need to fully support XP. We didn't need to since 2014.
But the important thing is that ASCII works.
I would be more concerned if the program crashed immediately.
Plus, it might actually work if we link against something Microsoft wanted us to link against.
Untested possible solution:
In this case, what would probably happen is UTF-8 appears as mojibake.
Nevermind, I'm a massive idiot…if
_setmodeerrors out, it wouldn't change from_O_TEXT...I don't immediately see the solution, but I don't think this should delay
v0.7.3.XP support is good enough for now, and there are higher priorities.
I think we can safely close this.
While this patch may crash XP on Unicode text with the default msvcrt.dll, that is not much worse than it was before the patch where Unicode also didn't work. And XP is 19 years old and EOL for 6 years so yeah.
@easyaspi314, I wholeheartedly disagree with that EOL reasoning. It means something for relatively wealthy people in industrially developed areas, but what about the rest of mankind who are being happy on little and have limited means to upgrade at once by an order of Silicon Valley hegemon? Otherwise, let’s appeal to extremes and abandon x86 in favour of x64, because, you know, “the progress calls”.
Firstly, XP is still patched by enthusiasts like Simplix. Secondly, there are projects such as DOSBox and ScummVM (accepted for Google Summer of Code, for that matter), which give a second life to pre-Win apps with an amazing benefit-to-every-byte ratio. Thirdly, the stats about XP machines exist, at least Internet-connected ones (not always the case), which show they are in no hurry to leave top 10 OS list.
That’s why I urge you to see this issue as an intellectual challenge like demoscene craftsmen have with 64K intros, like visual artists have with pixel paintings, like algorithm researchers have with code golfing, like Tom Cruise has with “Mission
impossible”. Pull it together, you can do it.Well the only thing I have left to try is mucking with Win32 API. 🤢 Apparently, Git does this.
I might try to set up an XP VM.
Holy shit,

WriteConsoleWworks.Mostly.
Yatta! @sergeevabc The new fix is up in #335
I don't want to see a
wchar_tever again.