forked from OSchip/llvm-project
clean up use of _WIN32
Replace the use of _WIN32 in libc++. Replace most use with a C runtime check _LIBCPP_MSVCRT or the new _LIBCPP_WIN32 to indicate that we are using the Win32 API. Use a new _LIBCPP_WCHAR_IS_UCS2 to indicate that we are on an environment that has a short wchar_t. llvm-svn: 290910
This commit is contained in:
parent
8a41319d8d
commit
b2826a1ddc
libcxx
include
src
|
@ -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 <sys/isa_defs.h>
|
||||
|
@ -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 @@ namespace std {
|
|||
|
||||
#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 @@ namespace std {
|
|||
#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 @@ namespace std {
|
|||
# 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 @@ template <unsigned> struct __static_assert_check {};
|
|||
#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 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
|
|||
#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
|
||||
|
|
|
@ -342,7 +342,7 @@ public:
|
|||
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;
|
||||
|
|
|
@ -110,10 +110,11 @@ _LIBCPP_ALWAYS_INLINE int __builtin_ctzll(unsigned long long mask)
|
|||
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<int>(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<unsigned long>(mask)))
|
||||
|
@ -121,8 +122,6 @@ _LIBCPP_ALWAYS_INLINE int __builtin_ctzll(unsigned long long mask)
|
|||
// Scan the High Word.
|
||||
if (_BitScanForward(&where, static_cast<unsigned long>(mask >> 32)))
|
||||
return static_cast<int>(where + 32); // Create a bit offset from the LSB.
|
||||
#else
|
||||
#error "Implementation of __builtin_ctzll required"
|
||||
#endif
|
||||
return 64;
|
||||
}
|
||||
|
@ -152,10 +151,11 @@ _LIBCPP_ALWAYS_INLINE int __builtin_clzll(unsigned long long mask)
|
|||
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<int>(63 - where);
|
||||
#elif defined(_WIN32)
|
||||
#else
|
||||
// Scan the high 32 bits.
|
||||
if (_BitScanReverse(&where, static_cast<unsigned long>(mask >> 32)))
|
||||
return static_cast<int>(63 -
|
||||
|
@ -163,8 +163,6 @@ _LIBCPP_ALWAYS_INLINE int __builtin_clzll(unsigned long long mask)
|
|||
// Scan the low 32 bits.
|
||||
if (_BitScanReverse(&where, static_cast<unsigned long>(mask)))
|
||||
return static_cast<int>(63 - where);
|
||||
#else
|
||||
#error "Implementation of __builtin_clzll required"
|
||||
#endif
|
||||
return 64; // Undefined Behavior.
|
||||
}
|
||||
|
|
|
@ -1681,9 +1681,9 @@ _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800);
|
|||
_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
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "system_error" // __throw_system_error
|
||||
#include <time.h> // clock_gettime, CLOCK_MONOTONIC and CLOCK_REALTIME
|
||||
|
||||
#if defined(_WIN32)
|
||||
#if defined(_LIBCPP_WIN32API)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define VC_EXTRA_LEAN
|
||||
#include <Windows.h>
|
||||
|
@ -22,13 +22,13 @@
|
|||
#else
|
||||
#if !defined(CLOCK_REALTIME)
|
||||
#include <sys/time.h> // 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/mach_time.h> // 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 @@ const bool system_clock::is_steady;
|
|||
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 @@ steady_clock::now() _NOEXCEPT
|
|||
return time_point(duration(fp()));
|
||||
}
|
||||
|
||||
#elif defined(_WIN32)
|
||||
#elif defined(_LIBCPP_WIN32API)
|
||||
|
||||
steady_clock::time_point
|
||||
steady_clock::now() _NOEXCEPT
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#ifndef _LIBCPP_CONFIG_ELAST
|
||||
#define _LIBCPP_CONFIG_ELAST
|
||||
|
||||
#if defined(_WIN32)
|
||||
#if defined(_LIBCPP_MSCVRT)
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
#include <errno.h>
|
||||
|
@ -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:
|
||||
|
|
|
@ -3254,7 +3254,7 @@ __codecvt_utf8<wchar_t>::do_out(state_type&,
|
|||
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<const uint16_t*>(frm);
|
||||
const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
|
||||
const uint16_t* _frm_nxt = _frm;
|
||||
|
@ -3266,7 +3266,7 @@ __codecvt_utf8<wchar_t>::do_out(state_type&,
|
|||
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
|
||||
uint8_t* _to_end = reinterpret_cast<uint8_t*>(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 @@ __codecvt_utf8<wchar_t>::do_in(state_type&,
|
|||
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
|
||||
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
|
||||
const uint8_t* _frm_nxt = _frm;
|
||||
#if _WIN32
|
||||
#if defined(_LIBCPP_SHORT_WCHAR)
|
||||
uint16_t* _to = reinterpret_cast<uint16_t*>(to);
|
||||
uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
|
||||
uint16_t* _to_nxt = _to;
|
||||
|
|
|
@ -72,7 +72,7 @@ operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC
|
|||
if (static_cast<size_t>(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<size_t>(alignment))) == nullptr)
|
||||
#else
|
||||
while (::posix_memalign(&p, static_cast<size_t>(alignment), size) != 0)
|
||||
|
|
|
@ -65,7 +65,7 @@ constexpr size_t strerror_buff_size = 1024;
|
|||
|
||||
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)
|
||||
|
|
|
@ -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 <unistd.h>
|
||||
#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 <windows.h>
|
||||
#endif
|
||||
#endif // defined(_LIBCPP_WIN32API)
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
|
@ -91,7 +92,7 @@ thread::hardware_concurrency() _NOEXCEPT
|
|||
if (result < 0)
|
||||
return 0;
|
||||
return static_cast<unsigned>(result);
|
||||
#elif defined(_WIN32)
|
||||
#elif defined(_LIBCPP_WIN32API)
|
||||
SYSTEM_INFO info;
|
||||
GetSystemInfo(&info);
|
||||
return info.dwNumberOfProcessors;
|
||||
|
|
Loading…
Reference in New Issue