Open Skyb0rg007 opened 3 months ago
I wrote a PowerShell script here that exhibits the bug. I believe that the gobbled error messages in the examples above is due to the Console encoding, and changing the Console to UTF8 fixes those error messages. It does not fix the underlying issue however.
This is not an easy fix, since we do not currently support wide characters/strings in SML/NJ. As I understand it, the Windows Unicode APIs assume UTF-16 encoding of file names. Perhaps we can convert between UTF-8 strings and UTF-16 in the runtime system.
I believe the standard method for doing this is the MultiByteToWideChar
function. Calling it at API boundaries could be a good fix, though it wouldn't completely fix the issue (due to esoteric reasons involving UCS-2 filenames which are not valid UTF16. That's more of a SML issue than an SML/NJ issue though).
Version
110.99.4 (Latest)
Operating System
OS Version
Windows 11 Pro
Processor
System Component
Core system
Severity
Minor
Description
On Windows, SML is unable to open files with Unicode filenames:
Transcript
See above
Expected Behavior
OS.FileSys.readDir
should not return paths to files that don't exist, and instead return the path of a file that exists.TextIO.openIn
should be able to open every file that exists on a system.Steps to Reproduce
Additional Information
I believe the issue is that the Win32 APIs are not compiled with the
UNICODE
macro defined, asOS.FileSys.readDir
is implemented usingFindFirstFile
which is macro-expanded to different versions based on the presence of this macro.Email address
skyler DOT soss AT gmail.com
Edit: Added example that didn't use UTF16 surrogates, since this is not a UTF16-specific issue.