-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
gh-94518: [_posixsubprocess] Replace variable validity flags with reserved values #94687
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
gh-94518: [_posixsubprocess] Replace variable validity flags with reserved values #94687
Conversation
This change has no user-visible effect so no NEWS entry is required. |
@tiran Done (initially I've thought this change is invisible to users so skipped it). |
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 like this PR :)
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
When we query `groups_list` size using `PySequence_Size()`, we get -1 for non-lists. It returns an ability to pass an empty list to `setgroups()` that is valid but treated as a no-op: > If `size` is zero, `list` is not modified, but the total number of > supplementary group IDs for the process is returned. This allows the > caller to determine the size of a dynamically allocated list to be > used in a further call to getgroups(). > > - <https://linux.die.net/man/2/setgroups>
`num_groups < 0` already implies `groups_list == Py_None` because `num_groups = PySequence_Size(groups_list)` does this check for us. Also, it guarantees that `groups_list == Py_None` <=> `groups == NULL`; it allows to replace `groups_list != Py_None ? groups : NULL` with just `groups` in a call of `do_fork_exec()`.
For some reason, Stacktrace
However, this is fixed by excluding a zero from the comparison:
For Bedevere: I have made the requested changes; please review again. For correct jump from Mentioned to this message instead of the following Bedevere's one: @gpshead. |
Thanks for making the requested changes! @gpshead: please review the changes made to this pull request. |
We are currently busy with 3.11 release. It may take until 3.11.0 final before we come back to this patch. It's definitely on the list for 3.12. |
Todo: replace I'll do it in a separate PR because both this PR and gh-94519 are already big enough to clobber them with extra details. |
@tiran could you review and possibly merge this PR please? It's an implementation of your proposal #94519 (comment) created as a separate PR to preserve diffs of both PRs readable. |
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 for doing this!
Thank you for merging, Gregory! |
Currently,
_posixsubprocess.c
uses group and user ids together with flags of whether the corrsponding variables were initialized. However such an implicit "either initialized or look somewhere else" confuses both a reader (another mental connection to constantly track between functions) and a compiler (warnings on potentially uninitialized variables). Instead, we can utilize a special group/user id as a flag value defined by POSIX but uses nowhere else. Namely:gid
:call_setgid = False
→gid = -1
uid
:call_setuid = False
→uid = -1
groups
:call_setgroups = False
→groups = NULL
(obtained with(groups_list != Py_None) ? groups : NULL
)This PR is required for gh-94519.
PS.: @tiran I applied your suggestion from gh-94519 as this, separate PR to keep that one limited in scope and reviewable.
_posixsubprocess.fork_exec
to Argument Clinic #94518