-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Manually implement tempname on non-windows #38879
Conversation
Shouldn't this do the opposite? If |
I am not sure I understand. This is doing exactly what you are describing. If the user passes We could also achieve the same by setting |
The comment says:
That's the opposite of what it should do: if |
Currently:
With this PR:
|
Ah! I see where the confusion comes from. I was documenting the behavior of |
Ah, I understand the confusion: the comment is explaining why we need to unset
I worry about the thread safety of messing with |
9d0d599
to
6aee4e0
Compare
Yeah... |
We could at least put a lock around this so that multiple calls to this function from different threads don't end up concurrently modifying the same environment variable. |
Instead of |
I am using |
Ah fair enough |
The issue is not just Julia code; if any C library (such as, for instance, Possible solutions:
|
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.
Per discussion, should avoid using libc, since messing with the environment is inherently problematic.
base/file.jl
Outdated
@@ -578,21 +578,40 @@ end | |||
|
|||
else # !windows | |||
|
|||
# Based of musl __randname | |||
function _rand_string() | |||
r = Base.rand(UInt) # FIXME: https://git.musl-libc.org/cgit/musl/tree/src/temp/__randname.c |
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.
Any good ideas on how to get a random number here? Musl use time_ns
, but then mixes in two pointers as sources of randomness.
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.
Is there a particular reason we are avoiding Base.rand
?
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.
Even if we use Base.rand
, we might want to initialize our own seed since we don't want the caller to be able to override this, no?
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.
since we don't want the caller to be able to override this, no?
I don't think we care about the state of the rng. IIUC we just want a random seed that is not likely to be used by another process. This is why musl mixes in the two pointers to get some randomness in the higher bits, but we don't need to high quality randomness.
Is there a particular reason we are avoiding
Base.rand
?
Base.rand
is implemented through the stdlib Random
and thus we would add a hard-dependency edge. Otherwise I would just use Random.randstring
.
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 believe Libc.rand()
should provide suitable quality for this. It appears we can also use the same code everywhere now, rather than using separate, identical implementation for windows.
base/file.jl
Outdated
end | ||
String(buf) | ||
end | ||
|
||
# Obtain a temporary filename. | ||
function tempname(parent::AbstractString=tempdir(); cleanup::Bool=true) |
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.
We should use this implementation on Windows as well
I find it a bit odd we are trying to implement |
🤷 I read that as well and found it entertaining, I assume they want to discourage usage since there is the risk of running into collisions and |
OMG, can we finish this? |
xD If anyone want to pick this up, please go ahead. |
cda41d9
to
86e2ef4
Compare
Rebased and unified a bit, as requested by reviewers. |
Co-authored-by: Steven G. Johnson <[email protected]>
This was a confusingly-named function, since `tempname()` doesn't create a file (and is thus prone to race conditions) whereas `mkstemp()` creates a file, reserving that filename as used immediately.
Any reason not to use this also on Windows? |
Despite the PR title, this does unify much of the windows/posix divide. |
This is green, and I believe all reviewer concerns have been addressed. I'm going to add the |
Thanks Elliot for picking this up! |
Thank you Valentin and Elliot! |
Edit: I may be too tired or I linked the wrong reports. |
See comments at the end of #38879
We may want to revert this until #43597 is merged. This is likely quite destabilizing to CI. |
See comments at the end of #38879
Co-authored-by: Steven G. Johnson <[email protected]> Co-authored-by: Elliot Saba <[email protected]> Co-authored-by: Steven G. Johnson <[email protected]>
See comments at the end of JuliaLang#38879
Co-authored-by: Steven G. Johnson <[email protected]> Co-authored-by: Elliot Saba <[email protected]> Co-authored-by: Steven G. Johnson <[email protected]>
See comments at the end of JuliaLang#38879
Fixes #35785