Skip to content

Conversation

@pedrobsaila
Copy link
Contributor

Fixes #69230

@ghost ghost added area-System.IO community-contribution Indicates that the PR has been added by a community member labels May 13, 2022
@ghost
Copy link

ghost commented May 13, 2022

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #69230

Author: pedrobsaila
Assignees: -
Labels:

area-System.IO

Milestone: -

@AaronRobinsonMSFT
Copy link
Member

/cc @dotnet/interop-contrib

@jeffhandley jeffhandley added the needs-author-action An issue or pull request that requires more info or actions from the author. label Jun 30, 2022
@ghost ghost removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Jul 8, 2022
@stephentoub
Copy link
Member

I'm not clear on why this change is so involved. If the goal here is just to use an initial stackalloc, why isn't it something more like main...stephentoub:runtime:readlinkstackalloc ?

@pedrobsaila
Copy link
Contributor Author

pedrobsaila commented Jul 8, 2022

I'm not clear on why this change is so involved. If the goal here is just to use an initial stackalloc, why isn't it something more like main...stephentoub:runtime:readlinkstackalloc ?

see this discussion :

#69335 (comment)

Rent may override last return (external code is depending on ReadLink last return to validate for example whether the file is really a symbolic link). So we need to relocate all validations done outside ReadLink scope and do it inside. We should also take into account that some callers do not care about validation, they want just the result.

@stephentoub
Copy link
Member

Rent may override last return (external code is depending on ReadLink last return to validate for example whether the file is really a symbolic link)

Isn't that a separate issue from the stackalloc, and one that already exists?

Addressing that also shouldn't require lots of additional changes: the original error code can just be stored into a local with Marshal.GetLastPInvokeError and then restored as the very last thing done with Marshal.SetLastPInvokeError.

@jkotas
Copy link
Member

jkotas commented Jul 8, 2022

Addressing that also shouldn't require lots of additional changes: the original error code can just be stored into a local with Marshal.GetLastPInvokeError and then restored as the very last thing done with Marshal.SetLastPInvokeError.

Some of the callers ignore all errors (including the unexpected errors) and assumed that null means that the link does not exist. The earlier version of this PR tried to address this by turning unexpected errors into exceptions. @pedrobsaila Is it correct?

(It is fine to not address this issue as part of this PR.)

@pedrobsaila
Copy link
Contributor Author

Addressing that also shouldn't require lots of additional changes: the original error code can just be stored into a local with Marshal.GetLastPInvokeError and then restored as the very last thing done with Marshal.SetLastPInvokeError.

Some of the callers ignore all errors (including the unexpected errors) and assumed that null means that the link does not exist. The earlier version of this PR tried to address this by turning unexpected errors into exceptions. @pedrobsaila Is it correct?

(It is fine to not address this issue as part of this PR.)

it is correct

@stephentoub
Copy link
Member

it is correct

Thanks. Then yeah, sounds like those call sites should be fixed separately after this PR goes in.

internal static string? ReadLink(ReadOnlySpan<char> path)
{
int outputBufferSize = 1024;
const int stackBufferSize = 256;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: StackBufferSize

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@stephentoub stephentoub merged commit 9701c5c into dotnet:main Jul 11, 2022
@jkotas
Copy link
Member

jkotas commented Jul 11, 2022

Thanks. Then yeah, sounds like those call sites should be fixed separately after this PR goes in.

Opened #71970

@ghost ghost locked as resolved and limited conversation to collaborators Aug 11, 2022
@pedrobsaila pedrobsaila deleted the 69230 branch November 1, 2022 19:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.IO community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve Interop.Sys.ReadLink loop with stackalloc

9 participants