-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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 Environment.GetEnvironmentVariables for Apple platforms using official API on iOS/tvOS/MacCatalyst #58161
Conversation
Tagging subscribers to this area: Issue DetailsNot for review yet, only trying CI
|
@@ -97,22 +89,57 @@ private static void EnsureEnvironmentCached() | |||
{ | |||
var results = new Dictionary<string, string>(); | |||
|
|||
foreach (string name in GetEnvironmentVariableNames()) | |||
IntPtr block = Interop.Sys.GetEnviron(); |
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.
This code is straight copy from NativeAOT.
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.
then I think it would be better to have it in shared location
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.
Generally I would agree.
I started with a minimal fix because I wanted to limit the impact for backporting to .NET 6 branch.
Then I moved it to System.Native based on chat with @akoeplinger (and I agree that it belongs there). Proper sharing of the code with NativeAOT will need few more changes and I wanted to validate the approach first before proceeding with that.
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.
Yeah I think this is fine for now, we can unify with NativeAOT in main later on.
cc @jkotas This will inevitably clash with NativeAOT. Ideally we'd want to share parts of the code but I am waiting for some feedback about the approach first. It may need to be backported to .NET 6 branch. |
22ee5be
to
33e5b5d
Compare
No worries. It is easy to fixup conflicts like this one. |
@@ -97,22 +89,57 @@ private static void EnsureEnvironmentCached() | |||
{ | |||
var results = new Dictionary<string, string>(); | |||
|
|||
foreach (string name in GetEnvironmentVariableNames()) | |||
IntPtr block = Interop.Sys.GetEnviron(); |
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.
Yeah I think this is fine for now, we can unify with NativeAOT in main later on.
9ba262c
to
3346036
Compare
Why not use it when it is available and avoid the memory leak from the other solution? |
|
It is not a public API on Apple device OSes, but I believe that it is de-facto public API on Apple desktop OSes. |
You are right, it seems to exist on the desktop headers. I incorrectly based the assumption on a 14-year old comment in the Mono code (https://github.com/dotnet/runtime/blame/3f61d42cdfc65cfa1822986a9d257f1558545c4d/src/mono/mono/metadata/icall.c#L6273-L6276). |
src/mono/System.Private.CoreLib/src/System/Environment.Unix.Mono.cs
Outdated
Show resolved
Hide resolved
src/mono/System.Private.CoreLib/src/System/Environment.Unix.Mono.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Alexander Köplinger <[email protected]>
Is it useful for ios apps to read their native environment ? Apple generally doesn't like it for security reasons, thats why a lot of these apis were removed. Wouldn't be better to return just the env variables defined by the user/set during the build ? |
Co-authored-by: Adeel Mujahid <[email protected]>
In some cases it is. There are some global variables like I would find it highly inconsistent that |
I am not sure that is the reason for the removal.
There's too many ways to set the environment variables (Info.plist files, |
/backport to release/6.0 |
Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/1173975336 |
@akoeplinger backporting to release/6.0 failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Implement mono_icall_get_environment_variable_names for Apple platforms using official API
Using index info to reconstruct a base tree...
M src/mono/mono/metadata/icall.c
Falling back to patching base and 3-way merge...
Auto-merging src/mono/mono/metadata/icall.c
CONFLICT (content): Merge conflict in src/mono/mono/metadata/icall.c
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Implement mono_icall_get_environment_variable_names for Apple platforms using official API
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
…ng official API (dotnet#58161) Move environment handling from Mono runtime to System.Native Fixes dotnet#58156 Co-authored-by: Alexander Köplinger <[email protected]> Co-authored-by: Adeel Mujahid <[email protected]>
…ng official API (#58161) (#58254) Move environment handling from Mono runtime to System.Native Fixes #58156 Co-authored-by: Filip Navara <[email protected]> Co-authored-by: Adeel Mujahid <[email protected]>
Fixes #58156