Unbreak build on glibc 2.5.1
authorTudor Bosman <tudorb@fb.com>
Thu, 9 May 2013 22:50:02 +0000 (15:50 -0700)
committerSara Golemon <sgolemon@fb.com>
Mon, 20 May 2013 18:01:27 +0000 (11:01 -0700)
Summary:
Also move manually-generated stuff away from folly-config.h and into
Portability.h.  This should be only for things that differs between the
various (compiler, library) pairs used internally at FB; everything else
should be autoconf-ed and therefore go into folly-config.h.

Test Plan: built and ran file_util_test on various platforms

Reviewed By: delong.j@fb.com

FB internal diff: D807067

Blame Revision: D806781

folly/FileUtil.cpp
folly/FileUtil.h
folly/Malloc.h
folly/Portability.h
folly/Range.h
folly/configure.ac
folly/io/RecordIO.cpp
folly/test/FileUtilTest.cpp

index 2e130a32ad4cb311f8f06421b4bdb01727fe5bcf..2d4573dc79e5c105025fbfddde60117fcb2daa12 100644 (file)
@@ -85,17 +85,21 @@ ssize_t readvFull(int fd, iovec* iov, int count) {
   return wrapvFull(readv, fd, iov, count);
 }
 
+#ifdef FOLLY_HAVE_PREADV
 ssize_t preadvFull(int fd, iovec* iov, int count, off_t offset) {
   return wrapvFull(preadv, fd, iov, count, offset);
 }
+#endif
 
 ssize_t writevFull(int fd, iovec* iov, int count) {
   return wrapvFull(writev, fd, iov, count);
 }
 
+#ifdef FOLLY_HAVE_PWRITEV
 ssize_t pwritevFull(int fd, iovec* iov, int count, off_t offset) {
   return wrapvFull(pwritev, fd, iov, count, offset);
 }
+#endif
 
 }  // namespaces
 
index 5845ba61d385db4b4c6ce97ef0084d135a7b912a..9d65bf53ff567f773f3a5a2c4d1a96338b31707e 100644 (file)
@@ -17,6 +17,8 @@
 #ifndef FOLLY_FILEUTIL_H_
 #define FOLLY_FILEUTIL_H_
 
+#include "folly/Portability.h"
+
 #include <sys/uio.h>
 #include <unistd.h>
 
@@ -63,7 +65,9 @@ ssize_t writevNoInt(int fd, const iovec* iov, int count);
 ssize_t readFull(int fd, void* buf, size_t n);
 ssize_t preadFull(int fd, void* buf, size_t n, off_t offset);
 ssize_t readvFull(int fd, iovec* iov, int count);
+#ifdef FOLLY_HAVE_PREADV
 ssize_t preadvFull(int fd, iovec* iov, int count, off_t offset);
+#endif
 
 /**
  * Similar to readFull and preadFull above, wrappers around write() and
@@ -82,7 +86,9 @@ ssize_t preadvFull(int fd, iovec* iov, int count, off_t offset);
 ssize_t writeFull(int fd, const void* buf, size_t n);
 ssize_t pwriteFull(int fd, const void* buf, size_t n, off_t offset);
 ssize_t writevFull(int fd, iovec* iov, int count);
+#ifdef FOLLY_HAVE_PWRITEV
 ssize_t pwritevFull(int fd, iovec* iov, int count, off_t offset);
+#endif
 
 }  // namespaces
 
index cd5e56e723bbc2b15f9e3d2105ab44f11b62a0c7..ab165229f6a4a16eed22b565efc9396acb5a5060 100644 (file)
@@ -43,7 +43,7 @@ namespace folly {
 #pragma GCC system_header
 #define FOLLY_HAVE_MALLOC_H 1
 #else
-#include "folly-config.h"
+#include "folly/Portability.h"
 #endif
 
 // for malloc_usable_size
index ccd90380001c7d108230362238eef08549c4d011..f4064a2222948e15a090c833708f954802fd91bd 100644 (file)
 
 #include "folly-config.h"
 
+#ifdef FOLLY_HAVE_FEATURES_H
+#include <features.h>
+#endif
+
+
 #ifdef FOLLY_HAVE_SCHED_H
  #include <sched.h>
  #ifndef FOLLY_HAVE_PTHREAD_YIELD
@@ -34,10 +39,36 @@ struct MaxAlign { char c; } __attribute__((aligned));
 # error Cannot define MaxAlign on this platform
 #endif
 
+
+// noreturn
 #if defined(__clang__) || defined(__GNUC__)
 # define FOLLY_NORETURN __attribute__((noreturn))
 #else
 # define FOLLY_NORETURN
 #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))
+#  define FOLLY_FINAL final
+#  define FOLLY_OVERRIDE override
+# else
+#  define FOLLY_FINAL /**/
+#  define FOLLY_OVERRIDE /**/
+# endif
+#endif
+
+
+// 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
+# endif
+#endif
+
 #endif // FOLLY_PORTABILITY_H_
