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

Louis Dionne via Phabricator reviews at reviews.llvm.org
Tue Jan 22 09:09:09 PST 2019


ldionne added inline comments.


================
Comment at: libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/curr_symbol.pass.cpp:119-123
+    size_t n = confstr(_CS_GNU_LIBC_VERSION, nullptr, (size_t)0);
+    char *buf = new char[n];
+    confstr(_CS_GNU_LIBC_VERSION, buf, n);
+    bool glibc_2_24_currency_symbol = strverscmp(buf, "glibc 2.24") >= 0;
+    delete[] buf;
----------------
This logic could be defined in a function like:

```
#if defined(_CS_GNU_LIBC_VERSION)
bool glibc_version_less_than(char const* version) {
    std::string test_version = "glibc "; test_version += 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
```

Then, we could use it as:

```
#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 (!glibc_version_less_than("2.24")) {
        assert(f.curr_symbol() == " \u20BD");
    } else {
        assert(f.curr_symbol() == " \xD1\x80\xD1\x83\xD0\xB1");
    }
#else
    assert(f.curr_symbol() == " \xD1\x80\xD1\x83\xD0\xB1");
#endif
```

We may or may not want to lift this function to a header common to the tests, but not defining the logic inline seems like a gain in readability. WDYT?



Repository:
  rCXX libc++

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56702/new/

https://reviews.llvm.org/D56702





More information about the libcxx-commits mailing list