Commit b93c8daa authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

move and revise fmt/compile.h portability

Summary: Move the libfmt portability code into `folly/portability/` and revise it only to mutate folly's namespace.

Reviewed By: Orvid

Differential Revision: D26182824

fbshipit-source-id: e0b72f523dfeac7ff7799ff2104a1146032dfbf3
parent 4ab51101
...@@ -16,11 +16,11 @@ ...@@ -16,11 +16,11 @@
#include <folly/File.h> #include <folly/File.h>
#include <folly/CompiledFormat.h>
#include <folly/Exception.h> #include <folly/Exception.h>
#include <folly/FileUtil.h> #include <folly/FileUtil.h>
#include <folly/ScopeGuard.h> #include <folly/ScopeGuard.h>
#include <folly/portability/Fcntl.h> #include <folly/portability/Fcntl.h>
#include <folly/portability/FmtCompile.h>
#include <folly/portability/SysFile.h> #include <folly/portability/SysFile.h>
#include <folly/portability/Unistd.h> #include <folly/portability/Unistd.h>
...@@ -41,7 +41,10 @@ File::File(const char* name, int flags, mode_t mode) ...@@ -41,7 +41,10 @@ File::File(const char* name, int flags, mode_t mode)
: fd_(::open(name, flags, mode)), ownsFd_(false) { : fd_(::open(name, flags, mode)), ownsFd_(false) {
if (fd_ == -1) { if (fd_ == -1) {
throwSystemError(fmt::format( throwSystemError(fmt::format(
FMT_COMPILE("open(\"{}\", {:#o}, 0{:#o}) failed"), name, flags, mode)); FOLLY_FMT_COMPILE("open(\"{}\", {:#o}, 0{:#o}) failed"),
name,
flags,
mode));
} }
ownsFd_ = true; ownsFd_ = true;
} }
......
...@@ -28,11 +28,11 @@ ...@@ -28,11 +28,11 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <folly/CompiledFormat.h>
#include <folly/Demangle.h> #include <folly/Demangle.h>
#include <folly/ScopeGuard.h> #include <folly/ScopeGuard.h>
#include <folly/detail/SingletonStackTrace.h> #include <folly/detail/SingletonStackTrace.h>
#include <folly/portability/Config.h> #include <folly/portability/Config.h>
#include <folly/portability/FmtCompile.h>
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__ANDROID__) #if !defined(_WIN32) && !defined(__APPLE__) && !defined(__ANDROID__)
#define FOLLY_SINGLETON_HAVE_DLSYM 1 #define FOLLY_SINGLETON_HAVE_DLSYM 1
...@@ -158,7 +158,7 @@ void singletonPrintDestructionStackTrace(const TypeDescriptor& type) { ...@@ -158,7 +158,7 @@ void singletonPrintDestructionStackTrace(const TypeDescriptor& type) {
} }
[[noreturn]] void singletonThrowNullCreator(const std::type_info& type) { [[noreturn]] void singletonThrowNullCreator(const std::type_info& type) {
auto const msg = fmt::format(FMT_COMPILE( auto const msg = fmt::format(FOLLY_FMT_COMPILE(
"nullptr_t should be passed if you want {} to be default constructed"), "nullptr_t should be passed if you want {} to be default constructed"),
folly::StringPiece(demangle(type))); folly::StringPiece(demangle(type)));
throw std::logic_error(msg); throw std::logic_error(msg);
......
...@@ -18,18 +18,18 @@ ...@@ -18,18 +18,18 @@
#include <stdexcept> #include <stdexcept>
#include <folly/CompiledFormat.h> #include <folly/portability/FmtCompile.h>
namespace folly { namespace folly {
namespace detail { namespace detail {
std::string familyNameStrDefault(sa_family_t family) { std::string familyNameStrDefault(sa_family_t family) {
return fmt::format(FMT_COMPILE("sa_family_t({})"), family); return fmt::format(FOLLY_FMT_COMPILE("sa_family_t({})"), family);
} }
[[noreturn]] void getNthMSBitImplThrow(size_t bitCount, sa_family_t family) { [[noreturn]] void getNthMSBitImplThrow(size_t bitCount, sa_family_t family) {
throw std::invalid_argument(fmt::format( throw std::invalid_argument(fmt::format(
FMT_COMPILE("Bit index must be < {} for addresses of type: {}"), FOLLY_FMT_COMPILE("Bit index must be < {} for addresses of type: {}"),
bitCount, bitCount,
familyNameStr(family))); familyNameStr(family)));
} }
......
...@@ -18,18 +18,23 @@ ...@@ -18,18 +18,23 @@
#include <fmt/compile.h> #include <fmt/compile.h>
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 8 #if !defined(FMT_COMPILE)
#define FOLLY_FMT_COMPILE(format_str) format_str
#elif defined(_MSC_VER)
// Workaround broken constexpr in MSVC.
#define FOLLY_FMT_COMPILE(format_str) format_str
#elif defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 8
// Forcefully disable compiled format strings for GCC 8 & below until fmt is // Forcefully disable compiled format strings for GCC 8 & below until fmt is
// updated to do this automatically. // updated to do this automatically.
#undef FMT_COMPILE #define FOLLY_FMT_COMPILE(format_str) format_str
#endif
#ifdef _MSC_VER #else
// Workaround broken constexpr in MSVC.
#undef FMT_COMPILE #define FOLLY_FMT_COMPILE(format_str) FMT_COMPILE(format_str)
#endif
// Fallback to runtime format string processing for compatibility with fmt 6.x.
#ifndef FMT_COMPILE
#define FMT_COMPILE(format_str) format_str
#endif #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