This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add Path.TryGetTempPath() #17097
Closed
Closed
Add Path.TryGetTempPath() #17097
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
75c1b14
use existing api
MarcoRossignoli f99a46f
wip
MarcoRossignoli a024058
wip
MarcoRossignoli 5ef6494
wip
MarcoRossignoli 81bbed6
address PR feedback
MarcoRossignoli 54d0ee2
non allocating string
MarcoRossignoli 2b23a97
remove unuseful checked
MarcoRossignoli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,8 @@ public int Length | |
|
||
public int Capacity => _chars.Length; | ||
|
||
public Span<char> Span => _chars; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have AsSpan() that you should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need a Span not a ReadOnlySpan to pass to api, right?or you mean create a custom modifiable Span and after Append? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want the ref char (which you do), you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok TYVM |
||
|
||
public void EnsureCapacity(int capacity) | ||
{ | ||
if (capacity > _chars.Length) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@JeremyKuhne @Anipik to avoid allocation of string i need to use
GetEnvironmentVariable(string lpName, Span<char> lpValue)
. I've exposed internal span and i'm pretty sure you don't want this. Can you help me with overload forGetEnvironmentVariable(string lpName, ref char lpTempFileName, int size)
orGetEnvironmentVariable(string lpName, ValueStringBuilder builder)
i don't find a way to castref char
tochar*
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.
You need to use
fixed
to get the address (char*
) of a ref char. If you follow the code down you'll see:What you should really do here is rewrite
GetEnvironmentVariableCoreHelper
to take a ValueStringBuilder. Take a look at the changes I made in dotnet/corefx@050bc33 for examples.char*
is equivalent toref char
in P\Invoke signatures. As such, the helper in Win32Native can just be removed and the Pinvoke can be changed to take aref char
as everything is calling it with aSpan
. You can avoid having to use the fixed statement that way. (Note that there is currently an issue in CoreRT that requires manually using fixed- if you look at P\Invokes in the shared folder you'll see#ifdef
s that do it both ways.)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.
Ok TYVM
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.
You will have issues with making the same code build with CoreRT. The environment stuff is factored differently there. We may need a (public) no-allocation API to read the environment to make this work well. No-allocation environment access is likely a lot more useful than no-allocation temporary path generator.
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.
Ah yes, I forgot that while the P/Invoke isn't shared, this is. We can do the same hack on the P/Invoke there that I mentioned above no? (e.g. ifdef and manually pin the ref char)
There isn't a need for it to be public to unblock this, is there? I agree that we should have a public API for it eventually.
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 be using the same patterns internally as we are using for our public APIs. If the
Try*
pattern that returns bool and Span does not work for out internal use, it is unlikely going to work well for our users as well. This suggests that the pattern we are using for the public API is wrong.This applies to both GetEnvironmentVariable or GetTempPath APIs.
I think we need to step back and do work on the API design. We may need to expose the ValueStringBuilder as public to make this work well.
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.
@JeremyKuhne i go on with above idea(paying attention to corert) right? If i success with this could help also on new environment api.
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.
Sorry @jkotas i've got a delay on refresh messages, i read your comment now. I wait your decision to understand how go on!I stay here and "listen". IMHO public ValueStringBuilder will be very useful.
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.
@jkotas I'll open an issue on ValueStringBuilder and link to it. While I think we definitely need VSB type APIs, I'm not confident that not having the existing
Try*
andSpan
pattern becomes moot with said APIs. What if you want to write to fixed size span and don't want it grabbing from array pool? Does it make sense to have an option on ValueStringBuilder that doesn't allow it to grow? I'll discuss it in the issue.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.
https://github.com/dotnet/corefx/issues/28379