make folly build on OSX
authorDaniel Sloof <goapsychadelic@gmail.com>
Tue, 28 May 2013 08:17:55 +0000 (10:17 +0200)
committerOwen Yamauchi <oyamauchi@fb.com>
Mon, 3 Jun 2013 19:23:43 +0000 (12:23 -0700)
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
folly/Bits.h
folly/FileUtil.cpp
folly/Malloc.h
folly/Portability.h
folly/detail/ThreadLocalDetail.h
folly/experimental/io/HugePages.cpp
folly/small_vector.h

index 6fc442000cc4707f35ce65889426b7167769d8b7..2fb3515269b0d301db8c5a2e9b25b0c321e2e43f 100644 (file)
@@ -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.
index 83c61708edc42156361e3cdcfeec18450bd41028..0b45f84f36c066204ef41310c37de8c568a15a54 100644 (file)
 #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"
index 393f54081907680578d44f517549a5267e4d766d..2d9cabf872dab44c82095fbd24f30c09d787257d 100644 (file)
@@ -17,6 +17,9 @@
 #include "folly/FileUtil.h"
 
 #include <cerrno>
+#ifdef __APPLE__
+#include <fcntl.h>
+#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) {
index ab165229f6a4a16eed22b565efc9396acb5a5060..e10c8255e092f653f9eff340019fa0d6153bc550 100644 (file)
@@ -64,14 +64,6 @@ namespace folly {
 
 #include <bits/functexcept.h>
 
-/**
- * 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) {
index f4064a2222948e15a090c833708f954802fd91bd..2989ebea10d2b8a62f62dea6784aa96a1f026db8 100644 (file)
@@ -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 <features.h>
@@ -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
 
index 205d2e521763728689f3fc7a845a00a9377ad1d0..6891d3e8d0f10cb53871311570ce390aa459c3a0 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <boost/thread/locks.hpp>
 #include <boost/thread/mutex.hpp>
+#include <boost/thread/locks.hpp>
 
 #include <glog/logging.h>
 
index a16b3f6057dbc8415374292a225236282a902e30..041dfa2d15d7b31141c73301752805c1de8c9237 100644 (file)
 #include "folly/experimental/FileGen.h"
 #include "folly/experimental/StringGen.h"
 
+#ifndef MAP_POPULATE
+#define MAP_POPULATE 0
+#endif
+
 namespace folly {
 
 namespace {
index 065cfae4eaff19b31c8102b6414f9f53445f65ca..12b6a6de70b7c49f2ea9ec5878493d9ed7b285c9 100644 (file)
@@ -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;