-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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-112970: Detect and use closefrom() on platforms where it is available #112969
gh-112970: Detect and use closefrom() on platforms where it is available #112969
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
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, 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>
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>
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! |
Thanks; I'll land this tomorrow. |
Thanks for the report and patch, @thesamesam. Thanks for the additional review, @serhiy-storchaka. |
Thank you folks! |
…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>
…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>
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).