-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Implement managed SegmentCommandLine #82883
Conversation
Tagging subscribers to this area: @dotnet/area-system-runtime |
//--------------------------------------------------------------------- | ||
// Splits a command line into argc/argv lists, using the VC7 parsing rules. | ||
// | ||
// This functions interface mimics the CommandLineToArgvW api. | ||
// | ||
//--------------------------------------------------------------------- | ||
// NOTE: Implementation-wise, once every few years it would be a good idea to | ||
// compare this code with the C runtime library's parse_cmdline method, | ||
// which is in vctools\crt\crtw32\startup\stdargv.c. (Note we don't | ||
// support wild cards, and we use Unicode characters exclusively.) | ||
// We are up to date as of ~6/2005. | ||
//--------------------------------------------------------------------- | ||
|
||
// The C# version is ported from C++ version in coreclr | ||
// The behavior mimics what MSVCRT does before main, | ||
// which is slightly different with CommandLineToArgvW |
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 don't think these comments are useful as written, especially since we're adding this specifically to not be in sync with MSVC's CommandLineToArgvW
API.
//--------------------------------------------------------------------- | ||
// Splits a command line into argc/argv lists, using the VC7 parsing rules. | ||
// | ||
// This functions interface mimics the CommandLineToArgvW api. | ||
// | ||
//--------------------------------------------------------------------- | ||
// NOTE: Implementation-wise, once every few years it would be a good idea to | ||
// compare this code with the C runtime library's parse_cmdline method, | ||
// which is in vctools\crt\crtw32\startup\stdargv.c. (Note we don't | ||
// support wild cards, and we use Unicode characters exclusively.) | ||
// We are up to date as of ~6/2005. | ||
//--------------------------------------------------------------------- | ||
|
||
// The C# version is ported from C++ version in coreclr | ||
// The behavior mimics what MSVCRT does before main, | ||
// which is slightly different with CommandLineToArgvW |
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.
//--------------------------------------------------------------------- | |
// Splits a command line into argc/argv lists, using the VC7 parsing rules. | |
// | |
// This functions interface mimics the CommandLineToArgvW api. | |
// | |
//--------------------------------------------------------------------- | |
// NOTE: Implementation-wise, once every few years it would be a good idea to | |
// compare this code with the C runtime library's parse_cmdline method, | |
// which is in vctools\crt\crtw32\startup\stdargv.c. (Note we don't | |
// support wild cards, and we use Unicode characters exclusively.) | |
// We are up to date as of ~6/2005. | |
//--------------------------------------------------------------------- | |
// The C# version is ported from C++ version in coreclr | |
// The behavior mimics what MSVCRT does before main, | |
// which is slightly different with CommandLineToArgvW | |
// Parse command line arguments using the rules documented at | |
// https://learn.microsoft.com/cpp/cpp/main-function-command-line-args#parsing-c-command-line-arguments | |
// | |
// CommandLineToArgvW API cannot be used here since | |
// it has slightly different behavior. |
Simplify this comment
You can access the method via private reflection (call |
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.
Thanks!
Known failure according to the Build Analysis |
* Implement managed version of SegmentCommandLine * Remove P/Invoke for CommandLineToArgv * Update parsing to latest UCRT * Add test and fix trailing space in command * Fix test cases
var method = typeof(Environment).GetMethod("SegmentCommandLine", BindingFlags.Static | BindingFlags.NonPublic); | ||
Assert.NotNull(method); | ||
|
||
var span = cmdLine.AsSpan(); // Workaround |
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.
Here is workaround for xUnit issue xunit/xunit#1969
Fixes #77644
Ported from the code deleted by #71111
How should we test it? Can we mark the method
internal
and test in some unit test?