-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Update homedir and pwd to use StringVector and buffer resizing #32295
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
Conversation
skip, stat, unsafe_read, unsafe_write, write, transcode, uv_error, | ||
rawhandle, OS_HANDLE, INVALID_OS_HANDLE, windowserror | ||
|
||
import .Base.RefValue |
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.
Moved the import in the module file, since it's used by both path.jl
and file.jl
(it was indirectly called in path.jl
even though the import is in file.jl
) this should make the intent clear.
@vtjnash, can you take a quick look at this and merge if it looks good to you. I had a glance through and it looked reasonable to me. |
I see, since |
@stevengj is there any advantage to the suggestion of using function pwd()
path_max = 1024
buf = Base.StringVector(path_max - 1) # space for null-terminator implied by StringVector
sz = RefValue{Csize_t}(length(buf) + 1)
while true
rc = ccall(:uv_cwd, Cint, (Ptr{UInt8}, Ptr{Csize_t}), buf, sz)
if rc == 0
resize!(buf, sz[])
return String(buf)
elseif rc == Base.UV_ENOBUFS
resize!(buf, sz[] - 1) # space for null-terminator is implied by String
else
uv_error(:cwd, rc)
end
end
end vs. function pwd()
path_max = 1024
buf = Vector{UInt8}(undef, path_max)
sz = RefValue{Csize_t}(length(buf))
while true
rc = ccall(:uv_cwd, Cint, (Ptr{UInt8}, Ptr{Csize_t}), buf, sz)
if rc == 0
resize!(buf, sz[])
return String(buf)
elseif rc == Base.UV_ENOBUFS
resize!(buf, sz[])
else
uv_error(:cwd, rc)
end
end
end |
|
A |
29f51b7
to
6dde899
Compare
I'm happy with the PR now and is ready on my end, just needs a final review. |
base/filesystem.jl
Outdated
import .Base: cwstring | ||
end | ||
|
||
const MAX_PATH = Sys.iswindows() ? 260 : 1024 # max buffer size including null terminator |
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.
Should we perhaps give this a more accurate name? The real MAX_PATH
on NT is 32768, on Win32 is 260, on bsd sockets is 108, on linux is 4096, etc.
Since we have logic to resize as needed, perhaps we should call this AVG_PATH
and define it to always be some moderate sized value (like 108 or 260)?
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.
Good point. I'm not sure on which value makes the most sense on average. I think the current numbers seem quite reasonable on average for non-Windows systems (we could go with 512
)?
For windows it seems reasonable however to just use 260
.
Renaming the constant makes sense I believe.
elseif rc == Base.UV_ENOBUFS | ||
resize!(buf, sz[] - 1) # space for null-terminator implied by StringVector | ||
else | ||
uv_error(:cwd, rc) |
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.
should we call this "pwd"
, to reflect the name of the Julia function, or keep the name "getcwd"
, to reflect the name of the libc function?
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.
Good question. I called it cwd
to reflect the name of the libuv call, which I decided was perhaps more helpful for debugging purposes. If the pwd()
function errors in julia it will be clear which function is throwing the error from the stacktrace, but perhaps not clear which internal function caused the error and thus I decided to call it :cwd
instead of pwd
.
Feedback addressed: I decided to go with |
Win32: timeout Rebased to master by force pushing to re-kick CI. |
unrelated download failure on win64 |
No description provided.