Index: include/__config =================================================================== --- include/__config +++ include/__config @@ -154,11 +154,13 @@ # define _LIBCPP_HAS_QUICK_EXIT #endif // __NetBSD__ -#ifdef _WIN32 +#if defined(_WIN32) +# define _LIBCPP_WIN32API 1 # define _LIBCPP_LITTLE_ENDIAN 1 # define _LIBCPP_BIG_ENDIAN 0 +# define _LIBCPP_SHORT_WCHAR 1 // Compiler intrinsics (MSVC) -#if defined(_MSC_VER) && _MSC_VER >= 1400 +# if defined(_MSC_VER) && _MSC_VER >= 1400 # define _LIBCPP_HAS_IS_BASE_OF # endif # if defined(_MSC_VER) && !defined(__clang__) @@ -167,11 +169,11 @@ # define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) # define _LIBCPP_WARNING(x) __pragma(message(__FILE__ "(" _LIBCPP_TOSTRING(__LINE__) ") : warning note: " x)) # endif -# // If mingw not explicitly detected, assume using MS C runtime only. +// If mingw not explicitly detected, assume using MS C runtime only. # ifndef __MINGW32__ # define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library # endif -#endif // _WIN32 +#endif // defined(_WIN32) #ifdef __sun__ # include @@ -195,7 +197,7 @@ // including accesses to the special files under /dev. C++11's // std::random_device is instead exposed through a NaCl syscall. # define _LIBCPP_USING_NACL_RANDOM -#elif defined(_WIN32) +#elif defined(_LIBCPP_WIN32API) # define _LIBCPP_USING_WIN32_RANDOM #else # define _LIBCPP_USING_DEV_RANDOM @@ -520,8 +522,15 @@ #endif // __clang__ || __GNUC__ || _MSC_VER || __IBMCPP__ +#if defined(__ELF__) +#define _LIBCPP_OBJECT_FORMAT_ELF 1 +#elif defined(__MACH__) +#define _LIBCPP_OBJECT_FORMAT_MACHO 1 +#else +#define _LIBCPP_OBJECT_FORMAT_COFF 1 +#endif -#ifdef _WIN32 +#if defined(_LIBCPP_OBJECT_FORMAT_COFF) #if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) # define _LIBCPP_DLL_VIS # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS @@ -546,6 +555,7 @@ #define _LIBCPP_TYPE_VIS_ONLY #define _LIBCPP_FUNC_VIS_ONLY #define _LIBCPP_ENUM_VIS + #if defined(_LIBCPP_MSVC) # define _LIBCPP_INLINE_VISIBILITY __forceinline # define _LIBCPP_ALWAYS_INLINE __forceinline @@ -555,7 +565,7 @@ # define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__)) # define _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY __attribute__ ((__always_inline__)) #endif -#endif // _WIN32 +#endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) #ifndef _LIBCPP_HIDDEN #if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) @@ -778,14 +788,14 @@ #define _LIBCPP_NONUNIQUE_RTTI_BIT (1ULL << 63) #endif -#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_WIN32) || \ +#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT) || \ defined(__sun__) || defined(__NetBSD__) || defined(__CloudABI__) #define _LIBCPP_LOCALE__L_EXTENSIONS 1 #endif #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) // Most unix variants have catopen. These are the specific ones that don't. -#if !defined(_WIN32) && !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) +#if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) #define _LIBCPP_HAS_CATOPEN 1 #endif #endif @@ -959,7 +969,7 @@ #endif #if !defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS) -#if defined(_WIN32) || defined(_NEWLIB_VERSION) +#if defined(_LIBCPP_MSVCRT) || defined(_NEWLIB_VERSION) #define _LIBCPP_HAS_NO_OFF_T_FUNCTIONS #endif #endif Index: include/__locale =================================================================== --- include/__locale +++ include/__locale @@ -342,7 +342,7 @@ static const mask punct = _ISpunct; static const mask xdigit = _ISxdigit; static const mask blank = _ISblank; -#elif defined(_WIN32) +#elif defined(_LIBCPP_MSVCRT) typedef unsigned short mask; static const mask space = _SPACE; static const mask print = _BLANK|_PUNCT|_ALPHA|_DIGIT; Index: include/support/win32/support.h =================================================================== --- include/support/win32/support.h +++ include/support/win32/support.h @@ -110,10 +110,11 @@ unsigned long where; // Search from LSB to MSB for first set bit. // Returns zero if no set bit is found. -#if defined(_WIN64) +#if (defined(_M_ARM) || defined(__arm__)) || \ + (defined(_M_AMD64) || defined(__x86_64__)) if (_BitScanForward64(&where, mask)) return static_cast(where); -#elif defined(_WIN32) +#else // Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls. // Scan the Low Word. if (_BitScanForward(&where, static_cast(mask))) @@ -121,8 +122,6 @@ // Scan the High Word. if (_BitScanForward(&where, static_cast(mask >> 32))) return static_cast(where + 32); // Create a bit offset from the LSB. -#else -#error "Implementation of __builtin_ctzll required" #endif return 64; } @@ -152,10 +151,11 @@ unsigned long where; // BitScanReverse scans from MSB to LSB for first set bit. // Returns 0 if no set bit is found. -#if defined(_WIN64) +#if (defined(_M_ARM) || defined(__arm__)) || \ + (defined(_M_AMD64) || defined(__x86_64__)) if (_BitScanReverse64(&where, mask)) return static_cast(63 - where); -#elif defined(_WIN32) +#else // Scan the high 32 bits. if (_BitScanReverse(&where, static_cast(mask >> 32))) return static_cast(63 - @@ -163,8 +163,6 @@ // Scan the low 32 bits. if (_BitScanReverse(&where, static_cast(mask))) return static_cast(63 - where); -#else -#error "Implementation of __builtin_clzll required" #endif return 64; // Undefined Behavior. } Index: include/type_traits =================================================================== --- include/type_traits +++ include/type_traits @@ -1681,9 +1681,9 @@ _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000); _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000); // PE/COFF does not support alignment beyond 8192 (=0x2000) -#if !defined(_WIN32) +#if !defined(_LIBCPP_OBJECT_FORMAT_COFF) _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000); -#endif // !_WIN32 +#endif // !defined(_LIBCPP_OBJECT_FORMAT_COFF) #undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION Index: src/chrono.cpp =================================================================== --- src/chrono.cpp +++ src/chrono.cpp @@ -12,7 +12,7 @@ #include "system_error" // __throw_system_error #include // clock_gettime, CLOCK_MONOTONIC and CLOCK_REALTIME -#if defined(_WIN32) +#if defined(_LIBCPP_WIN32API) #define WIN32_LEAN_AND_MEAN #define VC_EXTRA_LEAN #include @@ -22,13 +22,13 @@ #else #if !defined(CLOCK_REALTIME) #include // for gettimeofday and timeval -#endif -#endif +#endif // !defined(CLOCK_REALTIME) +#endif // defined(_LIBCPP_WIN32API) #if !defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) #if __APPLE__ #include // mach_absolute_time, mach_timebase_info_data_t -#elif !defined(_WIN32) && !defined(CLOCK_MONOTONIC) +#elif !defined(_LIBCPP_WIN32API) && !defined(CLOCK_MONOTONIC) #error "Monotonic clock not implemented" #endif #endif @@ -45,7 +45,7 @@ system_clock::time_point system_clock::now() _NOEXCEPT { -#if defined(_WIN32) +#if defined(_LIBCPP_WIN32API) // FILETIME is in 100ns units using filetime_duration = _VSTD::chrono::duration<__int64, @@ -158,7 +158,7 @@ return time_point(duration(fp())); } -#elif defined(_WIN32) +#elif defined(_LIBCPP_WIN32API) steady_clock::time_point steady_clock::now() _NOEXCEPT Index: src/include/config_elast.h =================================================================== --- src/include/config_elast.h +++ src/include/config_elast.h @@ -10,7 +10,7 @@ #ifndef _LIBCPP_CONFIG_ELAST #define _LIBCPP_CONFIG_ELAST -#if defined(_WIN32) +#if defined(_LIBCPP_MSCVRT) #include #else #include @@ -28,7 +28,7 @@ // No _LIBCPP_ELAST needed on Apple #elif defined(__sun__) #define _LIBCPP_ELAST ESTALE -#elif defined(_WIN32) +#elif defined(_LIBCPP_MSCVRT) #define _LIBCPP_ELAST _sys_nerr #else // Warn here so that the person doing the libcxx port has an easier time: Index: src/locale.cpp =================================================================== --- src/locale.cpp +++ src/locale.cpp @@ -3254,7 +3254,7 @@ const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt, extern_type* to, extern_type* to_end, extern_type*& to_nxt) const { -#if _WIN32 +#if defined(_LIBCPP_SHORT_WCHAR) const uint16_t* _frm = reinterpret_cast(frm); const uint16_t* _frm_end = reinterpret_cast(frm_end); const uint16_t* _frm_nxt = _frm; @@ -3266,7 +3266,7 @@ uint8_t* _to = reinterpret_cast(to); uint8_t* _to_end = reinterpret_cast(to_end); uint8_t* _to_nxt = _to; -#if _WIN32 +#if defined(_LIBCPP_SHORT_WCHAR) result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, _Maxcode_, _Mode_); #else @@ -3286,7 +3286,7 @@ const uint8_t* _frm = reinterpret_cast(frm); const uint8_t* _frm_end = reinterpret_cast(frm_end); const uint8_t* _frm_nxt = _frm; -#if _WIN32 +#if defined(_LIBCPP_SHORT_WCHAR) uint16_t* _to = reinterpret_cast(to); uint16_t* _to_end = reinterpret_cast(to_end); uint16_t* _to_nxt = _to; Index: src/new.cpp =================================================================== --- src/new.cpp +++ src/new.cpp @@ -72,7 +72,7 @@ if (static_cast(alignment) < sizeof(void*)) alignment = std::align_val_t(sizeof(void*)); void* p; -#if defined(_WIN32) +#if defined(_LIBCPP_MSVCRT) while ((p = _aligned_malloc(size, static_cast(alignment))) == nullptr) #else while (::posix_memalign(&p, static_cast(alignment), size) != 0) Index: src/system_error.cpp =================================================================== --- src/system_error.cpp +++ src/system_error.cpp @@ -65,7 +65,7 @@ string do_strerror_r(int ev); -#if defined(_WIN32) +#if defined(_LIBCPP_MSVCRT) string do_strerror_r(int ev) { char buffer[strerror_buff_size]; if (::strerror_s(buffer, strerror_buff_size, ev) == 0) Index: src/thread.cpp =================================================================== --- src/thread.cpp +++ src/thread.cpp @@ -24,16 +24,17 @@ # endif // defined(BSD) #endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) -#if !defined(_WIN32) +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) # include -#endif // !_WIN32 +#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) #if defined(__NetBSD__) #pragma weak pthread_create // Do not create libpthread dependency #endif -#if defined(_WIN32) + +#if defined(_LIBCPP_WIN32API) #include -#endif +#endif // defined(_LIBCPP_WIN32API) _LIBCPP_BEGIN_NAMESPACE_STD @@ -91,7 +92,7 @@ if (result < 0) return 0; return static_cast(result); -#elif defined(_WIN32) +#elif defined(_LIBCPP_WIN32API) SYSTEM_INFO info; GetSystemInfo(&info); return info.dwNumberOfProcessors;