Skip to content
Snippets Groups Projects
Commit 51f94778 authored by Jonathan Wakely's avatar Jonathan Wakely
Browse files

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.
parent 6933c05a
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment