[libcxx] Use runtime rather then compile-time glibc version check

glibc supports versioning, so it's possible to build against older
version and run against newer version. This is sometimes relied on
in practice, e.g. in Fuchsia build we build against older sysroot
(equivalent to Ubuntu Trusty) to cover the broadest possible range
of host systems, but that doesn't necessarily match the system that
binary is going to run on which may have newer version, in which case
the compile test used in curr_symbol is going to fail. Using runtime
check is more reliable. This is a follow up to D56702 which addressed
one instance, this patch addresses all of the remaining ones.

Differential Revision: https://reviews.llvm.org/D88188
This commit is contained in:
Petr Hosek 2020-09-23 15:53:45 -07:00
parent 35cb45c533
commit 80ef4126b1
7 changed files with 32 additions and 47 deletions
libcxx/test
std/localization/locale.categories
category.monetary
locale.money.get/locale.money.get.members
locale.money.put/locale.money.put.members
locale.moneypunct.byname
facet.numpunct/locale.numpunct.byname
support

View File

@ -54,10 +54,9 @@ public:
// this function converts the spaces in string inputs to that character if need
// be.
static std::wstring convert_thousands_sep(std::wstring const& in) {
#ifndef TEST_GLIBC_PREREQ
#define TEST_GLIBC_PREREQ(x, y) 0
#endif
#if TEST_GLIBC_PREREQ(2,27)
#if defined(_CS_GNU_LIBC_VERSION)
if (glibc_version_less_than("2.27"))
return in;
std::wstring out;
unsigned I = 0;
bool seen_decimal = false;

View File

@ -54,10 +54,9 @@ public:
// this function converts the spaces in string inputs to that character if need
// be.
static std::wstring convert_thousands_sep(std::wstring const& in) {
#ifndef TEST_GLIBC_PREREQ
#define TEST_GLIBC_PREREQ(x, y) 0
#endif
#if TEST_GLIBC_PREREQ(2,27)
#if defined(_CS_GNU_LIBC_VERSION)
if (glibc_version_less_than("2.27"))
return in;
std::wstring out;
unsigned I = 0;
bool seen_num_start = false;

View File

@ -61,20 +61,6 @@ public:
: std::moneypunct_byname<wchar_t, true>(nm, refs) {}
};
#if defined(_CS_GNU_LIBC_VERSION)
static bool glibc_version_less_than(char const* version) {
std::string test_version = std::string("glibc ") + version;
size_t n = confstr(_CS_GNU_LIBC_VERSION, nullptr, (size_t)0);
char *current_version = new char[n];
confstr(_CS_GNU_LIBC_VERSION, current_version, n);
bool result = strverscmp(current_version, test_version.c_str()) < 0;
delete[] current_version;
return result;
}
#endif
int main(int, char**)
{
{

View File

@ -110,15 +110,12 @@ int main(int, char**)
}
// GLIBC 2.23 uses '.' as the decimal point while other C libraries use ','
// GLIBC 2.27 corrects this
#ifndef TEST_GLIBC_PREREQ
#define TEST_GLIBC_PREREQ(x, y) 0
#endif
#if !defined(TEST_HAS_GLIBC) || TEST_GLIBC_PREREQ(2, 27)
#if defined(_CS_GNU_LIBC_VERSION)
const char sep = glibc_version_less_than("2.27") ? '.' : ',';
const wchar_t wsep = glibc_version_less_than("2.27") ? L'.' : L',';
#else
const char sep = ',';
const wchar_t wsep = L',';
#else
const char sep = '.';
const wchar_t wsep = L'.';
#endif
{
Fnf f(LOCALE_ru_RU_UTF_8, 1);

View File

@ -103,11 +103,8 @@ int main(int, char**)
assert(f.thousands_sep() == ' ');
}
// The below tests work around GLIBC's use of U202F as mon_thousands_sep.
#ifndef TEST_GLIBC_PREREQ
#define TEST_GLIBC_PREREQ(x, y) 0
#endif
#if defined(TEST_HAS_GLIBC) && TEST_GLIBC_PREREQ(2, 27)
const wchar_t fr_sep = L'\u202F';
#if defined(_CS_GNU_LIBC_VERSION)
const wchar_t fr_sep = glibc_version_less_than("2.27") ? L' ' : L'\u202F';
#else
const wchar_t fr_sep = L' ';
#endif
@ -123,18 +120,15 @@ int main(int, char**)
// and U002E as mon_decimal_point.
// TODO: Fix thousands_sep for 'char'.
// related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=16006
#ifndef TEST_HAS_GLIBC
#if defined(_CS_GNU_LIBC_VERSION)
const char sep = ' ';
const wchar_t wsep = L' ';
#elif TEST_GLIBC_PREREQ(2, 27)
// FIXME libc++ specifically works around \u00A0 by translating it into
// a regular space.
const char sep = ' ';
const wchar_t wsep = L'\u202F';
const wchar_t wsep = glibc_version_less_than("2.27") ? L'\u00A0' : L'\u202F';
#else
const char sep = ' ';
// FIXME libc++ specifically works around \u00A0 by translating it into
// a regular space.
const char sep = ' ';
const wchar_t wsep = L'\u00A0';
#endif
{

View File

@ -56,14 +56,10 @@ int main(int, char**)
}
{
std::locale l(LOCALE_fr_FR_UTF_8);
#if defined(TEST_HAS_GLIBC)
const char sep = ' ';
// The below tests work around GLIBC's use of U202F as LC_NUMERIC thousands_sep.
# if TEST_GLIBC_PREREQ(2, 27)
const wchar_t wsep = L'\u202f';
# else
const wchar_t wsep = L' ';
# endif
#if defined(_CS_GNU_LIBC_VERSION)
const char sep = ' ';
const wchar_t wsep = glibc_version_less_than("2.27") ? L' ' : L'\u202f';
#else
const char sep = ',';
const wchar_t wsep = L',';

View File

@ -110,4 +110,18 @@ std::wstring get_wide_temp_file_name()
#endif // __CloudABI__
#if defined(_CS_GNU_LIBC_VERSION)
inline bool glibc_version_less_than(char const* version) {
std::string test_version = std::string("glibc ") + version;
size_t n = confstr(_CS_GNU_LIBC_VERSION, nullptr, (size_t)0);
char *current_version = new char[n];
confstr(_CS_GNU_LIBC_VERSION, current_version, n);
bool result = strverscmp(current_version, test_version.c_str()) < 0;
delete[] current_version;
return result;
}
#endif // _CS_GNU_LIBC_VERSION
#endif // PLATFORM_SUPPORT_H