index 355b0855326deb902855a097564ec261ffe5500a..43bebb2ba51bff9af5e349316663b242e1f084b0 100644 (file)
@@ -20,7 +20,7 @@
 #ifndef FOLLY_RANGE_H_
 #define FOLLY_RANGE_H_
 
-#include "folly/folly-config.h"
+#include "folly/Portability.h"
 #include "folly/FBString.h"
 #include <glog/logging.h>
 #include <algorithm>
index 38927fb904020743edde41b82d0375ebbcd80bff..33ac2e8ecb933c5ad096bddf7a4a206ed221ae61 100644 (file)
@@ -38,7 +38,7 @@ AX_BOOST_SYSTEM
 
 # Checks for header files.
 AC_HEADER_STDC
-AC_CHECK_HEADERS([fcntl.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])
 
 AC_CHECK_HEADER(double-conversion.h, [], [AC_MSG_ERROR(
                 [Couldn't find double-conversion.h, please download from \
index 69bea4deeabb39c186971a693d53f9c7bf5b6109..566ce36564d7f2f43d71d6b6207e81988526bc4b 100644 (file)
@@ -22,6 +22,7 @@
 #include "folly/Exception.h"
 #include "folly/FileUtil.h"
 #include "folly/Memory.h"
+#include "folly/Portability.h"
 #include "folly/ScopeGuard.h"
 #include "folly/String.h"
 
@@ -51,11 +52,19 @@ void RecordIOWriter::write(std::unique_ptr<IOBuf> buf) {
   }
 
   DCHECK_EQ(buf->computeChainDataLength(), totalLength);
-  auto iov = buf->getIov();
 
   // We're going to write.  Reserve space for ourselves.
   off_t pos = filePos_.fetch_add(totalLength);
+
+#ifdef FOLLY_HAVE_PWRITEV
+  auto iov = buf->getIov();
   ssize_t bytes = pwritevFull(file_.fd(), iov.data(), iov.size(), pos);
+#else
+  buf->unshare();
+  buf->coalesce();
+  ssize_t bytes = pwriteFull(file_.fd(), buf->data(), buf->length(), pos);
+#endif
+
   checkUnixError(bytes, "pwrite() failed");
   DCHECK_EQ(bytes, totalLength);
 }
index f9fe52b7e3f6e8bf52e578faa25a29ddf2b66af3..b35a3abe2c1d354875dc0ec94fd9e3b316472894 100644 (file)
@@ -222,6 +222,7 @@ TEST_F(FileUtilTest, readv) {
   }
 }
 
+#ifdef FOLLY_HAVE_PREADV
 TEST_F(FileUtilTest, preadv) {
   for (auto& p : readers_) {
     IovecBuffers buf({12, 19, 31});
@@ -235,6 +236,7 @@ TEST_F(FileUtilTest, preadv) {
     }
   }
 }
+#endif
 
 
 }}  // namespaces