From ebcf92c2b35ceac48aa01fd32a752ec1d80cf304 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Thu, 14 Jul 2016 17:37:31 -0700 Subject: [PATCH] Add a check for wchar support Summary: Not all libc's are the same. Some support wchar_t and some don't do a great job... Reviewed By: Orvid Differential Revision: D3565016 fbshipit-source-id: 91da4f1332e30bdb20a93d0a26a0445d5eadd1b7 --- folly/configure.ac | 21 +++++++++++++++++++++ folly/test/FBStringTest.cpp | 10 +++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/folly/configure.ac b/folly/configure.ac index 48a99b5b..51ec0dd6 100644 --- a/folly/configure.ac +++ b/folly/configure.ac @@ -340,6 +340,27 @@ if test "$folly_cv_prog_cc_weak_symbols" = yes; then [Define to 1 if the linker supports weak symbols.]) fi + +# Figure out if we support wchar well +AC_CACHE_CHECK( + [for wchar support], + [folly_cv_prog_cc_wchar_support], + [AC_RUN_IFELSE( + [AC_LANG_SOURCE[ + #include + #include + + int main(int argc, char** argv) { + return wcstol(L"01", nullptr, 10) == 1 ? 0 : 1; + } + ]], + [folly_cv_prog_cc_wchar_support=yes], + [folly_cv_prog_cc_wchar_support=no])]) + +if test "$folly_cv_prog_cc_wchar_support" = "yes"; then + AC_DEFINE([HAVE_WCHAR_SUPPORT], [1], [Define to 1 if the libc supports wchar well]) +fi + # Figure out whether the architecture supports unaligned accesses AC_CACHE_CHECK( [for unaligned access support], diff --git a/folly/test/FBStringTest.cpp b/folly/test/FBStringTest.cpp index 1bc36391..8767b28f 100644 --- a/folly/test/FBStringTest.cpp +++ b/folly/test/FBStringTest.cpp @@ -984,9 +984,7 @@ TEST(FBString, testAllClauses) { EXPECT_TRUE(1) << "Starting with seed: " << seed; std::string r; folly::fbstring c; -#ifndef __ANDROID__ - // Disabled on Android: wchar support is not recommended and does not - // always behave as expected +#if FOLLY_HAVE_WCHAR_SUPPORT std::wstring wr; folly::basic_fbstring wc; #endif @@ -1001,7 +999,7 @@ TEST(FBString, testAllClauses) { randomString(&r); c = r; EXPECT_EQ(c, r); -#ifndef __ANDROID__ +#if FOLLY_HAVE_WCHAR_SUPPORT wr = std::wstring(r.begin(), r.end()); wc = folly::basic_fbstring(wr.c_str()); #endif @@ -1014,7 +1012,7 @@ TEST(FBString, testAllClauses) { << "Lengths: " << r.size() << " vs. " << c.size() << "\nReference: '" << r << "'" << "\nActual: '" << c.data()[0] << "'"; -#ifndef __ANDROID__ +#if FOLLY_HAVE_WCHAR_SUPPORT rng = RandomT(localSeed); f_wfbstring(wc); int wret = wcslen(wc.c_str()); @@ -1287,6 +1285,7 @@ TEST(FBString, testHash) { EXPECT_NE(hashfunc(a), hashfunc(b)); } +#if FOLLY_HAVE_WCHAR_SUPPORT TEST(FBString, testHashChar16) { using u16fbstring = basic_fbstring; u16fbstring a; @@ -1298,6 +1297,7 @@ TEST(FBString, testHashChar16) { std::hash hashfunc; EXPECT_NE(hashfunc(a), hashfunc(b)); } +#endif TEST(FBString, testFrontBack) { fbstring str("hello"); -- 2.34.1