public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/110133] New: System error message should ideally use strerror_r over strerror
@ 2023-06-05 22:35 romain.geissler at amadeus dot com
2023-06-05 23:21 ` [Bug libstdc++/110133] " redi at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: romain.geissler at amadeus dot com @ 2023-06-05 22:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110133
Bug ID: 110133
Summary: System error message should ideally use strerror_r
over strerror
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: romain.geissler at amadeus dot com
Target Milestone: ---
Hi,
Checking the source code, it seems that the underlying implementation of
generic_category/system_category message() function uses this code:
return string(strerror(i));
which happens to be thread safe when targetting glibc, but that remains an
implementation details, and not necessarily all libc implement this behavior.
Ideally strerror_r shall be used when available.
Note that unfortunately, glibc has two strerror_r implementations, with a
different return type and thus a different behavior. As an example to cope with
both behavior libc++ choose to use this overloading mechanism:
https://github.com/llvm/llvm-project/blob/2bd82c5462d511f1e58e7d9a4dcd5628cd16a32d/libcxx/src/system_error.cpp#LL114C8-L114C21
In the gcc project, the maintainers of libgfortran have implemented a similar
change this way:
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=723553bdc16695ecc686a2ffdff6d15bd600b676;hp=62f9aedcd0a97001f290a1c13fa66efd207a23cc
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/110133] System error message should ideally use strerror_r over strerror
2023-06-05 22:35 [Bug libstdc++/110133] New: System error message should ideally use strerror_r over strerror romain.geissler at amadeus dot com
@ 2023-06-05 23:21 ` redi at gcc dot gnu.org
2023-06-05 23:23 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2023-06-05 23:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110133
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2023-06-05
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Romain Geissler from comment #0)
> Ideally strerror_r shall be used when available.
Or strerrordesc_np.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/110133] System error message should ideally use strerror_r over strerror
2023-06-05 22:35 [Bug libstdc++/110133] New: System error message should ideally use strerror_r over strerror romain.geissler at amadeus dot com
2023-06-05 23:21 ` [Bug libstdc++/110133] " redi at gcc dot gnu.org
@ 2023-06-05 23:23 ` redi at gcc dot gnu.org
2023-11-04 8:44 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2023-06-05 23:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110133
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I've also considered using strerror_l (with newlocale and uselocale), so that
the strings are not affected by the current locale.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/110133] System error message should ideally use strerror_r over strerror
2023-06-05 22:35 [Bug libstdc++/110133] New: System error message should ideally use strerror_r over strerror romain.geissler at amadeus dot com
2023-06-05 23:21 ` [Bug libstdc++/110133] " redi at gcc dot gnu.org
2023-06-05 23:23 ` redi at gcc dot gnu.org
@ 2023-11-04 8:44 ` cvs-commit at gcc dot gnu.org
2023-12-06 14:44 ` cvs-commit at gcc dot gnu.org
2023-12-06 14:45 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-04 8:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110133
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
https://gcc.gnu.org/g:51f94778b45514992a716b0b2d7a87244e6f0018
commit r14-5123-g51f94778b45514992a716b0b2d7a87244e6f0018
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Fri Nov 3 13:59:48 2023 +0000
libstdc++: Use strerror_r in std::generic_category()::message(int)
[PR110133]
Use strerror_r instead of strerror when available, due to the latter not
being thread-safe. This is complicated by Glibc providing a GNU-specific
strerror_r which is not compatible with POSIX strerror_r, so we need to
dispatch on the return type.
We can use the recently-added std::string::__resize_and_overwrite to
write directly into the string buffer when possible. Because we estimate
the initial buffer size we might end up with excess capacity in the
returned std::string. We can slightly tweak the std::system_error
constructors to make use of that excess capacity, so that in some cases
we require fewer allocations to construct the std::system_error::what()
string.
libstdc++-v3/ChangeLog:
PR libstdc++/110133
* include/std/system_error (system_error::system_error): Group
arguments so that concatenation can reuse rvalue's capacity.
* src/c++11/system_error.cc (strerror_string): New function.
[_GLIBCXX_HAVE_STRERROR_R] (use_strerror_result): New functions.
(generic_error_category::message): Use strerror_string.
(system_error_category::message): Likewise.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/110133] System error message should ideally use strerror_r over strerror
2023-06-05 22:35 [Bug libstdc++/110133] New: System error message should ideally use strerror_r over strerror romain.geissler at amadeus dot com
` (2 preceding siblings ...)
2023-11-04 8:44 ` cvs-commit at gcc dot gnu.org
@ 2023-12-06 14:44 ` cvs-commit at gcc dot gnu.org
2023-12-06 14:45 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-06 14:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110133
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:
https://gcc.gnu.org/g:ca233ac9ba085e2acd385bda6a778684a0c96694
commit r13-8129-gca233ac9ba085e2acd385bda6a778684a0c96694
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Fri Nov 3 13:59:48 2023 +0000
libstdc++: Use strerror_r in std::generic_category()::message(int)
[PR110133]
Use strerror_r instead of strerror when available, due to the latter not
being thread-safe. This is complicated by Glibc providing a GNU-specific
strerror_r which is not compatible with POSIX strerror_r, so we need to
dispatch on the return type.
Because we estimate the initial std::string buffer size we might end up
with excess capacity in the returned std::string. We can slightly tweak
the std::system_error constructors to make use of that excess capacity,
so that in some cases we require fewer allocations to construct the
std::system_error::what() string.
libstdc++-v3/ChangeLog:
PR libstdc++/110133
* include/std/system_error (system_error::system_error): Group
arguments so that concatenation can reuse rvalue's capacity.
* src/c++11/system_error.cc (strerror_string): New function.
[_GLIBCXX_HAVE_STRERROR_R] (use_strerror_result): New functions.
(generic_error_category::message): Use strerror_string.
(system_error_category::message): Likewise.
(cherry picked from commit 51f94778b45514992a716b0b2d7a87244e6f0018)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/110133] System error message should ideally use strerror_r over strerror
2023-06-05 22:35 [Bug libstdc++/110133] New: System error message should ideally use strerror_r over strerror romain.geissler at amadeus dot com
` (3 preceding siblings ...)
2023-12-06 14:44 ` cvs-commit at gcc dot gnu.org
@ 2023-12-06 14:45 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2023-12-06 14:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110133
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Target Milestone|--- |13.3
Resolution|--- |FIXED
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 13.3, I don't think I'll backport it further.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-12-06 14:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-05 22:35 [Bug libstdc++/110133] New: System error message should ideally use strerror_r over strerror romain.geissler at amadeus dot com
2023-06-05 23:21 ` [Bug libstdc++/110133] " redi at gcc dot gnu.org
2023-06-05 23:23 ` redi at gcc dot gnu.org
2023-11-04 8:44 ` cvs-commit at gcc dot gnu.org
2023-12-06 14:44 ` cvs-commit at gcc dot gnu.org
2023-12-06 14:45 ` redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).