[PATCH] D56702: [libc++] Use runtime rather then compile-time glibc version check

Petr Hosek via Phabricator reviews at reviews.llvm.org
Mon Jan 14 20:36:36 PST 2019


phosek created this revision.
phosek added reviewers: EricWF, ldionne, mclow.lists, mcgrathr.
Herald added subscribers: libcxx-commits, christof, JDevlieghere.

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.


Repository:
  rCXX libc++

https://reviews.llvm.org/D56702

Files:
  libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/curr_symbol.pass.cpp


Index: libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/curr_symbol.pass.cpp
===================================================================
--- libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/curr_symbol.pass.cpp
+++ libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/curr_symbol.pass.cpp
@@ -115,19 +115,22 @@
         assert(f.curr_symbol() == L" EUR");
     }
 
+#if defined(_CS_GNU_LIBC_VERSION)
+    size_t n = confstr(_CS_GNU_LIBC_VERSION, nullptr, (size_t)0);
+    char *buf = new char[n];
+    confstr(_CS_GNU_LIBC_VERSION, buf, n);
+#endif
+
     {
         Fnf f(LOCALE_ru_RU_UTF_8, 1);
+#if defined(_CS_GNU_LIBC_VERSION)
         // GLIBC <= 2.23 uses currency_symbol="<U0440><U0443><U0431>"
         // GLIBC >= 2.24 uses currency_symbol="<U20BD>"
         // See also: http://www.fileformat.info/info/unicode/char/20bd/index.htm
-#if defined(TEST_GLIBC_PREREQ)
-    #if TEST_GLIBC_PREREQ(2, 24)
-        #define TEST_GLIBC_2_24_CURRENCY_SYMBOL
-    #endif
-#endif
-
-#if defined(TEST_GLIBC_2_24_CURRENCY_SYMBOL)
-        assert(f.curr_symbol() == " \u20BD");
+        if (strverscmp(buf, "glibc 2.24") < 0)
+          assert(f.curr_symbol() == " \xD1\x80\xD1\x83\xD0\xB1");
+        else
+          assert(f.curr_symbol() == " \u20BD");
 #else
         assert(f.curr_symbol() == " \xD1\x80\xD1\x83\xD0\xB1");
 #endif
@@ -138,13 +141,20 @@
     }
     {
         Fwf f(LOCALE_ru_RU_UTF_8, 1);
-#if defined(TEST_GLIBC_2_24_CURRENCY_SYMBOL)
-        assert(f.curr_symbol() == L" \u20BD");
+#if defined(_CS_GNU_LIBC_VERSION)
+        if (strverscmp(buf, "glibc 2.24") < 0)
+          assert(f.curr_symbol() == L" \x440\x443\x431");
+        else
+          assert(f.curr_symbol() == L" \u20BD");
 #else
         assert(f.curr_symbol() == L" \x440\x443\x431");
 #endif
     }
 
+#if defined(_CS_GNU_LIBC_VERSION)
+    delete[] buf;
+#endif
+
     {
         Fwt f(LOCALE_ru_RU_UTF_8, 1);
         assert(f.curr_symbol() == L" RUB");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56702.181711.patch
Type: text/x-patch
Size: 2068 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190115/ee503f10/attachment-0001.bin>


More information about the libcxx-commits mailing list