From: Tudor Bosman Date: Thu, 9 May 2013 22:50:02 +0000 (-0700) Subject: Unbreak build on glibc 2.5.1 X-Git-Tag: v0.22.0~977 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=9cdd19b750f66db9171344c9db2d21c27de467d9;p=folly.git Unbreak build on glibc 2.5.1 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 --- diff --git a/folly/FileUtil.cpp b/folly/FileUtil.cpp index 2e130a32..2d4573dc 100644 --- a/folly/FileUtil.cpp +++ b/folly/FileUtil.cpp @@ -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 diff --git a/folly/FileUtil.h b/folly/FileUtil.h index 5845ba61..9d65bf53 100644 --- a/folly/FileUtil.h +++ b/folly/FileUtil.h @@ -17,6 +17,8 @@ #ifndef FOLLY_FILEUTIL_H_ #define FOLLY_FILEUTIL_H_ +#include "folly/Portability.h" + #include #include @@ -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 diff --git a/folly/Malloc.h b/folly/Malloc.h index cd5e56e7..ab165229 100644 --- a/folly/Malloc.h +++ b/folly/Malloc.h @@ -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 diff --git a/folly/Portability.h b/folly/Portability.h index ccd90380..f4064a22 100644 --- a/folly/Portability.h +++ b/folly/Portability.h @@ -19,6 +19,11 @@ #include "folly-config.h" +#ifdef FOLLY_HAVE_FEATURES_H +#include +#endif + + #ifdef FOLLY_HAVE_SCHED_H #include #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_ diff --git a/folly/Range.h b/folly/Range.h index 355b0855..43bebb2b 100644 --- a/folly/Range.h +++ b/folly/Range.h @@ -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 #include diff --git a/folly/configure.ac b/folly/configure.ac index 38927fb9..33ac2e8e 100644 --- a/folly/configure.ac +++ b/folly/configure.ac @@ -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 \ diff --git a/folly/io/RecordIO.cpp b/folly/io/RecordIO.cpp index 69bea4de..566ce365 100644 --- a/folly/io/RecordIO.cpp +++ b/folly/io/RecordIO.cpp @@ -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 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); } diff --git a/folly/test/FileUtilTest.cpp b/folly/test/FileUtilTest.cpp index f9fe52b7..b35a3abe 100644 --- a/folly/test/FileUtilTest.cpp +++ b/folly/test/FileUtilTest.cpp @@ -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