-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
switch to using 'W' versions of windows functions instead of 'A' #534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
'A' functions convert narrow string parameter to UTF16 and call the 'W' variant. Manual conversion can be done by Win32 functions It is also possible to set codepage to UTF8 per application (or per thread) and let Windows do the conversions. |
Zig will use its own functions for this. Less room for error.
This is not acceptable since the strings have a non-upper-bounded length.
How? |
The above functions handle (or claim to handle) invalid input sentences and surrogates.
I have yet to see string longer than a page. Applications dealing with big texts (editors) split them into parts, long blob is a no-no.
Oops, not possible (to switch Win32 app to "UTF8 mode"). I was thinking something else. |
Better to not make syscalls when no syscalls are fundamentally required.
Not true since we accept an allocator argument when we want to use the heap. |
File paths is probably the only time this really matters. But yeah, to be safe. |
* error.BadFd is not a valid error code. it would always be a bug to get this error code. * merge error.Io with existing error.InputOutput * merge error.PathNotFound with existing error.FileNotFound. Not all OS's support both. * add os.File.openReadC * add error.BadPathName for windows file operations with invalid characters * add os.toPosixPath to help stack allocate a null terminating byte * add some TODOs for other functions to investigate removing the allocator requirement * optimize some implementations to use the alternate functions when a null byte is already available * add a missing error.SkipZigTest * os.selfExePath uses a non-allocating API * os.selfExeDirPath uses a non-allocating API * os.path.real uses a non-allocating API * add os.path.realAlloc and os.path.realC * convert many windows syscalls to use the W versions (See #534)
This does a proof of concept of changing most file system APIs to not require an allocator and remove the possibility of failure via OutOfMemory. This also does most of the work of #534.
Bumping up to 0.3.0 since this is mostly solved by the above commit. |
progress:
|
about the first one, should we really be using it? accord to the docs that api is deprecated. |
See #1318 for the details on |
Oops, according to that issue, actually we should just remove |
* `CryptAcquireContextA` * `CryptReleaseContext` * `CryptGenRandom` See #534 (comment)
In the future we could go for this and drop -W, using UTF-8 directly. Unfortunately this only works in very new versions of windows. Perhaps this should be left for zig 1.0 or beyond. |
BUT, it still has some problem, the path length is still limited to 260... |
OK now we're down to one final callsite before closing this issue: Line 180 in 0369b65
|
Now that zig |
With #17448 it now might be worth reconsidering using the ANSI functions by default. |
How is that related to this issue? |
It's possible to use embedded The problems with this strategy:
Oh, and another point that I tested a while back that's also relevant: setting the code page to UTF-8 using the |
FWIW there are areas of the Windows API where the A entry points are not simply wrappers that convert parameters and call the W version. This is a simplistic notion that is not universally true. For example, GetAddrInfoEx: the A entry points do not support async and all related parameters must be null, but the W variant does support async completion. There are other corners of the Windows ecosystem where this phenomenon holds. |
Uh oh!
There was an error while loading. Please reload this page.
Here's the situation:
The 'A' versions of windows functions depend on a global code-page setting. We don't want to depend on global state in this way.
The 'W' versions use UTF-16LE with no global state, which at least supports all of unicode.
There are also some microsoft decisions such as: 'A' versions of file paths are limited to 260 bytes while 'W' versions are limited to 32,727. For some new API functions, there is no 'A' version, only 'W'. In general, 'A' seems legacy and deprecated, and 'W' is the correct way to use the Windows API.
Sadly, since Zig uses UTF-8 in the standard library (and this remains the correct decision), this essentially means decoding UTF-8, encoding UTF-16LE, making a Windows API call, decoding UTF-16LE, encoding UTF-8 for many of our syscalls on windows. But that's how it goes in the windows world.
The text was updated successfully, but these errors were encountered: