-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
decouple Windows APIs from UTF16String type #15033
Conversation
return utf8(UTF16String(buf)) | ||
end | ||
systemerror(:longpath, n == 0) | ||
x = n < length(buf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this assigned to a variable? nevermind I see how it works now - add some comments?
lgtm. maybe squash to 1 commit though? i'm not sure the rest are necessary |
function access_env(onError::Function, str::AbstractString) | ||
var = cwstring(str) | ||
len = _getenvlen(var) | ||
len == 0 && return Libc.GetLastError() != ERROR_ENVVAR_NOT_FOUND ? utf8("") : onError(str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be clearer as if
s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's an impressive garden path. regardless of where i tried to start reading the expression, I had to revise my assumptions as a read more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may actually have screwed this up. Will fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does that mean missing branch coverage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, actually no – I didn't screw it up because of the return
. But yes, this is obviously confusing.
They're logically decoupled and none are broken, so I like the current breakdown into small pieces. Couple minor places that could use some comments or rearranging for clarity, otherwise LGTM2. |
Woot! Windows build success! That's the risky part. |
Looks like we don't have any tests for |
793fc26
to
f032a66
Compare
I tested |
still needs more comments - and a rebase given #15137 was merged separately |
Seems that the clipboard command doesn't work on Linux since we need xsel or xclip. Is there some way we can install one of those on Travis? |
f032a66
to
f11b2ab
Compare
f11b2ab
to
6970fda
Compare
I think so, we can add it to the big long list of |
decouple Windows APIs from UTF16String type
Hm the clipboard test is failing on the mac buildbot, it actually seems to be running at a reasonable pace the last few days - https://build.julialang.org/builders/build_osx10.9-x64/builds/377/steps/shell_2/logs/stdio Anyone have any ideas what might be causing this?
|
I wonder if the buildbot machines don't have usable clipboard functionality. |
@@ -152,7 +152,9 @@ end | |||
systemerror(:CloseClipboard, 0==ccall((:CloseClipboard, "user32"), stdcall, Cint, ())) | |||
plock = ccall((:GlobalLock, "kernel32"), stdcall, Ptr{UInt16}, (Ptr{UInt16},), pdata) | |||
systemerror(:GlobalLock, plock==C_NULL) | |||
s = utf8(utf16(plock)) | |||
len = 0 | |||
while unsafe_load(plock, len+1) != 0; len += 1; end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe len = ccall(:wcslen, Csize_t, (Ptr{Cwchar},), plock)
would be clearer? Better yet, add a method:
@windows_only utf16to8(p::Ptr{UInt16}, len=ccall(:wcslen, Csize_t, (Ptr{UInt16},), p)) = utf16to8(pointer_to_array(p, len))
method?
Eventually I think we'll want to export some version of these routines, for the benefit of external packages calling Windows APIs. |
@@ -96,6 +94,105 @@ convert(::Type{Cstring}, s::Symbol) = Cstring(unsafe_convert(Ptr{Cchar}, s)) | |||
|
|||
# in string.jl: unsafe_convert(::Type{Cwstring}, s::WString) | |||
|
|||
# FIXME: this should be handled by implicit conversion to Cwstring, but good luck with that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the obstacle to using the Cwstring
conversion for ccall
arguments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realise I'm coming late to this party, but if this is only being used on windows, would it be better to simply use the Windows APIs, e.g. |
@vtjnash suggested that at some point but I found testing the Windows API difficult. I suppose I could spin up a new VM and give it a shot. Or if someone else who has an actual Windows machine wants to take a crack at it, I'd be fine with that too. |
I did, but by then you had already implemented it in Julia, so there wasn't really any point in switching. |
There are a few reasons to change: less code to maintain and test, less temptation for users and packages to call unexported functions that we might change or remove in the future. |
This PR introduces three functions that are strictly internal to Base for now:
utf8to16
,utf16to8
andcwstring
– which callsutf8to16
ensuring that there are no embedded NULs and add a trailing NUL. These are self-contained and allow use to interact with Windows APIs without theUTF16String
type.