Commit ebcf92c2 authored by Michael Lee's avatar Michael Lee Committed by Facebook Github Bot 9

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
parent 81957665
...@@ -340,6 +340,27 @@ if test "$folly_cv_prog_cc_weak_symbols" = yes; then ...@@ -340,6 +340,27 @@ if test "$folly_cv_prog_cc_weak_symbols" = yes; then
[Define to 1 if the linker supports weak symbols.]) [Define to 1 if the linker supports weak symbols.])
fi 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 <cstddef>
#include <cwchar>
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 # Figure out whether the architecture supports unaligned accesses
AC_CACHE_CHECK( AC_CACHE_CHECK(
[for unaligned access support], [for unaligned access support],
......
...@@ -984,9 +984,7 @@ TEST(FBString, testAllClauses) { ...@@ -984,9 +984,7 @@ TEST(FBString, testAllClauses) {
EXPECT_TRUE(1) << "Starting with seed: " << seed; EXPECT_TRUE(1) << "Starting with seed: " << seed;
std::string r; std::string r;
folly::fbstring c; folly::fbstring c;
#ifndef __ANDROID__ #if FOLLY_HAVE_WCHAR_SUPPORT
// Disabled on Android: wchar support is not recommended and does not
// always behave as expected
std::wstring wr; std::wstring wr;
folly::basic_fbstring<wchar_t> wc; folly::basic_fbstring<wchar_t> wc;
#endif #endif
...@@ -1001,7 +999,7 @@ TEST(FBString, testAllClauses) { ...@@ -1001,7 +999,7 @@ TEST(FBString, testAllClauses) {
randomString(&r); randomString(&r);
c = r; c = r;
EXPECT_EQ(c, r); EXPECT_EQ(c, r);
#ifndef __ANDROID__ #if FOLLY_HAVE_WCHAR_SUPPORT
wr = std::wstring(r.begin(), r.end()); wr = std::wstring(r.begin(), r.end());
wc = folly::basic_fbstring<wchar_t>(wr.c_str()); wc = folly::basic_fbstring<wchar_t>(wr.c_str());
#endif #endif
...@@ -1014,7 +1012,7 @@ TEST(FBString, testAllClauses) { ...@@ -1014,7 +1012,7 @@ TEST(FBString, testAllClauses) {
<< "Lengths: " << r.size() << " vs. " << c.size() << "Lengths: " << r.size() << " vs. " << c.size()
<< "\nReference: '" << r << "'" << "\nReference: '" << r << "'"
<< "\nActual: '" << c.data()[0] << "'"; << "\nActual: '" << c.data()[0] << "'";
#ifndef __ANDROID__ #if FOLLY_HAVE_WCHAR_SUPPORT
rng = RandomT(localSeed); rng = RandomT(localSeed);
f_wfbstring(wc); f_wfbstring(wc);
int wret = wcslen(wc.c_str()); int wret = wcslen(wc.c_str());
...@@ -1287,6 +1285,7 @@ TEST(FBString, testHash) { ...@@ -1287,6 +1285,7 @@ TEST(FBString, testHash) {
EXPECT_NE(hashfunc(a), hashfunc(b)); EXPECT_NE(hashfunc(a), hashfunc(b));
} }
#if FOLLY_HAVE_WCHAR_SUPPORT
TEST(FBString, testHashChar16) { TEST(FBString, testHashChar16) {
using u16fbstring = basic_fbstring<char16_t>; using u16fbstring = basic_fbstring<char16_t>;
u16fbstring a; u16fbstring a;
...@@ -1298,6 +1297,7 @@ TEST(FBString, testHashChar16) { ...@@ -1298,6 +1297,7 @@ TEST(FBString, testHashChar16) {
std::hash<u16fbstring> hashfunc; std::hash<u16fbstring> hashfunc;
EXPECT_NE(hashfunc(a), hashfunc(b)); EXPECT_NE(hashfunc(a), hashfunc(b));
} }
#endif
TEST(FBString, testFrontBack) { TEST(FBString, testFrontBack) {
fbstring str("hello"); fbstring str("hello");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment