From 7acd886ecfa0adc8a14476eafe8cf1fa981cfe18 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 11 Jun 2014 19:05:50 +0000 Subject: Use std::error_code instead of llvm::error_code. The idea of this patch is to turn llvm/Support/system_error.h into a transitional header that just brings in the erorr_code api to the llvm namespace. I will remove it shortly afterwards. The cases where the general idea needed some tweaking: * std::errc is a namespace in msvc, so we cannot use "using std::errc". I could add an #ifdef, but there were not that many uses, so I just added std:: to them in this patch. * Template specialization had to be moved to the std namespace in this patch set already. * The msvc implementation of default_error_condition doesn't seem to provide the same transformations as we need. Not too surprising since the standard doesn't actually say what "equivalent" means. I fixed the problem by keeping our old mapping and using it at error_code construction time. Despite these shortcomings I think this is still a good thing. Some reasons: * The different implementations of system_error might improve over time. * It removes 925 lines of code from llvm already. * It removes 6313 bytes from the text segment of the clang binary when it is built with gcc and 2816 bytes when building with clang and libstdc++. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210687 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Object/Error.cpp | 2 +- lib/ProfileData/InstrProf.cpp | 2 +- lib/Support/CMakeLists.txt | 4 +- lib/Support/FileOutputBuffer.cpp | 2 +- lib/Support/LockFileManager.cpp | 4 +- lib/Support/MemoryBuffer.cpp | 2 +- lib/Support/Path.cpp | 10 +-- lib/Support/Unix/Path.inc | 12 +-- lib/Support/Unix/system_error.inc | 34 --------- lib/Support/Windows/Path.inc | 17 +++-- lib/Support/Windows/Process.inc | 3 +- lib/Support/Windows/system_error.inc | 141 ----------------------------------- lib/Support/WindowsError.cpp | 115 ++++++++++++++++++++++++++++ lib/Support/YAMLTraits.cpp | 6 +- lib/Support/system_error.cpp | 121 ------------------------------ 15 files changed, 147 insertions(+), 328 deletions(-) delete mode 100644 lib/Support/Unix/system_error.inc delete mode 100644 lib/Support/Windows/system_error.inc create mode 100644 lib/Support/WindowsError.cpp delete mode 100644 lib/Support/system_error.cpp (limited to 'lib') diff --git a/lib/Object/Error.cpp b/lib/Object/Error.cpp index 6bcc6f9a78..a373cff195 100644 --- a/lib/Object/Error.cpp +++ b/lib/Object/Error.cpp @@ -50,7 +50,7 @@ std::string _object_error_category::message(int EV) const { error_condition _object_error_category::default_error_condition(int EV) const { if (static_cast(EV) == object_error::success) return error_condition(); - return errc::invalid_argument; + return std::errc::invalid_argument; } const error_category &object::object_category() { diff --git a/lib/ProfileData/InstrProf.cpp b/lib/ProfileData/InstrProf.cpp index 94a79e9ed0..eed517df05 100644 --- a/lib/ProfileData/InstrProf.cpp +++ b/lib/ProfileData/InstrProf.cpp @@ -55,7 +55,7 @@ class InstrProfErrorCategoryType : public error_category { error_condition default_error_condition(int EV) const LLVM_NOEXCEPT override { if (static_cast(EV) == instrprof_error::success) return error_condition(); - return errc::invalid_argument; + return std::errc::invalid_argument; } }; } diff --git a/lib/Support/CMakeLists.txt b/lib/Support/CMakeLists.txt index 7f93a6c595..9febb84f2b 100644 --- a/lib/Support/CMakeLists.txt +++ b/lib/Support/CMakeLists.txt @@ -83,13 +83,13 @@ add_llvm_library(LLVMSupport RWMutex.cpp SearchForAddressOfSpecialSymbol.cpp Signals.cpp - system_error.cpp TargetRegistry.cpp ThreadLocal.cpp Threading.cpp TimeValue.cpp Valgrind.cpp Watchdog.cpp + WindowsError.cpp ADDITIONAL_HEADERS Unix/Host.inc @@ -100,7 +100,6 @@ add_llvm_library(LLVMSupport Unix/Program.inc Unix/RWMutex.inc Unix/Signals.inc - Unix/system_error.inc Unix/ThreadLocal.inc Unix/TimeValue.inc Unix/Watchdog.inc @@ -113,7 +112,6 @@ add_llvm_library(LLVMSupport Windows/Program.inc Windows/RWMutex.inc Windows/Signals.inc - Windows/system_error.inc Windows/ThreadLocal.inc Windows/TimeValue.inc Windows/Watchdog.inc diff --git a/lib/Support/FileOutputBuffer.cpp b/lib/Support/FileOutputBuffer.cpp index 5f74d00c6b..b869054338 100644 --- a/lib/Support/FileOutputBuffer.cpp +++ b/lib/Support/FileOutputBuffer.cpp @@ -51,7 +51,7 @@ error_code FileOutputBuffer::create(StringRef FilePath, if (EC) return EC; else - return make_error_code(errc::operation_not_permitted); + return make_error_code(std::errc::operation_not_permitted); } // Delete target file. diff --git a/lib/Support/LockFileManager.cpp b/lib/Support/LockFileManager.cpp index 05e75cff1a..2b7fc812d5 100644 --- a/lib/Support/LockFileManager.cpp +++ b/lib/Support/LockFileManager.cpp @@ -114,7 +114,7 @@ LockFileManager::LockFileManager(StringRef FileName) if (Out.has_error()) { // We failed to write out PID, so make up an excuse, remove the // unique lock file, and fail. - Error = make_error_code(errc::no_space_on_device); + Error = make_error_code(std::errc::no_space_on_device); sys::fs::remove(UniqueLockFileName.c_str()); return; } @@ -127,7 +127,7 @@ LockFileManager::LockFileManager(StringRef FileName) if (!EC) return; - if (EC != errc::file_exists) { + if (EC != std::errc::file_exists) { Error = EC; return; } diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp index b7298090db..1f69326a1d 100644 --- a/lib/Support/MemoryBuffer.cpp +++ b/lib/Support/MemoryBuffer.cpp @@ -361,7 +361,7 @@ static error_code getOpenFileImpl(int FD, const char *Filename, if (!Buf) { // Failed to create a buffer. The only way it can fail is if // new(std::nothrow) returns 0. - return make_error_code(errc::not_enough_memory); + return make_error_code(std::errc::not_enough_memory); } std::unique_ptr SB(Buf); diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index 76bee47984..a9ac88e5d3 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -204,7 +204,7 @@ retry_random_path: if (error_code EC = sys::fs::openFileForWrite(Twine(ResultPath.begin()), ResultFD, sys::fs::F_RW | sys::fs::F_Excl, Mode)) { - if (EC == errc::file_exists) + if (EC == std::errc::file_exists) goto retry_random_path; return EC; } @@ -224,7 +224,7 @@ retry_random_path: case FS_Dir: { if (error_code EC = sys::fs::create_directory(ResultPath.begin(), false)) { - if (EC == errc::file_exists) + if (EC == std::errc::file_exists) goto retry_random_path; return EC; } @@ -829,7 +829,7 @@ error_code create_directories(const Twine &Path, bool IgnoreExisting) { error_code EC = create_directory(P, IgnoreExisting); // If we succeeded, or had any error other than the parent not existing, just // return it. - if (EC != errc::no_such_file_or_directory) + if (EC != std::errc::no_such_file_or_directory) return EC; // We failed because of a no_such_file_or_directory, try to create the @@ -896,7 +896,7 @@ error_code has_magic(const Twine &path, const Twine &magic, bool &result) { SmallString<32> Buffer; if (error_code ec = get_magic(path, Magic.size(), Buffer)) { - if (ec == errc::value_too_large) { + if (ec == std::errc::value_too_large) { // Magic.size() > file_size(Path). result = false; return error_code(); @@ -1043,7 +1043,7 @@ error_code has_magic(const Twine &path, const Twine &magic, bool &result) { error_code identify_magic(const Twine &path, file_magic &result) { SmallString<32> Magic; error_code ec = get_magic(path, Magic.capacity(), Magic); - if (ec && ec != errc::value_too_large) + if (ec && ec != std::errc::value_too_large) return ec; result = identify_magic(Magic); diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc index 11ea10e120..ef291db52d 100644 --- a/lib/Support/Unix/Path.inc +++ b/lib/Support/Unix/Path.inc @@ -317,7 +317,7 @@ error_code remove(const Twine &path, bool IgnoreNonExisting) { // effectively prevents LLVM from erasing things like /dev/null, any block // special file, or other things that aren't "regular" files. if (!S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode) && !S_ISLNK(buf.st_mode)) - return make_error_code(errc::operation_not_permitted); + return make_error_code(std::errc::operation_not_permitted); if (::remove(p.begin()) == -1) { if (errno != ENOENT || !IgnoreNonExisting) @@ -402,7 +402,7 @@ static error_code fillStatus(int StatRet, const struct stat &Status, file_status &Result) { if (StatRet != 0) { error_code ec(errno, generic_category()); - if (ec == errc::no_such_file_or_directory) + if (ec == std::errc::no_such_file_or_directory) Result = file_status(file_type::file_not_found); else Result = file_status(file_type::status_error); @@ -466,7 +466,7 @@ error_code setLastModificationAndAccessTime(int FD, TimeValue Time) { return error_code(); #else #warning Missing futimes() and futimens() - return make_error_code(errc::not_supported); + return make_error_code(std::errc::not_supported); #endif } @@ -510,7 +510,7 @@ mapped_file_region::mapped_file_region(const Twine &path, , Mapping() { // Make sure that the requested size fits within SIZE_T. if (length > std::numeric_limits::max()) { - ec = make_error_code(errc::invalid_argument); + ec = make_error_code(std::errc::invalid_argument); return; } @@ -539,7 +539,7 @@ mapped_file_region::mapped_file_region(int fd, , Mapping() { // Make sure that the requested size fits within SIZE_T. if (length > std::numeric_limits::max()) { - ec = make_error_code(errc::invalid_argument); + ec = make_error_code(std::errc::invalid_argument); return; } @@ -645,7 +645,7 @@ error_code get_magic(const Twine &path, uint32_t len, if (std::feof(file) != 0) { std::fclose(file); result.set_size(size); - return make_error_code(errc::value_too_large); + return make_error_code(std::errc::value_too_large); } } std::fclose(file); diff --git a/lib/Support/Unix/system_error.inc b/lib/Support/Unix/system_error.inc deleted file mode 100644 index 681e919edb..0000000000 --- a/lib/Support/Unix/system_error.inc +++ /dev/null @@ -1,34 +0,0 @@ -//===- llvm/Support/Unix/system_error.inc - Unix error_code ------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file provides the Unix specific implementation of the error_code -// and error_condition classes. -// -//===----------------------------------------------------------------------===// - -//===----------------------------------------------------------------------===// -//=== WARNING: Implementation here must contain only generic UNIX code that -//=== is guaranteed to work on *all* UNIX variants. -//===----------------------------------------------------------------------===// - -using namespace llvm; - -std::string -_system_error_category::message(int ev) const { - return _do_message::message(ev); -} - -error_condition -_system_error_category::default_error_condition(int ev) const { -#ifdef ELAST - if (ev > ELAST) - return error_condition(ev, system_category()); -#endif // ELAST - return error_condition(ev, generic_category()); -} diff --git a/lib/Support/Windows/Path.inc b/lib/Support/Windows/Path.inc index a819156871..fb484778e6 100644 --- a/lib/Support/Windows/Path.inc +++ b/lib/Support/Windows/Path.inc @@ -17,6 +17,7 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/STLExtras.h" +#include "llvm/Support/WindowsError.h" #include #include #include @@ -45,7 +46,7 @@ using llvm::sys::windows::UTF8ToUTF16; using llvm::sys::windows::UTF16ToUTF8; static error_code windows_error(DWORD E) { - return error_code(E, system_category()); + return mapWindowsError(E); } static error_code TempDir(SmallVectorImpl &Result) { @@ -193,7 +194,7 @@ error_code remove(const Twine &path, bool IgnoreNonExisting) { file_status ST; if (error_code EC = status(path, ST)) { - if (EC != errc::no_such_file_or_directory || !IgnoreNonExisting) + if (EC != std::errc::no_such_file_or_directory || !IgnoreNonExisting) return EC; return error_code(); } @@ -205,14 +206,14 @@ error_code remove(const Twine &path, bool IgnoreNonExisting) { if (ST.type() == file_type::directory_file) { if (!::RemoveDirectoryW(c_str(path_utf16))) { error_code EC = windows_error(::GetLastError()); - if (EC != errc::no_such_file_or_directory || !IgnoreNonExisting) + if (EC != std::errc::no_such_file_or_directory || !IgnoreNonExisting) return EC; } return error_code(); } if (!::DeleteFileW(c_str(path_utf16))) { error_code EC = windows_error(::GetLastError()); - if (EC != errc::no_such_file_or_directory || !IgnoreNonExisting) + if (EC != std::errc::no_such_file_or_directory || !IgnoreNonExisting) return EC; } return error_code(); @@ -516,7 +517,7 @@ error_code mapped_file_region::init(int FD, bool CloseFD, uint64_t Offset) { _close(FileDescriptor); } else ::CloseHandle(FileHandle); - return make_error_code(errc::invalid_argument); + return make_error_code(std::errc::invalid_argument); } DWORD flprotect; @@ -652,7 +653,7 @@ mapped_file_region::mapped_file_region(int fd, if (closefd) _close(FileDescriptor); FileDescriptor = 0; - ec = make_error_code(errc::bad_file_descriptor); + ec = make_error_code(std::errc::bad_file_descriptor); return; } @@ -815,7 +816,7 @@ error_code openFileForRead(const Twine &Name, int &ResultFD) { if (LastError != ERROR_ACCESS_DENIED) return EC; if (is_directory(Name)) - return make_error_code(errc::is_a_directory); + return make_error_code(std::errc::is_a_directory); return EC; } @@ -867,7 +868,7 @@ error_code openFileForWrite(const Twine &Name, int &ResultFD, if (LastError != ERROR_ACCESS_DENIED) return EC; if (is_directory(Name)) - return make_error_code(errc::is_a_directory); + return make_error_code(std::errc::is_a_directory); return EC; } diff --git a/lib/Support/Windows/Process.inc b/lib/Support/Windows/Process.inc index 9707cf103f..0be871c695 100644 --- a/lib/Support/Windows/Process.inc +++ b/lib/Support/Windows/Process.inc @@ -13,6 +13,7 @@ #include "llvm/Support/Allocator.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/WindowsError.h" #include // The Windows.h header must be after LLVM and standard headers. @@ -180,7 +181,7 @@ Optional Process::GetEnv(StringRef Name) { } static error_code windows_error(DWORD E) { - return error_code(E, system_category()); + return mapWindowsError(E); } error_code diff --git a/lib/Support/Windows/system_error.inc b/lib/Support/Windows/system_error.inc deleted file mode 100644 index 89492efad3..0000000000 --- a/lib/Support/Windows/system_error.inc +++ /dev/null @@ -1,141 +0,0 @@ -//===- llvm/Support/Win32/system_error.inc - Windows error_code --*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file provides the Windows specific implementation of the error_code -// and error_condition classes. -// -//===----------------------------------------------------------------------===// - -//===----------------------------------------------------------------------===// -//=== WARNING: Implementation here must contain only generic Windows code that -//=== is guaranteed to work on *all* Windows variants. -//===----------------------------------------------------------------------===// - -#include -#include - -using namespace llvm; - -std::string -_system_error_category::message(int ev) const { - LPVOID lpMsgBuf = 0; - DWORD retval = ::FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - ev, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPSTR) &lpMsgBuf, - 0, - NULL); - if (retval == 0) { - ::LocalFree(lpMsgBuf); - return std::string("Unknown error"); - } - - std::string str( static_cast(lpMsgBuf) ); - ::LocalFree(lpMsgBuf); - - while (str.size() - && (str[str.size()-1] == '\n' || str[str.size()-1] == '\r')) - str.erase( str.size()-1 ); - if (str.size() && str[str.size()-1] == '.') - str.erase( str.size()-1 ); - return str; -} - -// I'd rather not double the line count of the following. -#define MAP_ERR_TO_COND(x, y) case x: return make_error_condition(errc::y) - -error_condition -_system_error_category::default_error_condition(int ev) const { - switch (ev) { - // Windows system -> posix_errno decode table ---------------------------// - // see WinError.h comments for descriptions of errors - MAP_ERR_TO_COND(ERROR_ACCESS_DENIED, permission_denied); - MAP_ERR_TO_COND(ERROR_ALREADY_EXISTS, file_exists); - MAP_ERR_TO_COND(ERROR_BAD_UNIT, no_such_device); - MAP_ERR_TO_COND(ERROR_BUFFER_OVERFLOW, filename_too_long); - MAP_ERR_TO_COND(ERROR_BUSY, device_or_resource_busy); - MAP_ERR_TO_COND(ERROR_BUSY_DRIVE, device_or_resource_busy); - MAP_ERR_TO_COND(ERROR_CANNOT_MAKE, permission_denied); - MAP_ERR_TO_COND(ERROR_CANTOPEN, io_error); - MAP_ERR_TO_COND(ERROR_CANTREAD, io_error); - MAP_ERR_TO_COND(ERROR_CANTWRITE, io_error); - MAP_ERR_TO_COND(ERROR_CURRENT_DIRECTORY, permission_denied); - MAP_ERR_TO_COND(ERROR_DEV_NOT_EXIST, no_such_device); - MAP_ERR_TO_COND(ERROR_DEVICE_IN_USE, device_or_resource_busy); - MAP_ERR_TO_COND(ERROR_DIR_NOT_EMPTY, directory_not_empty); - MAP_ERR_TO_COND(ERROR_DIRECTORY, invalid_argument); - MAP_ERR_TO_COND(ERROR_DISK_FULL, no_space_on_device); - MAP_ERR_TO_COND(ERROR_FILE_EXISTS, file_exists); - MAP_ERR_TO_COND(ERROR_FILE_NOT_FOUND, no_such_file_or_directory); - MAP_ERR_TO_COND(ERROR_HANDLE_DISK_FULL, no_space_on_device); - MAP_ERR_TO_COND(ERROR_HANDLE_EOF, value_too_large); - MAP_ERR_TO_COND(ERROR_INVALID_ACCESS, permission_denied); - MAP_ERR_TO_COND(ERROR_INVALID_DRIVE, no_such_device); - MAP_ERR_TO_COND(ERROR_INVALID_FUNCTION, function_not_supported); - MAP_ERR_TO_COND(ERROR_INVALID_HANDLE, invalid_argument); - MAP_ERR_TO_COND(ERROR_INVALID_NAME, invalid_argument); - MAP_ERR_TO_COND(ERROR_LOCK_VIOLATION, no_lock_available); - MAP_ERR_TO_COND(ERROR_LOCKED, no_lock_available); - MAP_ERR_TO_COND(ERROR_NEGATIVE_SEEK, invalid_argument); - MAP_ERR_TO_COND(ERROR_NOACCESS, permission_denied); - MAP_ERR_TO_COND(ERROR_NOT_ENOUGH_MEMORY, not_enough_memory); - MAP_ERR_TO_COND(ERROR_NOT_READY, resource_unavailable_try_again); - MAP_ERR_TO_COND(ERROR_NOT_SAME_DEVICE, cross_device_link); - MAP_ERR_TO_COND(ERROR_OPEN_FAILED, io_error); - MAP_ERR_TO_COND(ERROR_OPEN_FILES, device_or_resource_busy); - MAP_ERR_TO_COND(ERROR_OPERATION_ABORTED, operation_canceled); - MAP_ERR_TO_COND(ERROR_OUTOFMEMORY, not_enough_memory); - MAP_ERR_TO_COND(ERROR_PATH_NOT_FOUND, no_such_file_or_directory); - MAP_ERR_TO_COND(ERROR_BAD_NETPATH, no_such_file_or_directory); - MAP_ERR_TO_COND(ERROR_READ_FAULT, io_error); - MAP_ERR_TO_COND(ERROR_RETRY, resource_unavailable_try_again); - MAP_ERR_TO_COND(ERROR_SEEK, io_error); - MAP_ERR_TO_COND(ERROR_SHARING_VIOLATION, permission_denied); - MAP_ERR_TO_COND(ERROR_TOO_MANY_OPEN_FILES, too_many_files_open); - MAP_ERR_TO_COND(ERROR_WRITE_FAULT, io_error); - MAP_ERR_TO_COND(ERROR_WRITE_PROTECT, permission_denied); - MAP_ERR_TO_COND(ERROR_SEM_TIMEOUT, timed_out); - MAP_ERR_TO_COND(WSAEACCES, permission_denied); - MAP_ERR_TO_COND(WSAEADDRINUSE, address_in_use); - MAP_ERR_TO_COND(WSAEADDRNOTAVAIL, address_not_available); - MAP_ERR_TO_COND(WSAEAFNOSUPPORT, address_family_not_supported); - MAP_ERR_TO_COND(WSAEALREADY, connection_already_in_progress); - MAP_ERR_TO_COND(WSAEBADF, bad_file_descriptor); - MAP_ERR_TO_COND(WSAECONNABORTED, connection_aborted); - MAP_ERR_TO_COND(WSAECONNREFUSED, connection_refused); - MAP_ERR_TO_COND(WSAECONNRESET, connection_reset); - MAP_ERR_TO_COND(WSAEDESTADDRREQ, destination_address_required); - MAP_ERR_TO_COND(WSAEFAULT, bad_address); - MAP_ERR_TO_COND(WSAEHOSTUNREACH, host_unreachable); - MAP_ERR_TO_COND(WSAEINPROGRESS, operation_in_progress); - MAP_ERR_TO_COND(WSAEINTR, interrupted); - MAP_ERR_TO_COND(WSAEINVAL, invalid_argument); - MAP_ERR_TO_COND(WSAEISCONN, already_connected); - MAP_ERR_TO_COND(WSAEMFILE, too_many_files_open); - MAP_ERR_TO_COND(WSAEMSGSIZE, message_size); - MAP_ERR_TO_COND(WSAENAMETOOLONG, filename_too_long); - MAP_ERR_TO_COND(WSAENETDOWN, network_down); - MAP_ERR_TO_COND(WSAENETRESET, network_reset); - MAP_ERR_TO_COND(WSAENETUNREACH, network_unreachable); - MAP_ERR_TO_COND(WSAENOBUFS, no_buffer_space); - MAP_ERR_TO_COND(WSAENOPROTOOPT, no_protocol_option); - MAP_ERR_TO_COND(WSAENOTCONN, not_connected); - MAP_ERR_TO_COND(WSAENOTSOCK, not_a_socket); - MAP_ERR_TO_COND(WSAEOPNOTSUPP, operation_not_supported); - MAP_ERR_TO_COND(WSAEPROTONOSUPPORT, protocol_not_supported); - MAP_ERR_TO_COND(WSAEPROTOTYPE, wrong_protocol_type); - MAP_ERR_TO_COND(WSAETIMEDOUT, timed_out); - MAP_ERR_TO_COND(WSAEWOULDBLOCK, operation_would_block); - default: return error_condition(ev, system_category()); - } -} diff --git a/lib/Support/WindowsError.cpp b/lib/Support/WindowsError.cpp new file mode 100644 index 0000000000..59c575ff9e --- /dev/null +++ b/lib/Support/WindowsError.cpp @@ -0,0 +1,115 @@ +//===-- WindowsError.cpp - Support for mapping windows errors to posix-----===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements a mapping from windows errors to posix ones. +// The standard doesn't define what the equivalence is from system +// errors to generic ones. The one implemented in msvc is too conservative +// for llvm, so we do an extra mapping when constructing an error_code +// from an windows error. This allows the rest of llvm to simple checks +// like "EC == std::errc::file_exists" and have it work on both posix and +// windows. +// +//===----------------------------------------------------------------------===// + +#ifdef _MSC_VER + +#include + +#include "llvm/Support/WindowsError.h" + +// I'd rather not double the line count of the following. +#define MAP_ERR_TO_COND(x, y) \ + case x: \ + return std::make_error_code(std::errc::y) + +std::error_code llvm::mapWindowsError(unsigned EV) { + switch (EV) { + MAP_ERR_TO_COND(ERROR_ACCESS_DENIED, permission_denied); + MAP_ERR_TO_COND(ERROR_ALREADY_EXISTS, file_exists); + MAP_ERR_TO_COND(ERROR_BAD_UNIT, no_such_device); + MAP_ERR_TO_COND(ERROR_BUFFER_OVERFLOW, filename_too_long); + MAP_ERR_TO_COND(ERROR_BUSY, device_or_resource_busy); + MAP_ERR_TO_COND(ERROR_BUSY_DRIVE, device_or_resource_busy); + MAP_ERR_TO_COND(ERROR_CANNOT_MAKE, permission_denied); + MAP_ERR_TO_COND(ERROR_CANTOPEN, io_error); + MAP_ERR_TO_COND(ERROR_CANTREAD, io_error); + MAP_ERR_TO_COND(ERROR_CANTWRITE, io_error); + MAP_ERR_TO_COND(ERROR_CURRENT_DIRECTORY, permission_denied); + MAP_ERR_TO_COND(ERROR_DEV_NOT_EXIST, no_such_device); + MAP_ERR_TO_COND(ERROR_DEVICE_IN_USE, device_or_resource_busy); + MAP_ERR_TO_COND(ERROR_DIR_NOT_EMPTY, directory_not_empty); + MAP_ERR_TO_COND(ERROR_DIRECTORY, invalid_argument); + MAP_ERR_TO_COND(ERROR_DISK_FULL, no_space_on_device); + MAP_ERR_TO_COND(ERROR_FILE_EXISTS, file_exists); + MAP_ERR_TO_COND(ERROR_FILE_NOT_FOUND, no_such_file_or_directory); + MAP_ERR_TO_COND(ERROR_HANDLE_DISK_FULL, no_space_on_device); + MAP_ERR_TO_COND(ERROR_HANDLE_EOF, value_too_large); + MAP_ERR_TO_COND(ERROR_INVALID_ACCESS, permission_denied); + MAP_ERR_TO_COND(ERROR_INVALID_DRIVE, no_such_device); + MAP_ERR_TO_COND(ERROR_INVALID_FUNCTION, function_not_supported); + MAP_ERR_TO_COND(ERROR_INVALID_HANDLE, invalid_argument); + MAP_ERR_TO_COND(ERROR_INVALID_NAME, invalid_argument); + MAP_ERR_TO_COND(ERROR_LOCK_VIOLATION, no_lock_available); + MAP_ERR_TO_COND(ERROR_LOCKED, no_lock_available); + MAP_ERR_TO_COND(ERROR_NEGATIVE_SEEK, invalid_argument); + MAP_ERR_TO_COND(ERROR_NOACCESS, permission_denied); + MAP_ERR_TO_COND(ERROR_NOT_ENOUGH_MEMORY, not_enough_memory); + MAP_ERR_TO_COND(ERROR_NOT_READY, resource_unavailable_try_again); + MAP_ERR_TO_COND(ERROR_NOT_SAME_DEVICE, cross_device_link); + MAP_ERR_TO_COND(ERROR_OPEN_FAILED, io_error); + MAP_ERR_TO_COND(ERROR_OPEN_FILES, device_or_resource_busy); + MAP_ERR_TO_COND(ERROR_OPERATION_ABORTED, operation_canceled); + MAP_ERR_TO_COND(ERROR_OUTOFMEMORY, not_enough_memory); + MAP_ERR_TO_COND(ERROR_PATH_NOT_FOUND, no_such_file_or_directory); + MAP_ERR_TO_COND(ERROR_BAD_NETPATH, no_such_file_or_directory); + MAP_ERR_TO_COND(ERROR_READ_FAULT, io_error); + MAP_ERR_TO_COND(ERROR_RETRY, resource_unavailable_try_again); + MAP_ERR_TO_COND(ERROR_SEEK, io_error); + MAP_ERR_TO_COND(ERROR_SHARING_VIOLATION, permission_denied); + MAP_ERR_TO_COND(ERROR_TOO_MANY_OPEN_FILES, too_many_files_open); + MAP_ERR_TO_COND(ERROR_WRITE_FAULT, io_error); + MAP_ERR_TO_COND(ERROR_WRITE_PROTECT, permission_denied); + MAP_ERR_TO_COND(ERROR_SEM_TIMEOUT, timed_out); + MAP_ERR_TO_COND(WSAEACCES, permission_denied); + MAP_ERR_TO_COND(WSAEADDRINUSE, address_in_use); + MAP_ERR_TO_COND(WSAEADDRNOTAVAIL, address_not_available); + MAP_ERR_TO_COND(WSAEAFNOSUPPORT, address_family_not_supported); + MAP_ERR_TO_COND(WSAEALREADY, connection_already_in_progress); + MAP_ERR_TO_COND(WSAEBADF, bad_file_descriptor); + MAP_ERR_TO_COND(WSAECONNABORTED, connection_aborted); + MAP_ERR_TO_COND(WSAECONNREFUSED, connection_refused); + MAP_ERR_TO_COND(WSAECONNRESET, connection_reset); + MAP_ERR_TO_COND(WSAEDESTADDRREQ, destination_address_required); + MAP_ERR_TO_COND(WSAEFAULT, bad_address); + MAP_ERR_TO_COND(WSAEHOSTUNREACH, host_unreachable); + MAP_ERR_TO_COND(WSAEINPROGRESS, operation_in_progress); + MAP_ERR_TO_COND(WSAEINTR, interrupted); + MAP_ERR_TO_COND(WSAEINVAL, invalid_argument); + MAP_ERR_TO_COND(WSAEISCONN, already_connected); + MAP_ERR_TO_COND(WSAEMFILE, too_many_files_open); + MAP_ERR_TO_COND(WSAEMSGSIZE, message_size); + MAP_ERR_TO_COND(WSAENAMETOOLONG, filename_too_long); + MAP_ERR_TO_COND(WSAENETDOWN, network_down); + MAP_ERR_TO_COND(WSAENETRESET, network_reset); + MAP_ERR_TO_COND(WSAENETUNREACH, network_unreachable); + MAP_ERR_TO_COND(WSAENOBUFS, no_buffer_space); + MAP_ERR_TO_COND(WSAENOPROTOOPT, no_protocol_option); + MAP_ERR_TO_COND(WSAENOTCONN, not_connected); + MAP_ERR_TO_COND(WSAENOTSOCK, not_a_socket); + MAP_ERR_TO_COND(WSAEOPNOTSUPP, operation_not_supported); + MAP_ERR_TO_COND(WSAEPROTONOSUPPORT, protocol_not_supported); + MAP_ERR_TO_COND(WSAEPROTOTYPE, wrong_protocol_type); + MAP_ERR_TO_COND(WSAETIMEDOUT, timed_out); + MAP_ERR_TO_COND(WSAEWOULDBLOCK, operation_would_block); + default: + return std::error_code(EV, std::system_category()); + } +} + +#endif diff --git a/lib/Support/YAMLTraits.cpp b/lib/Support/YAMLTraits.cpp index 20f8b245c9..ed80eac76a 100644 --- a/lib/Support/YAMLTraits.cpp +++ b/lib/Support/YAMLTraits.cpp @@ -74,7 +74,7 @@ bool Input::setCurrentDocument() { Node *N = DocIterator->getRoot(); if (!N) { assert(Strm->failed() && "Root is NULL iff parsing failed"); - EC = make_error_code(errc::invalid_argument); + EC = make_error_code(std::errc::invalid_argument); return false; } @@ -124,7 +124,7 @@ bool Input::preflightKey(const char *Key, bool Required, bool, bool &UseDefault, // nodes are present. if (!CurrentNode) { if (Required) - EC = make_error_code(errc::invalid_argument); + EC = make_error_code(std::errc::invalid_argument); return false; } @@ -300,7 +300,7 @@ void Input::setError(HNode *hnode, const Twine &message) { void Input::setError(Node *node, const Twine &message) { Strm->printError(node, message); - EC = make_error_code(errc::invalid_argument); + EC = make_error_code(std::errc::invalid_argument); } Input::HNode *Input::createHNodes(Node *N) { diff --git a/lib/Support/system_error.cpp b/lib/Support/system_error.cpp deleted file mode 100644 index 46b501eea0..0000000000 --- a/lib/Support/system_error.cpp +++ /dev/null @@ -1,121 +0,0 @@ -//===---------------------- system_error.cpp ------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This was lifted from libc++ and modified for C++03. -// -//===----------------------------------------------------------------------===// - -#include "llvm/Support/system_error.h" -#include "llvm/Support/Errno.h" -#include -#include - -namespace llvm { - -// class error_category - -error_category::error_category() { -} - -error_category::~error_category() { -} - -error_condition -error_category::default_error_condition(int ev) const { - return error_condition(ev, *this); -} - -bool -error_category::equivalent(int code, const error_condition& condition) const { - return default_error_condition(code) == condition; -} - -bool -error_category::equivalent(const error_code& code, int condition) const { - return *this == code.category() && code.value() == condition; -} - -std::string -_do_message::message(int ev) const { - return std::string(sys::StrError(ev)); -} - -class _generic_error_category : public _do_message { -public: - const char* name() const LLVM_NOEXCEPT override; - std::string message(int ev) const override; -}; - -const char* -_generic_error_category::name() const { - return "generic"; -} - -std::string -_generic_error_category::message(int ev) const { -#ifdef ELAST - if (ev > ELAST) - return std::string("unspecified generic_category error"); -#endif // ELAST - return _do_message::message(ev); -} - -const error_category& -generic_category() { - static _generic_error_category s; - return s; -} - -class _system_error_category : public _do_message { -public: - const char* name() const LLVM_NOEXCEPT override; - std::string message(int ev) const override; - error_condition default_error_condition(int ev) const override; -}; - -const char* -_system_error_category::name() const { - return "system"; -} - -// std::string _system_error_category::message(int ev) const { -// Is in Platform/system_error.inc - -// error_condition _system_error_category::default_error_condition(int ev) const -// Is in Platform/system_error.inc - -const error_category& -system_category() { - static _system_error_category s; - return s; -} - -// error_condition - -std::string -error_condition::message() const { - return _cat_->message(_val_); -} - -// error_code - -std::string -error_code::message() const { - return _cat_->message(_val_); -} - -} // end namespace llvm - -// Include the truly platform-specific parts of this class. -#if defined(LLVM_ON_UNIX) -#include "Unix/system_error.inc" -#endif -#if defined(LLVM_ON_WIN32) -#include "Windows/system_error.inc" -#endif -- cgit v1.2.3