From: Peter Griess Date: Tue, 26 Nov 2013 20:12:14 +0000 (-0800) Subject: Handle lack of and X-Git-Tag: v0.22.0~750 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=708be4fcfe5c4c985b879cf8a3b1a36c6c9c6626;p=folly.git Handle lack of and Summary: - Clang's libc++ doesn't provide these header files. Detect libc++ via the _LIBCPP_VERSION symbol (pulling it in by sourcing some header files earlier if necessary) and avoid using these files. - This is another attempt at D1074481. Test Plan: . Reviewed By: andrei.alexandrescu@fb.com FB internal diff: D1074723 --- diff --git a/folly/FBString.h b/folly/FBString.h index b75db3d4..02e4d276 100644 --- a/folly/FBString.h +++ b/folly/FBString.h @@ -58,6 +58,12 @@ #endif #endif +#include +#include +#include + +// libc++ doesn't provide this header +#ifndef _LIBCPP_VERSION // This file appears in two locations: inside fbcode and in the // libstdc++ source code (when embedding fbstring as std::string). // To aid in this schizophrenic use, two macros are defined in @@ -65,6 +71,7 @@ // _LIBSTDCXX_FBSTRING - Set inside libstdc++. This is useful to // gate use inside fbcode v. libstdc++ #include +#endif #ifdef _LIBSTDCXX_FBSTRING @@ -97,10 +104,6 @@ #define FBSTRING_LIKELY(x) (__builtin_expect((x), 1)) #define FBSTRING_UNLIKELY(x) (__builtin_expect((x), 0)) -#include -#include -#include - // Ignore shadowing warnings within this file, so includers can use -Wshadow. #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wshadow" diff --git a/folly/Makefile.am b/folly/Makefile.am index 45c53716..f0a34935 100644 --- a/folly/Makefile.am +++ b/folly/Makefile.am @@ -41,6 +41,7 @@ nobase_follyinclude_HEADERS = \ detail/DiscriminatedPtrDetail.h \ detail/FileUtilDetail.h \ detail/FingerprintPolynomial.h \ + detail/FunctionalExcept.h \ detail/Futex.h \ detail/GroupVarintDetail.h \ detail/Malloc.h \ @@ -174,6 +175,10 @@ if !HAVE_WEAK_SYMBOLS libfolly_la_SOURCES += detail/Malloc.cpp endif +if !HAVE_BITS_FUNCTEXCEPT +libfolly_la_SOURCES += detail/FunctionalExcept.cpp +endif + FingerprintTables.cpp: generate_fingerprint_tables ./generate_fingerprint_tables CLEANFILES += FingerprintTables.cpp diff --git a/folly/Malloc.h b/folly/Malloc.h index 72c0fb10..d3ad40d0 100644 --- a/folly/Malloc.h +++ b/folly/Malloc.h @@ -54,6 +54,7 @@ __attribute__((weak)); extern "C" int allocm(void**, size_t*, size_t, int) __attribute__((weak)); +#include #define FOLLY_HAVE_MALLOC_H 1 #else #include "folly/detail/Malloc.h" @@ -76,8 +77,6 @@ __attribute__((weak)); #include -#include - /** * Define various ALLOCM_* macros normally provided by jemalloc. We define * them so that we don't have to include jemalloc.h, in case the program is diff --git a/folly/Portability.h b/folly/Portability.h index 1bec1699..3b07fec9 100644 --- a/folly/Portability.h +++ b/folly/Portability.h @@ -104,6 +104,13 @@ struct MaxAlign { char c; } __attribute__((aligned)); #include "folly/detail/Clock.h" #endif +// Provide our own std::__throw_* wrappers for platforms that don't have them +#if FOLLY_HAVE_BITS_FUNCTEXCEPT_H +#include +#else +#include "folly/detail/FunctionalExcept.h" +#endif + #if defined(__cplusplus) // Unfortunately, boost::has_trivial_copy is broken in libc++ due to its // usage of __has_trivial_copy(), so we can't use it as a diff --git a/folly/Range.h b/folly/Range.h index 5466c6d6..1d3d0dd0 100644 --- a/folly/Range.h +++ b/folly/Range.h @@ -30,7 +30,18 @@ #include #include #include + +// libc++ doesn't provide this header +#if !FOLLY_USE_LIBCPP +// This file appears in two locations: inside fbcode and in the +// libstdc++ source code (when embedding fbstring as std::string). +// To aid in this schizophrenic use, two macros are defined in +// c++config.h: +// _LIBSTDCXX_FBSTRING - Set inside libstdc++. This is useful to +// gate use inside fbcode v. libstdc++ #include +#endif + #include "folly/CpuId.h" #include "folly/Traits.h" #include "folly/Likely.h" diff --git a/folly/Traits.h b/folly/Traits.h index f5fe5816..4d6deeb5 100644 --- a/folly/Traits.h +++ b/folly/Traits.h @@ -25,7 +25,16 @@ #include "folly/Portability.h" +// libc++ doesn't provide this header +#if !FOLLY_USE_LIBCPP +// This file appears in two locations: inside fbcode and in the +// libstdc++ source code (when embedding fbstring as std::string). +// To aid in this schizophrenic use, two macros are defined in +// c++config.h: +// _LIBSTDCXX_FBSTRING - Set inside libstdc++. This is useful to +// gate use inside fbcode v. libstdc++ #include +#endif #include #include diff --git a/folly/configure.ac b/folly/configure.ac index 70afc3f0..825668f7 100644 --- a/folly/configure.ac +++ b/folly/configure.ac @@ -52,7 +52,7 @@ AX_BOOST_SYSTEM # Checks for header files. AC_HEADER_STDC -AC_CHECK_HEADERS([fcntl.h features.h inttypes.h limits.h stdint.h stdlib.h string.h sys/time.h unistd.h mutex.h malloc.h emmintrin.h byteswap.h]) +AC_CHECK_HEADERS([fcntl.h features.h inttypes.h limits.h stdint.h stdlib.h string.h sys/time.h unistd.h mutex.h malloc.h emmintrin.h byteswap.h bits/functexcept.h]) AC_CHECK_HEADER(double-conversion.h, [], [AC_MSG_ERROR( [Couldn't find double-conversion.h, please download from \ @@ -175,6 +175,7 @@ AM_CONDITIONAL([HAVE_STD_THREAD], [test "$ac_cv_header_features" = "yes"]) AM_CONDITIONAL([HAVE_X86_64], [test "$build_cpu" = "x86_64"]) AM_CONDITIONAL([HAVE_LINUX], [test "$build_os" == "linux-gnu"]) AM_CONDITIONAL([HAVE_WEAK_SYMBOLS], [test "$ac_have_weak_symbols" = "yes"]) +AM_CONDITIONAL([HAVE_BITS_FUNCTEXCEPT], [test "$ac_cv_header_bits_functexcept" = "yes"]) # Output AC_CONFIG_FILES([Makefile diff --git a/folly/detail/FunctionalExcept.cpp b/folly/detail/FunctionalExcept.cpp new file mode 100644 index 00000000..a6986f7d --- /dev/null +++ b/folly/detail/FunctionalExcept.cpp @@ -0,0 +1,35 @@ +/* + * Copyright 2013 Facebook, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "folly/detail/FunctionalExcept.h" + +#include + +FOLLY_NAMESPACE_STD_BEGIN + +void __throw_length_error(const char* msg) FOLLY_NORETURN { + throw std::length_error(msg); +} + +void __throw_logic_error(const char* msg) FOLLY_NORETURN { + throw std::logic_error(msg); +} + +void __throw_out_of_range(const char* msg) FOLLY_NORETURN { + throw std::out_of_range(msg); +} + +FOLLY_NAMESPACE_STD_END diff --git a/folly/detail/FunctionalExcept.h b/folly/detail/FunctionalExcept.h new file mode 100644 index 00000000..cda11925 --- /dev/null +++ b/folly/detail/FunctionalExcept.h @@ -0,0 +1,30 @@ +/* + * Copyright 2013 Facebook, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOLLY_DETAIL_FUNCTIONAL_EXCEPT_H +#define FOLLY_DETAIL_FUNCTIONAL_EXCEPT_H + +#include "folly/Portability.h" + +FOLLY_NAMESPACE_STD_BEGIN + +void __throw_length_error(const char* msg) FOLLY_NORETURN; +void __throw_logic_error(const char* msg) FOLLY_NORETURN; +void __throw_out_of_range(const char* msg) FOLLY_NORETURN; + +FOLLY_NAMESPACE_STD_END + +#endif