This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] New std::string implementation


This is the long-awaited ABI break for std::string, replacing our
venerable Copy-On-Write implementation with a C++11-conforming
Small-String-Optimization implementation (based on Paolo's vstring).

The gist of it is adding a second complete std::string implementation
that is tagged with abi_tag("cxx11") so it mangles differently (as
already done for std::list and std::ios_base::failure).

Because strings are used pervasively through the library loads of
functions need to be compiled twice, using the old and new string, so
that both versions are exported from the library. That involved loads
of shuffling things around within the libstdc++-v3/src directory so
the right definitions could be included twice by different files and
compiled with the right -std option and the right value of the
_GLIBCXX_USE_CXX11_ABI macro.

The stringstream classes are so tightly coupled to std::string that I
just added the tag to them as well.

The exception to the "compile it twice" rule are (fittingly) the
exception classes. Because exceptions cross function/API/library
boundaries without being "visible" to the linker simply adding the
abi_tag to the exception types would have caused runtime failures
where one module throws an old std::runtime_error and the code trying
to catch it only handles the new std::runtime_error[abi:cxx11] type.

So in order to avoid changing the exception types I have devised a
horrible hack where the exception classes always use the old COW
std::string type, even when the rest of the program doesn't. This is
done by ensuring all constructing/copying/destroying of the exception
classes is done in a context where the old std::string ABI is in
effect. In practice that means the relevant functions are non-inline
and exported from the library.

This patch doesn't include all the testsuite fixes, which I'll send
separately. We have lots of tests for features that are true for COW
strings but not SSO strings so they need adjusting.

There are also some failures in 22_locale and 28_regex which I'm
investigating (with all the duplicated symbols and shuffling of code
in the locale instantiations I'm amazed there arren't more failures!)

This change *doesn't* resolve PRs 54354 and 60396, they require
abi-tagging the time_get facet and ensuring that std::locale objects
contain both the old and new time_get facets. That will require even
more black magic than is usually involved with std::locale changes,
but I still hope to have it done before stage 1 ends, if I can fix the
testsuite problems I'm seeing now.

Tested on x86_64-linux and powerpc64-linux, also with
--disable-libstdcxx11-abi to verify all the incompatible changes can
be disabled if needed.

I plan to commit this today or tomorrow, but I'll check with Jakub and
Richi if they'd prefer I wait until Sunday morning, to avoid causing
massive churn for everyone else trying to get things in before stage 1
ends.

Attachment: patch.txt.gz
Description: application/gzip


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]