Skip to content
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

Remove redundant P/Invoke-s in S.D.Process on Apple platforms #54273

Merged

Conversation

MaximLipnin
Copy link
Contributor

Contributes to #47533.

This PR excludes only P/Invoke to SystemNative_ConfigureTerminalForChildProcess which is mentioned in #47533.

But, as Alexander mentioned, since all the native console methods in src/libraries/Native/Unix/System.Native/pal_console.c are excluded from the build on Apple platforms, it'd make sense to update the respective part of managed code as well.

@ghost
Copy link

ghost commented Jun 16, 2021

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

Issue Details

Contributes to #47533.

This PR excludes only P/Invoke to SystemNative_ConfigureTerminalForChildProcess which is mentioned in #47533.

But, as Alexander mentioned, since all the native console methods in src/libraries/Native/Unix/System.Native/pal_console.c are excluded from the build on Apple platforms, it'd make sense to update the respective part of managed code as well.

Author: MaximLipnin
Assignees: -
Labels:

area-System.Diagnostics.Process

Milestone: -

@@ -19,7 +19,10 @@ public partial class Process : IDisposable
private static volatile bool s_initialized;
private static readonly object s_initializedGate = new object();
private static readonly ReaderWriterLockSlim s_processStartLock = new ReaderWriterLockSlim();

#if !TARGET_MACCATALYST && !TARGET_IOS && !TARGET_TVOS
Copy link
Member

Choose a reason for hiding this comment

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

nit: is there a simpler way of saying that given target is from apple but it's not macOS?

Copy link
Contributor

Choose a reason for hiding this comment

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

src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems: <IsiOSLike Condition="'$(TargetsMacCatalyst)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true'">true</IsiOSLike> ?

Copy link
Member

Choose a reason for hiding this comment

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

Also, you can avoid the ifdefs in the .cs files by moving the ConfigureTerminalForChildProcesses support into a separate .cs file, defining partial methods for it here, and including the .cs file only for targets that need it.

Copy link
Member

Choose a reason for hiding this comment

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

Another alternative to solve this problem is to define a dummy method in the shim to make it link succesfully. This strategy is used in number of places today, e.g. https://github.com/dotnet/runtime/blob/main/src/libraries/Native/Unix/System.Native/pal_interfaceaddresses.c#L571

@@ -1051,26 +1050,9 @@ private static void OnSigChild(int reapAll)
/// </summary>
internal static void ConfigureTerminalForChildProcesses(int increment)
Copy link
Member

Choose a reason for hiding this comment

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

I do not think you need the ConfigureTerminalForChildProcesses / ConfigureTerminalForChildProcessesInner split. ConfigureTerminalForChildProcesses can be the partial method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ConfigureTerminalForChildProcesses method has a modifier so there can be error CS8795: Partial method 'Process.ConfigureTerminalForChildProcesses(int)' must have an implementation part because it has accessibility modifiers.
Removing the modifier leads to src/System/Diagnostics/ProcessWaitState.Unix.cs(575,33): error CS0122: 'Process.ConfigureTerminalForChildProcesses(int)' is inaccessible due to its protection level

Copy link
Member

Choose a reason for hiding this comment

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

Hmmm, that's annoying.

@MaximLipnin MaximLipnin marked this pull request as ready for review June 18, 2021 10:09
@marek-safar marek-safar merged commit f891033 into dotnet:main Jun 21, 2021
@adamsitnik adamsitnik added this to the 6.0.0 milestone Jun 21, 2021
@MaximLipnin MaximLipnin deleted the remove_redundant_pinvokes_in_S.D.Process branch June 21, 2021 07:26
@ghost ghost locked as resolved and limited conversation to collaborators Jul 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants