diff --git a/folly/FBString.h b/folly/FBString.h index 4bf69f47882..13cd670e16c 100644 --- a/folly/FBString.h +++ b/folly/FBString.h @@ -2792,9 +2792,9 @@ operator<<( os.setstate(_ostream_type::badbit | _ostream_type::failbit); } } -#elif defined(_MSC_VER) +#elif defined(_MSC_VER) || defined(_CPPLIB_VER) + // MSVC nor Dinkumware headers define __ostream_insert typedef decltype(os.precision()) streamsize; - // MSVC doesn't define __ostream_insert os.write(str.data(), static_cast(str.size())); #else std::__ostream_insert(os, str.data(), str.size()); diff --git a/folly/SingletonThreadLocal.h b/folly/SingletonThreadLocal.h index 3eadb1a4239..a5d639ff24c 100644 --- a/folly/SingletonThreadLocal.h +++ b/folly/SingletonThreadLocal.h @@ -16,10 +16,10 @@ #pragma once +#include #include #include - #include #include #include diff --git a/folly/ThreadLocal.h b/folly/ThreadLocal.h index ca8fa30c448..05d2a875ec3 100644 --- a/folly/ThreadLocal.h +++ b/folly/ThreadLocal.h @@ -40,6 +40,7 @@ #pragma once +#include #include #include #include diff --git a/folly/Traits.h b/folly/Traits.h index 63f0ec5f31f..497f7006be7 100644 --- a/folly/Traits.h +++ b/folly/Traits.h @@ -428,16 +428,16 @@ struct IsLessThanComparable IsLessThanComparable; namespace traits_detail_IsNothrowSwappable { -#if defined(__cpp_lib_is_swappable) || (_CPPLIB_VER && _HAS_CXX17) +#if defined(__cpp_lib_is_swappable) || (_CPPLIB_VER && (_HAS_CPP17 || _HAS_CXX17)) // MSVC already implements the C++17 P0185R1 proposal which adds // std::is_nothrow_swappable, so use it instead if C++17 mode is // enabled. template using IsNothrowSwappable = std::is_nothrow_swappable; -#elif _CPPLIB_VER +#elif _MSC_VER // MSVC defines the base even if C++17 is disabled, and MSVC has -// issues with our fallback implementation due to over-eager -// evaluation of noexcept. +// issues with our fallback implementation due to +// over-eager evaluation of noexcept. template using IsNothrowSwappable = std::_Is_nothrow_swappable; #else diff --git a/folly/detail/ThreadLocalDetail.h b/folly/detail/ThreadLocalDetail.h index afe7d7ef0c8..148e564a541 100644 --- a/folly/detail/ThreadLocalDetail.h +++ b/folly/detail/ThreadLocalDetail.h @@ -18,14 +18,13 @@ #include +#include #include #include #include #include #include -#include - #include #include #include diff --git a/folly/memory/Malloc.h b/folly/memory/Malloc.h index 964320828f3..293094c134b 100644 --- a/folly/memory/Malloc.h +++ b/folly/memory/Malloc.h @@ -95,8 +95,8 @@ mallctlbymib(const size_t*, size_t, void*, size_t*, void*, size_t) // for malloc_usable_size // NOTE: FreeBSD 9 doesn't have malloc.h. Its definitions -// are found in stdlib.h. -#if __has_include() +// are found in stdlib.h and it errors when including malloc.h. +#if __has_include() && (!defined(__STDC__) || !__STDC__) #include #else #include diff --git a/folly/portability/Malloc.h b/folly/portability/Malloc.h index 4792bf6672e..bbbf2d1d6a0 100644 --- a/folly/portability/Malloc.h +++ b/folly/portability/Malloc.h @@ -26,7 +26,7 @@ // malloc_usable_size, and that's what we should be using. #include // @manual #else -#ifndef __APPLE__ +#if !defined(__APPLE__) && (!defined(__STDC__) || !__STDC__) #include #endif diff --git a/folly/system/ThreadId.h b/folly/system/ThreadId.h index fdced32982b..b7b232a4c12 100644 --- a/folly/system/ThreadId.h +++ b/folly/system/ThreadId.h @@ -23,6 +23,10 @@ #include #include +#if __has_include() +#include +#endif + namespace folly { /** @@ -84,8 +88,12 @@ inline uint64_t getOSThreadID() { return tid; #elif _WIN32 return uint64_t(GetCurrentThreadId()); -#else +#elif __linux__ return uint64_t(syscall(FOLLY_SYS_gettid)); +#elif __has_include() + return uint64_t(pthread_getthreadid_np()); +#else +#error Cannot define platform-specific get Thread ID. #endif } } // namespace folly