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

bpo-32862: Make os.dup2(fd, fd) a no-op for valid fd #5713

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

izbyshev
Copy link
Contributor

@izbyshev izbyshev commented Feb 17, 2018

os.dup2(fd, fd, inheritable=True) never changed fd inheritability,
but with inheritable=False the function might fail or change it
in an inconsistent manner depending on the platform.

https://bugs.python.org/issue32862

os.dup2(fd, fd, inheritable=True) never changed fd inheritability,
but with inheritable=False the function might fail or change it
in an inconsistent manner depending on the platform.
# dup2(fd, fd) must have no effect for a valid fd
# Issue #26935: Avoid failure due to a bionic bug
# in old Android.
if (not hasattr(sys, 'getandroidapilevel') or
Copy link
Contributor

@ZackerySpytz ZackerySpytz Sep 7, 2019

Choose a reason for hiding this comment

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

I think this new test code should be placed in a new method. The Android checks should be put in a @unittest.skip* decorator.

@@ -741,6 +741,9 @@ as internal buffering of data.
<fd_inheritance>` by default or non-inheritable if *inheritable*
is ``False``.

If *fd* is valid and equal to *fd2*, this function has no effect
Copy link
Contributor

@ZackerySpytz ZackerySpytz Sep 7, 2019

Choose a reason for hiding this comment

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

There should be a versionchanged directive.

Copy link
Member

@vstinner vstinner Jan 16, 2020

Choose a reason for hiding this comment

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

"this function has no effect": that's wrong, it does validate the FD which is a legit usage of this function. I would rather remove this sentence.

@@ -3102,6 +3102,18 @@ def test_dup2(self):
self.assertEqual(os.dup2(fd, fd3, inheritable=False), fd3)
self.assertFalse(os.get_inheritable(fd3))

# dup2(fd, fd) must have no effect for a valid fd
# Issue #26935: Avoid failure due to a bionic bug
Copy link
Contributor

@ZackerySpytz ZackerySpytz Sep 7, 2019

Choose a reason for hiding this comment

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

Suggested change
# Issue #26935: Avoid failure due to a bionic bug
# bpo-26935: Avoid failure due to a bionic bug

I believe it's preferred to use bpo-n in code comments.

@csabella csabella requested review from vstinner and benjaminp Jan 16, 2020
@@ -741,6 +741,9 @@ as internal buffering of data.
<fd_inheritance>` by default or non-inheritable if *inheritable*
is ``False``.

If *fd* is valid and equal to *fd2*, this function has no effect
Copy link
Member

@vstinner vstinner Jan 16, 2020

Choose a reason for hiding this comment

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

"this function has no effect": that's wrong, it does validate the FD which is a legit usage of this function. I would rather remove this sentence.

@@ -3102,6 +3102,18 @@ def test_dup2(self):
self.assertEqual(os.dup2(fd, fd3, inheritable=False), fd3)
self.assertFalse(os.get_inheritable(fd3))

# dup2(fd, fd) must have no effect for a valid fd
Copy link
Member

@vstinner vstinner Jan 16, 2020

Choose a reason for hiding this comment

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

Please move this test into a separated method and emit somehow a SkipTest exception to record that the test is skipped on old Android versions.

@@ -8041,7 +8041,7 @@ os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable)
res = fd2; // msvcrt dup2 returns 0 on success.

Copy link
Member

@vstinner vstinner Jan 16, 2020

Choose a reason for hiding this comment

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

Please document somewhere the rationale for "fd != fd2" tests with a reference to "bpo-32862".

@bedevere-bot
Copy link

bedevere-bot commented Jan 16, 2020

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@github-actions
Copy link

github-actions bot commented Aug 15, 2022

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting changes stale Stale PR or inactive for long period of time.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants