From d364aea0dec7121fc2185f65bc89a08774ec3a65 Mon Sep 17 00:00:00 2001 From: Peter Griess Date: Fri, 31 Jan 2014 20:08:02 -0800 Subject: [PATCH] Try again to fix hash namespacing Summary: - Unfortunately when D1152140 broke the Android build, which uses the Bionic C++ standard library, and which Boost doesn't auto-detect. Deal with this by manually picking namespaces for template specialization based on #defines. Test Plan: - fbconfig -r folly/ unicorn/utils/ && fbmake runtests - Build Liger on iOS and Android Reviewed By: andrei.alexandrescu@fb.com FB internal diff: D1154569 Blame Revision: D1152140 --- folly/FBString.h | 41 +++++++++++++++++++++++++++++++++++++++-- folly/String.h | 18 ++++++++++++------ 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/folly/FBString.h b/folly/FBString.h index 143a006c..30fcb4ab 100644 --- a/folly/FBString.h +++ b/folly/FBString.h @@ -73,6 +73,11 @@ #include #endif +#ifdef _GLIBCXX_SYMVER +#include +#include +#endif + #ifdef _LIBSTDCXX_FBSTRING #pragma GCC system_header @@ -2439,21 +2444,53 @@ _GLIBCXX_END_NAMESPACE_VERSION } // namespace folly -#pragma GCC diagnostic pop - #ifndef _LIBSTDCXX_FBSTRING +// Hash functions to make fbstring usable with e.g. hash_map +// +// Handle interaction with different C++ standard libraries, which +// expect these types to be in different namespaces. namespace std { + +template +struct hash > : private hash { + size_t operator()(const folly::basic_fbstring & s) const { + return hash::operator()(s.c_str()); + } +}; + template <> struct hash< ::folly::fbstring> { size_t operator()(const ::folly::fbstring& s) const { return ::folly::hash::fnv32_buf(s.data(), s.size()); } }; + } +#if defined(_GLIBCXX_SYMVER) && !defined(__BIONIC__) +namespace __gnu_cxx { + +template +struct hash > : private hash { + size_t operator()(const folly::basic_fbstring & s) const { + return hash::operator()(s.c_str()); + } +}; + +template <> +struct hash< ::folly::fbstring> { + size_t operator()(const ::folly::fbstring& s) const { + return ::folly::hash::fnv32_buf(s.data(), s.size()); + } +}; + +} +#endif // _GLIBCXX_SYMVER && !__BIONIC__ #endif // _LIBSTDCXX_FBSTRING +#pragma GCC diagnostic pop + #undef FBSTRING_DISABLE_ADDRESS_SANITIZER #undef throw #undef FBSTRING_LIKELY diff --git a/folly/String.h b/folly/String.h index bea17b72..90f9c739 100644 --- a/folly/String.h +++ b/folly/String.h @@ -495,19 +495,24 @@ std::string join(const Delim& delimiter, } // namespace folly -// Hash functions for string and fbstring usable with e.g. hash_map +// Hash functions to make std::string usable with e.g. hash_map // -// We let Boost pick the namespace here for us, since it has logic to do the -// right thing based on the C++ standard library implementation being used. -namespace BOOST_STD_EXTENSION_NAMESPACE { +// Handle interaction with different C++ standard libraries, which +// expect these types to be in different namespaces. +namespace std { template -struct hash > : private hash { - size_t operator()(const folly::basic_fbstring & s) const { +struct hash > : private hash { + size_t operator()(const std::basic_string & s) const { return hash::operator()(s.c_str()); } }; +} + +#if defined(_GLIBCXX_SYMVER) && !defined(__BIONIC__) +namespace __gnu_cxx { + template struct hash > : private hash { size_t operator()(const std::basic_string & s) const { @@ -516,6 +521,7 @@ struct hash > : private hash { }; } +#endif // Hook into boost's type traits namespace boost { -- 2.34.1