gh-112970: Detect and use closefrom() on platforms where it is available#112969
Merged
erlend-aasland merged 4 commits intopython:mainfrom Dec 12, 2023
Merged
gh-112970: Detect and use closefrom() on platforms where it is available#112969erlend-aasland merged 4 commits intopython:mainfrom
erlend-aasland merged 4 commits intopython:mainfrom
Conversation
47995c4 to
179dd3c
Compare
glibc-2.34 implements closefrom(3) using the same semantics as on BSD. Check for closefrom in configure and use the check result in fileutils.c rather than hardcoding a FreeBSD check (which was wrong for other BSDs anyway). Signed-off-by: Sam James <sam@gentoo.org>
fe2d4ed to
bbb3254
Compare
erlend-aasland
approved these changes
Dec 11, 2023
Contributor
erlend-aasland
left a comment
There was a problem hiding this comment.
Thanks, this makes sense.
Misc/NEWS.d/next/Library/2023-12-11-16-13-15.gh-issue-112970.87jmKP.rst
Outdated
Show resolved
Hide resolved
Signed-off-by: Sam James <sam@gentoo.org>
Contributor
|
I noticed that
We should probably explicitly tell the compiler that we're throwing away the return value, to avoid possible future compiler warnings ( diff --git a/Python/fileutils.c b/Python/fileutils.c
index 9d12bc89c9..05cd70cdd0 100644
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -2922,7 +2922,7 @@ _Py_closerange(int first, int last)
#ifdef USE_CLOSEFROM
if (last >= sysconf(_SC_OPEN_MAX)) {
/* Any errors encountered while closing file descriptors are ignored */
- closefrom(first);
+ (void)closefrom(first);
}
else
#endif /* USE_CLOSEFROM */
|
There are two variants of closefrom, one returns void, but another returns int, so let's cast the return value to void to explicitly discard it to avoid -Wunused-result warnings. Signed-off-by: Sam James <sam@gentoo.org>
Contributor
Author
|
Ah, my bad for forgetting about that. I did a bunch of porting for packages getting this wrong a few years ago when glibc-2.34 came out, and forgot about it since. Done, thanks! |
erlend-aasland
approved these changes
Dec 11, 2023
Contributor
|
Thanks; I'll land this tomorrow. |
serhiy-storchaka
approved these changes
Dec 12, 2023
Contributor
|
Thanks for the report and patch, @thesamesam. Thanks for the additional review, @serhiy-storchaka. |
Contributor
Author
|
Thank you folks! |
aisk
pushed a commit
to aisk/cpython
that referenced
this pull request
Feb 11, 2024
…2969) glibc-2.34 implements closefrom(3) using the same semantics as on BSD. Check for closefrom() in configure and use the check result in fileutils.c, rather than hardcoding a FreeBSD check. Some implementations of closefrom() return an int. Explicitly discard the return value by casting it to void, to avoid future compiler warnings. Signed-off-by: Sam James <sam@gentoo.org>
Glyphack
pushed a commit
to Glyphack/cpython
that referenced
this pull request
Sep 2, 2024
…2969) glibc-2.34 implements closefrom(3) using the same semantics as on BSD. Check for closefrom() in configure and use the check result in fileutils.c, rather than hardcoding a FreeBSD check. Some implementations of closefrom() return an int. Explicitly discard the return value by casting it to void, to avoid future compiler warnings. Signed-off-by: Sam James <sam@gentoo.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
glibc-2.34 implements closefrom(3) using the same semantics as on BSD. Check for closefrom in configure and use the check result in fileutils.c rather than hardcoding a FreeBSD check (which was wrong for other BSDs anyway).