From edf5a373cd47666cf9554ae4fe21c3d8d7d89ac0 Mon Sep 17 00:00:00 2001 From: Daniel Sloof Date: Tue, 28 May 2013 10:17:55 +0200 Subject: [PATCH] make folly build on OSX Summary: A squash of https://github.com/danslo/folly/compare/master Github Author: danslo Test Plan: he said it compiles on OSX Reviewed By: oyamauchi@fb.com FB internal diff: D830883 --- folly/Benchmark.cpp | 3 ++- folly/Bits.h | 3 +++ folly/FileUtil.cpp | 7 +++++++ folly/Malloc.h | 22 +++++++++++++--------- folly/Portability.h | 25 +++++++++++++++++++------ folly/detail/ThreadLocalDetail.h | 1 + folly/experimental/io/HugePages.cpp | 4 ++++ folly/small_vector.h | 10 +++++----- 8 files changed, 54 insertions(+), 21 deletions(-) diff --git a/folly/Benchmark.cpp b/folly/Benchmark.cpp index 6fc44200..2fb35152 100644 --- a/folly/Benchmark.cpp +++ b/folly/Benchmark.cpp @@ -210,7 +210,8 @@ static double runBenchmarkGetNSPerIteration(const BenchmarkFun& fun, // the clock resolution is worse than that, it will be larger. In // essence we're aiming at making the quantization noise 0.01%. static const auto minNanoseconds = - max(FLAGS_bm_min_usec * 1000UL, min(resolutionInNs * 100000, 1000000000UL)); + max(FLAGS_bm_min_usec * 1000UL, + min(resolutionInNs * 100000, 1000000000ULL)); // We do measurements in several epochs and take the minimum, to // account for jitter. diff --git a/folly/Bits.h b/folly/Bits.h index 83c61708..0b45f84f 100644 --- a/folly/Bits.h +++ b/folly/Bits.h @@ -65,7 +65,10 @@ #error GCC required #endif +#ifndef FOLLY_NO_CONFIG #include "folly/folly-config.h" +#endif + #include "folly/detail/BitsDetail.h" #include "folly/detail/BitIteratorDetail.h" #include "folly/Likely.h" diff --git a/folly/FileUtil.cpp b/folly/FileUtil.cpp index 393f5408..2d9cabf8 100644 --- a/folly/FileUtil.cpp +++ b/folly/FileUtil.cpp @@ -17,6 +17,9 @@ #include "folly/FileUtil.h" #include +#ifdef __APPLE__ +#include +#endif #include "folly/detail/FileUtilDetail.h" @@ -50,7 +53,11 @@ int fsyncNoInt(int fd) { } int fdatasyncNoInt(int fd) { +#ifndef __APPLE__ return wrapNoInt(fdatasync, fd); +#else + return wrapNoInt(fcntl, fd, F_FULLFSYNC); +#endif } int ftruncateNoInt(int fd, off_t len) { diff --git a/folly/Malloc.h b/folly/Malloc.h index ab165229..e10c8255 100644 --- a/folly/Malloc.h +++ b/folly/Malloc.h @@ -64,14 +64,6 @@ namespace folly { #include -/** - * Declare rallocm() and malloc_usable_size() as weak symbols. It - * will be provided by jemalloc if we are using jemalloc, or it will - * be NULL if we are using another malloc implementation. - */ -extern "C" int rallocm(void**, size_t*, size_t, size_t, int) -__attribute__((weak)); - /** * 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 @@ -88,7 +80,19 @@ __attribute__((weak)); #define ALLOCM_LG_ALIGN(la) (la) -#endif /* !ALLOCM_SUCCESS */ +#if defined(JEMALLOC_MANGLE) && defined(JEMALLOC_EXPERIMENTAL) +#define rallocm je_rallocm +#endif + +#endif /* ALLOCM_SUCCESS */ + +/** + * Declare rallocm() and malloc_usable_size() as weak symbols. It + * will be provided by jemalloc if we are using jemalloc, or it will + * be NULL if we are using another malloc implementation. + */ +extern "C" int rallocm(void**, size_t*, size_t, size_t, int) +__attribute__((weak)); #ifdef _LIBSTDCXX_FBSTRING namespace std _GLIBCXX_VISIBILITY(default) { diff --git a/folly/Portability.h b/folly/Portability.h index f4064a22..2989ebea 100644 --- a/folly/Portability.h +++ b/folly/Portability.h @@ -17,7 +17,9 @@ #ifndef FOLLY_PORTABILITY_H_ #define FOLLY_PORTABILITY_H_ +#ifndef FOLLY_NO_CONFIG #include "folly-config.h" +#endif #ifdef FOLLY_HAVE_FEATURES_H #include @@ -48,12 +50,21 @@ struct MaxAlign { char c; } __attribute__((aligned)); #endif +// portable version check +#ifndef __GNUC_PREREQ +# if defined __GNUC__ && defined __GNUC_MINOR__ +# define __GNUC_PREREQ(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= \ + ((maj) << 16) + (min)) +# else +# define __GNUC_PREREQ(maj, min) 0 +# endif +#endif + + /* Define macro wrappers for C++11's "final" and "override" keywords, which * are supported in gcc 4.7 but not gcc 4.6. */ #if !defined(FOLLY_FINAL) && !defined(FOLLY_OVERRIDE) -# if defined(__clang__) || \ - (defined(__GNUC__) && defined(__GNUC_MINOR__) && \ - ((__GNUC__ << 16) + __GNUC_MINOR__) >= ((4 << 16) + 7)) +# if defined(__clang__) || __GNUC_PREREQ(4, 7) # define FOLLY_FINAL final # define FOLLY_OVERRIDE override # else @@ -65,9 +76,11 @@ struct MaxAlign { char c; } __attribute__((aligned)); // Define to 1 if you have the `preadv' and `pwritev' functions, respectively #if !defined(FOLLY_HAVE_PREADV) && !defined(FOLLY_HAVE_PWRITEV) -# if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 10) -# define FOLLY_HAVE_PREADV 1 -# define FOLLY_HAVE_PWRITEV 1 +# if defined(__GLIBC_PREREQ) +# if __GLIBC_PREREQ(2, 10) +# define FOLLY_HAVE_PREADV 1 +# define FOLLY_HAVE_PWRITEV 1 +# endif # endif #endif diff --git a/folly/detail/ThreadLocalDetail.h b/folly/detail/ThreadLocalDetail.h index 205d2e52..6891d3e8 100644 --- a/folly/detail/ThreadLocalDetail.h +++ b/folly/detail/ThreadLocalDetail.h @@ -25,6 +25,7 @@ #include #include +#include #include diff --git a/folly/experimental/io/HugePages.cpp b/folly/experimental/io/HugePages.cpp index a16b3f60..041dfa2d 100644 --- a/folly/experimental/io/HugePages.cpp +++ b/folly/experimental/io/HugePages.cpp @@ -43,6 +43,10 @@ #include "folly/experimental/FileGen.h" #include "folly/experimental/StringGen.h" +#ifndef MAP_POPULATE +#define MAP_POPULATE 0 +#endif + namespace folly { namespace { diff --git a/folly/small_vector.h b/folly/small_vector.h index 065cfae4..12b6a6de 100644 --- a/folly/small_vector.h +++ b/folly/small_vector.h @@ -1010,7 +1010,7 @@ private: try { new (&newp[pos]) value_type(std::move(*v)); } catch (...) { - std::free(newh); + free(newh); throw; } @@ -1019,7 +1019,7 @@ private: detail::moveToUninitialized(begin(), begin() + pos, newp); } catch (...) { newp[pos].~value_type(); - std::free(newh); + free(newh); throw; } @@ -1032,7 +1032,7 @@ private: for (size_type i = 0; i <= pos; ++i) { newp[i].~value_type(); } - std::free(newh); + free(newh); throw; } } else { @@ -1040,7 +1040,7 @@ private: try { detail::moveToUninitialized(begin(), end(), newp); } catch (...) { - std::free(newh); + free(newh); throw; } } @@ -1161,7 +1161,7 @@ private: void freeHeap() { auto vp = detail::pointerFlagClear(pdata_.heap_); - std::free(vp); + free(vp); } } FB_PACKED u; } FB_PACKED; -- 2.34.1