Commit 708be4fc authored by Peter Griess's avatar Peter Griess Committed by Jordan DeLong

Handle lack of <bits/c++config.h> and <bits/functexcept.h>

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
parent 3bde358c
...@@ -58,6 +58,12 @@ ...@@ -58,6 +58,12 @@
#endif #endif
#endif #endif
#include <atomic>
#include <limits>
#include <type_traits>
// libc++ doesn't provide this header
#ifndef _LIBCPP_VERSION
// This file appears in two locations: inside fbcode and in the // This file appears in two locations: inside fbcode and in the
// libstdc++ source code (when embedding fbstring as std::string). // libstdc++ source code (when embedding fbstring as std::string).
// To aid in this schizophrenic use, two macros are defined in // To aid in this schizophrenic use, two macros are defined in
...@@ -65,6 +71,7 @@ ...@@ -65,6 +71,7 @@
// _LIBSTDCXX_FBSTRING - Set inside libstdc++. This is useful to // _LIBSTDCXX_FBSTRING - Set inside libstdc++. This is useful to
// gate use inside fbcode v. libstdc++ // gate use inside fbcode v. libstdc++
#include <bits/c++config.h> #include <bits/c++config.h>
#endif
#ifdef _LIBSTDCXX_FBSTRING #ifdef _LIBSTDCXX_FBSTRING
...@@ -97,10 +104,6 @@ ...@@ -97,10 +104,6 @@
#define FBSTRING_LIKELY(x) (__builtin_expect((x), 1)) #define FBSTRING_LIKELY(x) (__builtin_expect((x), 1))
#define FBSTRING_UNLIKELY(x) (__builtin_expect((x), 0)) #define FBSTRING_UNLIKELY(x) (__builtin_expect((x), 0))
#include <atomic>
#include <limits>
#include <type_traits>
// Ignore shadowing warnings within this file, so includers can use -Wshadow. // Ignore shadowing warnings within this file, so includers can use -Wshadow.
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow" #pragma GCC diagnostic ignored "-Wshadow"
......
...@@ -41,6 +41,7 @@ nobase_follyinclude_HEADERS = \ ...@@ -41,6 +41,7 @@ nobase_follyinclude_HEADERS = \
detail/DiscriminatedPtrDetail.h \ detail/DiscriminatedPtrDetail.h \
detail/FileUtilDetail.h \ detail/FileUtilDetail.h \
detail/FingerprintPolynomial.h \ detail/FingerprintPolynomial.h \
detail/FunctionalExcept.h \
detail/Futex.h \ detail/Futex.h \
detail/GroupVarintDetail.h \ detail/GroupVarintDetail.h \
detail/Malloc.h \ detail/Malloc.h \
...@@ -174,6 +175,10 @@ if !HAVE_WEAK_SYMBOLS ...@@ -174,6 +175,10 @@ if !HAVE_WEAK_SYMBOLS
libfolly_la_SOURCES += detail/Malloc.cpp libfolly_la_SOURCES += detail/Malloc.cpp
endif endif
if !HAVE_BITS_FUNCTEXCEPT
libfolly_la_SOURCES += detail/FunctionalExcept.cpp
endif
FingerprintTables.cpp: generate_fingerprint_tables FingerprintTables.cpp: generate_fingerprint_tables
./generate_fingerprint_tables ./generate_fingerprint_tables
CLEANFILES += FingerprintTables.cpp CLEANFILES += FingerprintTables.cpp
......
...@@ -54,6 +54,7 @@ __attribute__((weak)); ...@@ -54,6 +54,7 @@ __attribute__((weak));
extern "C" int allocm(void**, size_t*, size_t, int) extern "C" int allocm(void**, size_t*, size_t, int)
__attribute__((weak)); __attribute__((weak));
#include <bits/functexcept.h>
#define FOLLY_HAVE_MALLOC_H 1 #define FOLLY_HAVE_MALLOC_H 1
#else #else
#include "folly/detail/Malloc.h" #include "folly/detail/Malloc.h"
...@@ -76,8 +77,6 @@ __attribute__((weak)); ...@@ -76,8 +77,6 @@ __attribute__((weak));
#include <new> #include <new>
#include <bits/functexcept.h>
/** /**
* Define various ALLOCM_* macros normally provided by jemalloc. We define * 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 * them so that we don't have to include jemalloc.h, in case the program is
......
...@@ -104,6 +104,13 @@ struct MaxAlign { char c; } __attribute__((aligned)); ...@@ -104,6 +104,13 @@ struct MaxAlign { char c; } __attribute__((aligned));
#include "folly/detail/Clock.h" #include "folly/detail/Clock.h"
#endif #endif
// Provide our own std::__throw_* wrappers for platforms that don't have them
#if FOLLY_HAVE_BITS_FUNCTEXCEPT_H
#include <bits/functexcept.h>
#else
#include "folly/detail/FunctionalExcept.h"
#endif
#if defined(__cplusplus) #if defined(__cplusplus)
// Unfortunately, boost::has_trivial_copy<T> is broken in libc++ due to its // Unfortunately, boost::has_trivial_copy<T> is broken in libc++ due to its
// usage of __has_trivial_copy(), so we can't use it as a // usage of __has_trivial_copy(), so we can't use it as a
......
...@@ -30,7 +30,18 @@ ...@@ -30,7 +30,18 @@
#include <stdexcept> #include <stdexcept>
#include <type_traits> #include <type_traits>
#include <boost/operators.hpp> #include <boost/operators.hpp>
// 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 <bits/c++config.h> #include <bits/c++config.h>
#endif
#include "folly/CpuId.h" #include "folly/CpuId.h"
#include "folly/Traits.h" #include "folly/Traits.h"
#include "folly/Likely.h" #include "folly/Likely.h"
......
...@@ -25,7 +25,16 @@ ...@@ -25,7 +25,16 @@
#include "folly/Portability.h" #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 <bits/c++config.h> #include <bits/c++config.h>
#endif
#include <boost/type_traits.hpp> #include <boost/type_traits.hpp>
#include <boost/mpl/and.hpp> #include <boost/mpl/and.hpp>
......
...@@ -52,7 +52,7 @@ AX_BOOST_SYSTEM ...@@ -52,7 +52,7 @@ AX_BOOST_SYSTEM
# Checks for header files. # Checks for header files.
AC_HEADER_STDC 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( AC_CHECK_HEADER(double-conversion.h, [], [AC_MSG_ERROR(
[Couldn't find double-conversion.h, please download from \ [Couldn't find double-conversion.h, please download from \
...@@ -175,6 +175,7 @@ AM_CONDITIONAL([HAVE_STD_THREAD], [test "$ac_cv_header_features" = "yes"]) ...@@ -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_X86_64], [test "$build_cpu" = "x86_64"])
AM_CONDITIONAL([HAVE_LINUX], [test "$build_os" == "linux-gnu"]) AM_CONDITIONAL([HAVE_LINUX], [test "$build_os" == "linux-gnu"])
AM_CONDITIONAL([HAVE_WEAK_SYMBOLS], [test "$ac_have_weak_symbols" = "yes"]) AM_CONDITIONAL([HAVE_WEAK_SYMBOLS], [test "$ac_have_weak_symbols" = "yes"])
AM_CONDITIONAL([HAVE_BITS_FUNCTEXCEPT], [test "$ac_cv_header_bits_functexcept" = "yes"])
# Output # Output
AC_CONFIG_FILES([Makefile AC_CONFIG_FILES([Makefile
......
/*
* 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 <stdexcept>
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
/*
* 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
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