From 29a60e6deba1f4f77d7f688017af66c90f5d6580 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Wed, 12 Feb 2014 21:26:20 +0000 Subject: Rename Windows.h to WindowsSupport.h to avoid ambiguity git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201258 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/CrashRecoveryContext.cpp | 2 +- lib/Support/Threading.cpp | 2 +- lib/Support/Windows/DynamicLibrary.inc | 2 +- lib/Support/Windows/Host.inc | 2 +- lib/Support/Windows/Memory.inc | 2 +- lib/Support/Windows/Mutex.inc | 2 +- lib/Support/Windows/Path.inc | 2 +- lib/Support/Windows/Process.inc | 2 +- lib/Support/Windows/Program.inc | 2 +- lib/Support/Windows/RWMutex.inc | 2 +- lib/Support/Windows/Signals.inc | 2 +- lib/Support/Windows/ThreadLocal.inc | 2 +- lib/Support/Windows/TimeValue.inc | 2 +- lib/Support/Windows/Windows.h | 169 -------------------------------- lib/Support/Windows/WindowsSupport.h | 172 +++++++++++++++++++++++++++++++++ 15 files changed, 185 insertions(+), 182 deletions(-) delete mode 100644 lib/Support/Windows/Windows.h create mode 100644 lib/Support/Windows/WindowsSupport.h (limited to 'lib/Support') diff --git a/lib/Support/CrashRecoveryContext.cpp b/lib/Support/CrashRecoveryContext.cpp index 92c370dda4..29f73fc539 100644 --- a/lib/Support/CrashRecoveryContext.cpp +++ b/lib/Support/CrashRecoveryContext.cpp @@ -132,7 +132,7 @@ CrashRecoveryContext::unregisterCleanup(CrashRecoveryContextCleanup *cleanup) { #ifdef LLVM_ON_WIN32 -#include "Windows/Windows.h" +#include "Windows/WindowsSupport.h" // On Windows, we can make use of vectored exception handling to // catch most crashing situations. Note that this does mean diff --git a/lib/Support/Threading.cpp b/lib/Support/Threading.cpp index 13fba2ea25..9d7ac6c18d 100644 --- a/lib/Support/Threading.cpp +++ b/lib/Support/Threading.cpp @@ -103,7 +103,7 @@ void llvm::llvm_execute_on_thread(void (*Fn)(void*), void *UserData, ::pthread_attr_destroy(&Attr); } #elif LLVM_ENABLE_THREADS!=0 && defined(LLVM_ON_WIN32) -#include "Windows/Windows.h" +#include "Windows/WindowsSupport.h" #include struct ThreadInfo { diff --git a/lib/Support/Windows/DynamicLibrary.inc b/lib/Support/Windows/DynamicLibrary.inc index 5a7b21920a..504471eaff 100644 --- a/lib/Support/Windows/DynamicLibrary.inc +++ b/lib/Support/Windows/DynamicLibrary.inc @@ -11,7 +11,7 @@ // //===----------------------------------------------------------------------===// -#include "Windows.h" +#include "WindowsSupport.h" #ifdef __MINGW32__ #include diff --git a/lib/Support/Windows/Host.inc b/lib/Support/Windows/Host.inc index 2e6d6f1903..7bda89dc49 100644 --- a/lib/Support/Windows/Host.inc +++ b/lib/Support/Windows/Host.inc @@ -11,7 +11,7 @@ // //===----------------------------------------------------------------------===// -#include "Windows.h" +#include "WindowsSupport.h" #include #include diff --git a/lib/Support/Windows/Memory.inc b/lib/Support/Windows/Memory.inc index 12604524d4..ebe78782b9 100644 --- a/lib/Support/Windows/Memory.inc +++ b/lib/Support/Windows/Memory.inc @@ -17,7 +17,7 @@ #include "llvm/Support/Process.h" // The Windows.h header must be the last one included. -#include "Windows.h" +#include "WindowsSupport.h" namespace { diff --git a/lib/Support/Windows/Mutex.inc b/lib/Support/Windows/Mutex.inc index 583dc6359a..ab79d07912 100644 --- a/lib/Support/Windows/Mutex.inc +++ b/lib/Support/Windows/Mutex.inc @@ -16,7 +16,7 @@ //=== is guaranteed to work on *all* Win32 variants. //===----------------------------------------------------------------------===// -#include "Windows.h" +#include "WindowsSupport.h" #include "llvm/Support/Mutex.h" namespace llvm { diff --git a/lib/Support/Windows/Path.inc b/lib/Support/Windows/Path.inc index 8329d271b3..46e9ce7acb 100644 --- a/lib/Support/Windows/Path.inc +++ b/lib/Support/Windows/Path.inc @@ -24,7 +24,7 @@ // These two headers must be included last, and make sure shlobj is required // after Windows.h to make sure it picks up our definition of _WIN32_WINNT -#include "Windows.h" +#include "WindowsSupport.h" #include #undef max diff --git a/lib/Support/Windows/Process.inc b/lib/Support/Windows/Process.inc index a0e3bc413a..a794ca08f6 100644 --- a/lib/Support/Windows/Process.inc +++ b/lib/Support/Windows/Process.inc @@ -15,7 +15,7 @@ #include // The Windows.h header must be after LLVM and standard headers. -#include "Windows.h" +#include "WindowsSupport.h" #include #include diff --git a/lib/Support/Windows/Program.inc b/lib/Support/Windows/Program.inc index dc09738e2e..365e87eea5 100644 --- a/lib/Support/Windows/Program.inc +++ b/lib/Support/Windows/Program.inc @@ -11,7 +11,7 @@ // //===----------------------------------------------------------------------===// -#include "Windows.h" +#include "WindowsSupport.h" #include "llvm/ADT/OwningPtr.h" #include "llvm/Support/FileSystem.h" #include diff --git a/lib/Support/Windows/RWMutex.inc b/lib/Support/Windows/RWMutex.inc index c4318448e7..00d0e93d8d 100644 --- a/lib/Support/Windows/RWMutex.inc +++ b/lib/Support/Windows/RWMutex.inc @@ -16,7 +16,7 @@ //=== is guaranteed to work on *all* Win32 variants. //===----------------------------------------------------------------------===// -#include "Windows.h" +#include "WindowsSupport.h" namespace llvm { using namespace sys; diff --git a/lib/Support/Windows/Signals.inc b/lib/Support/Windows/Signals.inc index 5add76a0c0..a28b0b8003 100644 --- a/lib/Support/Windows/Signals.inc +++ b/lib/Support/Windows/Signals.inc @@ -17,7 +17,7 @@ #include // The Windows.h header must be after LLVM and standard headers. -#include "Windows.h" +#include "WindowsSupport.h" #ifdef __MINGW32__ #include diff --git a/lib/Support/Windows/ThreadLocal.inc b/lib/Support/Windows/ThreadLocal.inc index 057deb325d..3914cf72fa 100644 --- a/lib/Support/Windows/ThreadLocal.inc +++ b/lib/Support/Windows/ThreadLocal.inc @@ -16,7 +16,7 @@ //=== is guaranteed to work on *all* Win32 variants. //===----------------------------------------------------------------------===// -#include "Windows.h" +#include "WindowsSupport.h" #include "llvm/Support/ThreadLocal.h" namespace llvm { diff --git a/lib/Support/Windows/TimeValue.inc b/lib/Support/Windows/TimeValue.inc index 98b07d6e44..6c59024d9c 100644 --- a/lib/Support/Windows/TimeValue.inc +++ b/lib/Support/Windows/TimeValue.inc @@ -11,7 +11,7 @@ // //===----------------------------------------------------------------------===// -#include "Windows.h" +#include "WindowsSupport.h" #include #include diff --git a/lib/Support/Windows/Windows.h b/lib/Support/Windows/Windows.h deleted file mode 100644 index 5666de267d..0000000000 --- a/lib/Support/Windows/Windows.h +++ /dev/null @@ -1,169 +0,0 @@ -//===- Win32/Win32.h - Common Win32 Include File ----------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines things specific to Win32 implementations. -// -//===----------------------------------------------------------------------===// - -//===----------------------------------------------------------------------===// -//=== WARNING: Implementation here must contain only generic Win32 code that -//=== is guaranteed to work on *all* Win32 variants. -//===----------------------------------------------------------------------===// - -// mingw-w64 tends to define it as 0x0502 in its headers. -#undef _WIN32_WINNT -#undef _WIN32_IE - -// Require at least Windows XP(5.1) API. -#define _WIN32_WINNT 0x0501 -#define _WIN32_IE 0x0600 // MinGW at it again. -#define WIN32_LEAN_AND_MEAN - -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/Config/config.h" // Get build system configuration settings -#include "llvm/Support/Compiler.h" -#include "llvm/Support/system_error.h" -#include -#include -#include -#include -#include - -inline bool MakeErrMsg(std::string* ErrMsg, const std::string& prefix) { - if (!ErrMsg) - return true; - char *buffer = NULL; - DWORD R = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM, - NULL, GetLastError(), 0, (LPSTR)&buffer, 1, NULL); - if (R) - *ErrMsg = prefix + buffer; - else - *ErrMsg = prefix + "Unknown error"; - - LocalFree(buffer); - return R != 0; -} - -template -class ScopedHandle { - typedef typename HandleTraits::handle_type handle_type; - handle_type Handle; - - ScopedHandle(const ScopedHandle &other); // = delete; - void operator=(const ScopedHandle &other); // = delete; -public: - ScopedHandle() - : Handle(HandleTraits::GetInvalid()) {} - - explicit ScopedHandle(handle_type h) - : Handle(h) {} - - ~ScopedHandle() { - if (HandleTraits::IsValid(Handle)) - HandleTraits::Close(Handle); - } - - handle_type take() { - handle_type t = Handle; - Handle = HandleTraits::GetInvalid(); - return t; - } - - ScopedHandle &operator=(handle_type h) { - if (HandleTraits::IsValid(Handle)) - HandleTraits::Close(Handle); - Handle = h; - return *this; - } - - // True if Handle is valid. - LLVM_EXPLICIT operator bool() const { - return HandleTraits::IsValid(Handle) ? true : false; - } - - operator handle_type() const { - return Handle; - } -}; - -struct CommonHandleTraits { - typedef HANDLE handle_type; - - static handle_type GetInvalid() { - return INVALID_HANDLE_VALUE; - } - - static void Close(handle_type h) { - ::CloseHandle(h); - } - - static bool IsValid(handle_type h) { - return h != GetInvalid(); - } -}; - -struct JobHandleTraits : CommonHandleTraits { - static handle_type GetInvalid() { - return NULL; - } -}; - -struct CryptContextTraits : CommonHandleTraits { - typedef HCRYPTPROV handle_type; - - static handle_type GetInvalid() { - return 0; - } - - static void Close(handle_type h) { - ::CryptReleaseContext(h, 0); - } - - static bool IsValid(handle_type h) { - return h != GetInvalid(); - } -}; - -struct FindHandleTraits : CommonHandleTraits { - static void Close(handle_type h) { - ::FindClose(h); - } -}; - -struct FileHandleTraits : CommonHandleTraits {}; - -typedef ScopedHandle ScopedCommonHandle; -typedef ScopedHandle ScopedFileHandle; -typedef ScopedHandle ScopedCryptContext; -typedef ScopedHandle ScopedFindHandle; -typedef ScopedHandle ScopedJobHandle; - -namespace llvm { -template -class SmallVectorImpl; - -template -typename SmallVectorImpl::const_pointer -c_str(SmallVectorImpl &str) { - str.push_back(0); - str.pop_back(); - return str.data(); -} - -namespace sys { -namespace windows { -error_code UTF8ToUTF16(StringRef utf8, - SmallVectorImpl &utf16); -error_code UTF16ToUTF8(const wchar_t *utf16, size_t utf16_len, - SmallVectorImpl &utf8); -} // end namespace windows -} // end namespace sys -} // end namespace llvm. diff --git a/lib/Support/Windows/WindowsSupport.h b/lib/Support/Windows/WindowsSupport.h new file mode 100644 index 0000000000..6bef444460 --- /dev/null +++ b/lib/Support/Windows/WindowsSupport.h @@ -0,0 +1,172 @@ +//===- WindowsSupport.h - Common Windows Include File -----------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines things specific to Windows implementations. In addition to +// providing some helpers for working with win32 APIs, this header wraps +// with some portability macros. Always include WindowsSupport.h +// instead of including directly. +// +//===----------------------------------------------------------------------===// + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only generic Win32 code that +//=== is guaranteed to work on *all* Win32 variants. +//===----------------------------------------------------------------------===// + +// mingw-w64 tends to define it as 0x0502 in its headers. +#undef _WIN32_WINNT +#undef _WIN32_IE + +// Require at least Windows XP(5.1) API. +#define _WIN32_WINNT 0x0501 +#define _WIN32_IE 0x0600 // MinGW at it again. +#define WIN32_LEAN_AND_MEAN + +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Config/config.h" // Get build system configuration settings +#include "llvm/Support/Compiler.h" +#include "llvm/Support/system_error.h" +#include +#include +#include +#include +#include + +inline bool MakeErrMsg(std::string* ErrMsg, const std::string& prefix) { + if (!ErrMsg) + return true; + char *buffer = NULL; + DWORD R = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM, + NULL, GetLastError(), 0, (LPSTR)&buffer, 1, NULL); + if (R) + *ErrMsg = prefix + buffer; + else + *ErrMsg = prefix + "Unknown error"; + + LocalFree(buffer); + return R != 0; +} + +template +class ScopedHandle { + typedef typename HandleTraits::handle_type handle_type; + handle_type Handle; + + ScopedHandle(const ScopedHandle &other); // = delete; + void operator=(const ScopedHandle &other); // = delete; +public: + ScopedHandle() + : Handle(HandleTraits::GetInvalid()) {} + + explicit ScopedHandle(handle_type h) + : Handle(h) {} + + ~ScopedHandle() { + if (HandleTraits::IsValid(Handle)) + HandleTraits::Close(Handle); + } + + handle_type take() { + handle_type t = Handle; + Handle = HandleTraits::GetInvalid(); + return t; + } + + ScopedHandle &operator=(handle_type h) { + if (HandleTraits::IsValid(Handle)) + HandleTraits::Close(Handle); + Handle = h; + return *this; + } + + // True if Handle is valid. + LLVM_EXPLICIT operator bool() const { + return HandleTraits::IsValid(Handle) ? true : false; + } + + operator handle_type() const { + return Handle; + } +}; + +struct CommonHandleTraits { + typedef HANDLE handle_type; + + static handle_type GetInvalid() { + return INVALID_HANDLE_VALUE; + } + + static void Close(handle_type h) { + ::CloseHandle(h); + } + + static bool IsValid(handle_type h) { + return h != GetInvalid(); + } +}; + +struct JobHandleTraits : CommonHandleTraits { + static handle_type GetInvalid() { + return NULL; + } +}; + +struct CryptContextTraits : CommonHandleTraits { + typedef HCRYPTPROV handle_type; + + static handle_type GetInvalid() { + return 0; + } + + static void Close(handle_type h) { + ::CryptReleaseContext(h, 0); + } + + static bool IsValid(handle_type h) { + return h != GetInvalid(); + } +}; + +struct FindHandleTraits : CommonHandleTraits { + static void Close(handle_type h) { + ::FindClose(h); + } +}; + +struct FileHandleTraits : CommonHandleTraits {}; + +typedef ScopedHandle ScopedCommonHandle; +typedef ScopedHandle ScopedFileHandle; +typedef ScopedHandle ScopedCryptContext; +typedef ScopedHandle ScopedFindHandle; +typedef ScopedHandle ScopedJobHandle; + +namespace llvm { +template +class SmallVectorImpl; + +template +typename SmallVectorImpl::const_pointer +c_str(SmallVectorImpl &str) { + str.push_back(0); + str.pop_back(); + return str.data(); +} + +namespace sys { +namespace windows { +error_code UTF8ToUTF16(StringRef utf8, + SmallVectorImpl &utf16); +error_code UTF16ToUTF8(const wchar_t *utf16, size_t utf16_len, + SmallVectorImpl &utf8); +} // end namespace windows +} // end namespace sys +} // end namespace llvm. -- cgit v1.2.3