diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-09-13 11:24:46 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-09-13 11:25:39 +0900 |
commit | 4fadd968fa12130524c8380f33fcfe25d4de79e5 (patch) | |
tree | fd26a490cd15388d42fc6652b3c5c13012e7f93e /boost/system | |
parent | b5c87084afaef42b2d058f68091be31988a6a874 (diff) | |
download | boost-upstream/1.65.0.tar.gz boost-upstream/1.65.0.tar.bz2 boost-upstream/1.65.0.zip |
Imported Upstream version 1.65.0upstream/1.65.0
Change-Id: Icf8400b375482cb11bcf77440a6934ba360d6ba4
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'boost/system')
-rw-r--r-- | boost/system/detail/error_code.ipp | 212 | ||||
-rw-r--r-- | boost/system/detail/local_free_on_destruction.hpp | 4 | ||||
-rw-r--r-- | boost/system/error_code.hpp | 293 | ||||
-rw-r--r-- | boost/system/system_error.hpp | 8 | ||||
-rw-r--r-- | boost/system/windows_error.hpp | 116 |
5 files changed, 427 insertions, 206 deletions
diff --git a/boost/system/detail/error_code.ipp b/boost/system/detail/error_code.ipp index 71c60f61da..51ba3f4747 100644 --- a/boost/system/detail/error_code.ipp +++ b/boost/system/detail/error_code.ipp @@ -1,4 +1,4 @@ -// error_code support implementation file ----------------------------------// +// error_code support implementation file --------------------------------------------// // Copyright Beman Dawes 2002, 2006 // Copyright (c) Microsoft Corporation 2014 @@ -7,7 +7,7 @@ // See library home page at http://www.boost.org/libs/system -//----------------------------------------------------------------------------// +//--------------------------------------------------------------------------------------// #include <boost/config/warning_disable.hpp> @@ -21,7 +21,9 @@ #include <cstring> // for strerror/strerror_r # if defined( BOOST_WINDOWS_API ) -# include <windows.h> +# include <boost/detail/winapi/error_codes.hpp> +# include <boost/detail/winapi/error_handling.hpp> +# include <boost/detail/winapi/character_code_conversion.hpp> # if !BOOST_PLAT_WINDOWS_RUNTIME # include <boost/system/detail/local_free_on_destruction.hpp> # endif @@ -30,7 +32,7 @@ # endif # endif -//----------------------------------------------------------------------------// +//--------------------------------------------------------------------------------------// namespace boost { namespace system @@ -39,7 +41,7 @@ namespace boost namespace { - // standard error categories ---------------------------------------------// + // standard error categories -------------------------------------------------------// class generic_error_category : public error_category { @@ -84,7 +86,8 @@ namespace // -- VMS doesn't provide strerror_r, but on this platform, strerror is // thread safe. # if defined(BOOST_WINDOWS_API) || defined(__hpux) || defined(__sun)\ - || (defined(__linux) && (!defined(__USE_XOPEN2K) || defined(BOOST_SYSTEM_USE_STRERROR)))\ + || (defined(__linux) && (!defined(__USE_XOPEN2K)\ + || defined(BOOST_SYSTEM_USE_STRERROR)))\ || (defined(__osf__) && !defined(_REENTRANT))\ || (defined(__INTEGRITY))\ || (defined(__vms))\ @@ -156,14 +159,15 @@ namespace # endif // else POSIX version of strerror_r # endif // else use strerror_r } - // system_error_category implementation --------------------------------// + // system_error_category implementation --------------------------------------------// const char * system_error_category::name() const BOOST_SYSTEM_NOEXCEPT { return "system"; } - error_condition system_error_category::default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT + error_condition system_error_category::default_error_condition( int ev ) const + BOOST_SYSTEM_NOEXCEPT { using namespace boost::system::errc; #if defined(__PGI) @@ -181,11 +185,17 @@ namespace # endif # endif +# if defined(BOOST_WINDOWS_API) + + using namespace boost::detail::winapi; // for error codes + +# endif + switch ( ev ) { case 0: return make_error_condition( success ); # if defined(BOOST_POSIX_API) - // POSIX-like O/S -> posix_errno decode table ---------------------------// + // POSIX-like O/S -> posix_errno decode table -------------------------------------// case E2BIG: return make_error_condition( argument_list_too_long ); case EACCES: return make_error_condition( permission_denied ); case EADDRINUSE: return make_error_condition( address_in_use ); @@ -279,80 +289,81 @@ namespace #else // Windows system -> posix_errno decode table ---------------------------// // see WinError.h comments for descriptions of errors - case ERROR_ACCESS_DENIED: return make_error_condition( permission_denied ); - case ERROR_ALREADY_EXISTS: return make_error_condition( file_exists ); - case ERROR_BAD_UNIT: return make_error_condition( no_such_device ); - case ERROR_BUFFER_OVERFLOW: return make_error_condition( filename_too_long ); - case ERROR_BUSY: return make_error_condition( device_or_resource_busy ); - case ERROR_BUSY_DRIVE: return make_error_condition( device_or_resource_busy ); - case ERROR_CANNOT_MAKE: return make_error_condition( permission_denied ); - case ERROR_CANTOPEN: return make_error_condition( io_error ); - case ERROR_CANTREAD: return make_error_condition( io_error ); - case ERROR_CANTWRITE: return make_error_condition( io_error ); - case ERROR_CURRENT_DIRECTORY: return make_error_condition( permission_denied ); - case ERROR_DEV_NOT_EXIST: return make_error_condition( no_such_device ); - case ERROR_DEVICE_IN_USE: return make_error_condition( device_or_resource_busy ); - case ERROR_DIR_NOT_EMPTY: return make_error_condition( directory_not_empty ); - case ERROR_DIRECTORY: return make_error_condition( invalid_argument ); // WinError.h: "The directory name is invalid" - case ERROR_DISK_FULL: return make_error_condition( no_space_on_device ); - case ERROR_FILE_EXISTS: return make_error_condition( file_exists ); - case ERROR_FILE_NOT_FOUND: return make_error_condition( no_such_file_or_directory ); - case ERROR_HANDLE_DISK_FULL: return make_error_condition( no_space_on_device ); - case ERROR_INVALID_ACCESS: return make_error_condition( permission_denied ); - case ERROR_INVALID_DRIVE: return make_error_condition( no_such_device ); - case ERROR_INVALID_FUNCTION: return make_error_condition( function_not_supported ); - case ERROR_INVALID_HANDLE: return make_error_condition( invalid_argument ); - case ERROR_INVALID_NAME: return make_error_condition( invalid_argument ); - case ERROR_LOCK_VIOLATION: return make_error_condition( no_lock_available ); - case ERROR_LOCKED: return make_error_condition( no_lock_available ); - case ERROR_NEGATIVE_SEEK: return make_error_condition( invalid_argument ); - case ERROR_NOACCESS: return make_error_condition( permission_denied ); - case ERROR_NOT_ENOUGH_MEMORY: return make_error_condition( not_enough_memory ); - case ERROR_NOT_READY: return make_error_condition( resource_unavailable_try_again ); - case ERROR_NOT_SAME_DEVICE: return make_error_condition( cross_device_link ); - case ERROR_OPEN_FAILED: return make_error_condition( io_error ); - case ERROR_OPEN_FILES: return make_error_condition( device_or_resource_busy ); - case ERROR_OPERATION_ABORTED: return make_error_condition( operation_canceled ); - case ERROR_OUTOFMEMORY: return make_error_condition( not_enough_memory ); - case ERROR_PATH_NOT_FOUND: return make_error_condition( no_such_file_or_directory ); - case ERROR_READ_FAULT: return make_error_condition( io_error ); - case ERROR_RETRY: return make_error_condition( resource_unavailable_try_again ); - case ERROR_SEEK: return make_error_condition( io_error ); - case ERROR_SHARING_VIOLATION: return make_error_condition( permission_denied ); - case ERROR_TOO_MANY_OPEN_FILES: return make_error_condition( too_many_files_open ); - case ERROR_WRITE_FAULT: return make_error_condition( io_error ); - case ERROR_WRITE_PROTECT: return make_error_condition( permission_denied ); - case WSAEACCES: return make_error_condition( permission_denied ); - case WSAEADDRINUSE: return make_error_condition( address_in_use ); - case WSAEADDRNOTAVAIL: return make_error_condition( address_not_available ); - case WSAEAFNOSUPPORT: return make_error_condition( address_family_not_supported ); - case WSAEALREADY: return make_error_condition( connection_already_in_progress ); - case WSAEBADF: return make_error_condition( bad_file_descriptor ); - case WSAECONNABORTED: return make_error_condition( connection_aborted ); - case WSAECONNREFUSED: return make_error_condition( connection_refused ); - case WSAECONNRESET: return make_error_condition( connection_reset ); - case WSAEDESTADDRREQ: return make_error_condition( destination_address_required ); - case WSAEFAULT: return make_error_condition( bad_address ); - case WSAEHOSTUNREACH: return make_error_condition( host_unreachable ); - case WSAEINPROGRESS: return make_error_condition( operation_in_progress ); - case WSAEINTR: return make_error_condition( interrupted ); - case WSAEINVAL: return make_error_condition( invalid_argument ); - case WSAEISCONN: return make_error_condition( already_connected ); - case WSAEMFILE: return make_error_condition( too_many_files_open ); - case WSAEMSGSIZE: return make_error_condition( message_size ); - case WSAENAMETOOLONG: return make_error_condition( filename_too_long ); - case WSAENETDOWN: return make_error_condition( network_down ); - case WSAENETRESET: return make_error_condition( network_reset ); - case WSAENETUNREACH: return make_error_condition( network_unreachable ); - case WSAENOBUFS: return make_error_condition( no_buffer_space ); - case WSAENOPROTOOPT: return make_error_condition( no_protocol_option ); - case WSAENOTCONN: return make_error_condition( not_connected ); - case WSAENOTSOCK: return make_error_condition( not_a_socket ); - case WSAEOPNOTSUPP: return make_error_condition( operation_not_supported ); - case WSAEPROTONOSUPPORT: return make_error_condition( protocol_not_supported ); - case WSAEPROTOTYPE: return make_error_condition( wrong_protocol_type ); - case WSAETIMEDOUT: return make_error_condition( timed_out ); - case WSAEWOULDBLOCK: return make_error_condition( operation_would_block ); + case ERROR_ACCESS_DENIED_: return make_error_condition( permission_denied ); + case ERROR_ALREADY_EXISTS_: return make_error_condition( file_exists ); + case ERROR_BAD_UNIT_: return make_error_condition( no_such_device ); + case ERROR_BUFFER_OVERFLOW_: return make_error_condition( filename_too_long ); + case ERROR_BUSY_: return make_error_condition( device_or_resource_busy ); + case ERROR_BUSY_DRIVE_: return make_error_condition( device_or_resource_busy ); + case ERROR_CANNOT_MAKE_: return make_error_condition( permission_denied ); + case ERROR_CANTOPEN_: return make_error_condition( io_error ); + case ERROR_CANTREAD_: return make_error_condition( io_error ); + case ERROR_CANTWRITE_: return make_error_condition( io_error ); + case ERROR_CURRENT_DIRECTORY_: return make_error_condition( permission_denied ); + case ERROR_DEV_NOT_EXIST_: return make_error_condition( no_such_device ); + case ERROR_DEVICE_IN_USE_: return make_error_condition( device_or_resource_busy ); + case ERROR_DIR_NOT_EMPTY_: return make_error_condition( directory_not_empty ); + case ERROR_DIRECTORY_: return make_error_condition( invalid_argument );\ + // WinError.h: "The directory name is invalid" + case ERROR_DISK_FULL_: return make_error_condition( no_space_on_device ); + case ERROR_FILE_EXISTS_: return make_error_condition( file_exists ); + case ERROR_FILE_NOT_FOUND_: return make_error_condition( no_such_file_or_directory ); + case ERROR_HANDLE_DISK_FULL_: return make_error_condition( no_space_on_device ); + case ERROR_INVALID_ACCESS_: return make_error_condition( permission_denied ); + case ERROR_INVALID_DRIVE_: return make_error_condition( no_such_device ); + case ERROR_INVALID_FUNCTION_: return make_error_condition( function_not_supported ); + case ERROR_INVALID_HANDLE_: return make_error_condition( invalid_argument ); + case ERROR_INVALID_NAME_: return make_error_condition( invalid_argument ); + case ERROR_LOCK_VIOLATION_: return make_error_condition( no_lock_available ); + case ERROR_LOCKED_: return make_error_condition( no_lock_available ); + case ERROR_NEGATIVE_SEEK_: return make_error_condition( invalid_argument ); + case ERROR_NOACCESS_: return make_error_condition( permission_denied ); + case ERROR_NOT_ENOUGH_MEMORY_: return make_error_condition( not_enough_memory ); + case ERROR_NOT_READY_: return make_error_condition( resource_unavailable_try_again ); + case ERROR_NOT_SAME_DEVICE_: return make_error_condition( cross_device_link ); + case ERROR_OPEN_FAILED_: return make_error_condition( io_error ); + case ERROR_OPEN_FILES_: return make_error_condition( device_or_resource_busy ); + case ERROR_OPERATION_ABORTED_: return make_error_condition( operation_canceled ); + case ERROR_OUTOFMEMORY_: return make_error_condition( not_enough_memory ); + case ERROR_PATH_NOT_FOUND_: return make_error_condition( no_such_file_or_directory ); + case ERROR_READ_FAULT_: return make_error_condition( io_error ); + case ERROR_RETRY_: return make_error_condition( resource_unavailable_try_again ); + case ERROR_SEEK_: return make_error_condition( io_error ); + case ERROR_SHARING_VIOLATION_: return make_error_condition( permission_denied ); + case ERROR_TOO_MANY_OPEN_FILES_: return make_error_condition( too_many_files_open ); + case ERROR_WRITE_FAULT_: return make_error_condition( io_error ); + case ERROR_WRITE_PROTECT_: return make_error_condition( permission_denied ); + case WSAEACCES_: return make_error_condition( permission_denied ); + case WSAEADDRINUSE_: return make_error_condition( address_in_use ); + case WSAEADDRNOTAVAIL_: return make_error_condition( address_not_available ); + case WSAEAFNOSUPPORT_: return make_error_condition( address_family_not_supported ); + case WSAEALREADY_: return make_error_condition( connection_already_in_progress ); + case WSAEBADF_: return make_error_condition( bad_file_descriptor ); + case WSAECONNABORTED_: return make_error_condition( connection_aborted ); + case WSAECONNREFUSED_: return make_error_condition( connection_refused ); + case WSAECONNRESET_: return make_error_condition( connection_reset ); + case WSAEDESTADDRREQ_: return make_error_condition( destination_address_required ); + case WSAEFAULT_: return make_error_condition( bad_address ); + case WSAEHOSTUNREACH_: return make_error_condition( host_unreachable ); + case WSAEINPROGRESS_: return make_error_condition( operation_in_progress ); + case WSAEINTR_: return make_error_condition( interrupted ); + case WSAEINVAL_: return make_error_condition( invalid_argument ); + case WSAEISCONN_: return make_error_condition( already_connected ); + case WSAEMFILE_: return make_error_condition( too_many_files_open ); + case WSAEMSGSIZE_: return make_error_condition( message_size ); + case WSAENAMETOOLONG_: return make_error_condition( filename_too_long ); + case WSAENETDOWN_: return make_error_condition( network_down ); + case WSAENETRESET_: return make_error_condition( network_reset ); + case WSAENETUNREACH_: return make_error_condition( network_unreachable ); + case WSAENOBUFS_: return make_error_condition( no_buffer_space ); + case WSAENOPROTOOPT_: return make_error_condition( no_protocol_option ); + case WSAENOTCONN_: return make_error_condition( not_connected ); + case WSAENOTSOCK_: return make_error_condition( not_a_socket ); + case WSAEOPNOTSUPP_: return make_error_condition( operation_not_supported ); + case WSAEPROTONOSUPPORT_: return make_error_condition( protocol_not_supported ); + case WSAEPROTOTYPE_: return make_error_condition( wrong_protocol_type ); + case WSAETIMEDOUT_: return make_error_condition( timed_out ); + case WSAEWOULDBLOCK_: return make_error_condition( operation_would_block ); #endif default: return error_condition( ev, system_category() ); } @@ -372,12 +383,13 @@ namespace std::wstring buf(128, wchar_t()); for (;;) { - DWORD retval = ::FormatMessageW( - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, + boost::detail::winapi::DWORD_ retval = boost::detail::winapi::FormatMessageW( + boost::detail::winapi::FORMAT_MESSAGE_FROM_SYSTEM_ | + boost::detail::winapi::FORMAT_MESSAGE_IGNORE_INSERTS_, NULL, ev, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + boost::detail::winapi::MAKELANGID_(boost::detail::winapi::LANG_NEUTRAL_, + boost::detail::winapi::SUBLANG_DEFAULT_), // Default language &buf[0], buf.size(), NULL @@ -388,7 +400,8 @@ namespace buf.resize(retval); break; } - else if ( ::GetLastError() != ERROR_INSUFFICIENT_BUFFER ) + else if (boost::detail::winapi::GetLastError() != + boost::detail::winapi::ERROR_INSUFFICIENT_BUFFER_) { return std::string("Unknown error"); } @@ -399,23 +412,26 @@ namespace } int num_chars = (buf.size() + 1) * 2; - LPSTR narrow_buffer = (LPSTR)_alloca( num_chars ); - if (::WideCharToMultiByte(CP_ACP, 0, buf.c_str(), -1, narrow_buffer, num_chars, NULL, NULL) == 0) + boost::detail::winapi::LPSTR_ narrow_buffer = + (boost::detail::winapi::LPSTR_)_alloca(num_chars); + if (boost::detail::winapi::WideCharToMultiByte(boost::detail::winapi::CP_ACP_, 0, + buf.c_str(), -1, narrow_buffer, num_chars, NULL, NULL) == 0) { return std::string("Unknown error"); } std::string str( narrow_buffer ); #else - LPVOID lpMsgBuf = 0; - DWORD retval = ::FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, + boost::detail::winapi::LPVOID_ lpMsgBuf = 0; + boost::detail::winapi::DWORD_ retval = boost::detail::winapi::FormatMessageA( + boost::detail::winapi::FORMAT_MESSAGE_ALLOCATE_BUFFER_ | + boost::detail::winapi::FORMAT_MESSAGE_FROM_SYSTEM_ | + boost::detail::winapi::FORMAT_MESSAGE_IGNORE_INSERTS_, NULL, ev, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPSTR) &lpMsgBuf, + boost::detail::winapi::MAKELANGID_(boost::detail::winapi::LANG_NEUTRAL_, + boost::detail::winapi::SUBLANG_DEFAULT_), // Default language + (boost::detail::winapi::LPSTR_) &lpMsgBuf, 0, NULL ); @@ -423,7 +439,7 @@ namespace if (retval == 0) return std::string("Unknown error"); - std::string str( static_cast<LPCSTR>(lpMsgBuf) ); + std::string str(static_cast<boost::detail::winapi::LPCSTR_>(lpMsgBuf)); # endif while ( str.size() && (str[str.size()-1] == '\n' || str[str.size()-1] == '\r') ) diff --git a/boost/system/detail/local_free_on_destruction.hpp b/boost/system/detail/local_free_on_destruction.hpp index 110024f3d5..25f879b3b0 100644 --- a/boost/system/detail/local_free_on_destruction.hpp +++ b/boost/system/detail/local_free_on_destruction.hpp @@ -12,6 +12,8 @@ #ifndef BOOST_SYSTEM_LOCAL_FREE_ON_EXIT_HPP #define BOOST_SYSTEM_LOCAL_FREE_ON_EXIT_HPP +#include <boost/detail/winapi/local_memory.hpp> + namespace boost { namespace system { namespace detail { @@ -24,7 +26,7 @@ public: ~local_free_on_destruction() { - ::LocalFree(p_); + boost::detail::winapi::LocalFree(p_); } private: diff --git a/boost/system/error_code.hpp b/boost/system/error_code.hpp index b6ff6e4bad..0d64b2b72e 100644 --- a/boost/system/error_code.hpp +++ b/boost/system/error_code.hpp @@ -1,4 +1,4 @@ -// boost/system/error_code.hpp ---------------------------------------------// +// boost/system/error_code.hpp -------------------------------------------------------// // Copyright Beman Dawes 2006, 2007 // Copyright Christoper Kohlhoff 2007 @@ -28,6 +28,10 @@ # error BOOST_POSIX_API or BOOST_WINDOWS_API must be defined #endif +#ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR +#include <system_error> +#endif + #include <boost/config/abi_prefix.hpp> // must be the last #include #ifndef BOOST_SYSTEM_NOEXCEPT @@ -43,7 +47,7 @@ namespace boost class error_condition; // portable generic values defined below, but ultimately // based on the POSIX standard - // "Concept" helpers ---------------------------------------------------// + // "Concept" helpers -------------------------------------------------------------// template< class T > struct is_error_code_enum { static const bool value = false; }; @@ -51,7 +55,7 @@ namespace boost template< class T > struct is_error_condition_enum { static const bool value = false; }; - // generic error_conditions --------------------------------------------// + // generic error_conditions ------------------------------------------------------// namespace errc { @@ -149,9 +153,9 @@ namespace boost { static const bool value = true; }; - // ----------------------------------------------------------------------// + // --------------------------------------------------------------------------------// - // Operating system specific interfaces --------------------------------// + // Operating system specific interfaces ------------------------------------------// // The interface is divided into general and system-specific portions to @@ -179,52 +183,152 @@ namespace boost // These headers are effectively empty for compiles on operating systems // where they are not applicable. - // ----------------------------------------------------------------------// + // --------------------------------------------------------------------------------// + + class error_category; + + // predefined error categories ---------------------------------------------------// + +#ifdef BOOST_ERROR_CODE_HEADER_ONLY + inline const error_category & system_category() BOOST_SYSTEM_NOEXCEPT; + inline const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT; +#else + BOOST_SYSTEM_DECL const error_category & system_category() BOOST_SYSTEM_NOEXCEPT; + BOOST_SYSTEM_DECL const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT; +#endif + // deprecated synonyms ------------------------------------------------------------// + +#ifndef BOOST_SYSTEM_NO_DEPRECATED + inline const error_category & get_system_category() { return system_category(); } + inline const error_category & get_generic_category() { return generic_category(); } + inline const error_category & get_posix_category() { return generic_category(); } + static const error_category & posix_category BOOST_ATTRIBUTE_UNUSED + = generic_category(); + static const error_category & errno_ecat BOOST_ATTRIBUTE_UNUSED + = generic_category(); + static const error_category & native_ecat BOOST_ATTRIBUTE_UNUSED + = system_category(); +#endif // class error_category ------------------------------------------------// class error_category : public noncopyable { +#ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR + + private: + + class std_category: public std::error_category + { + private: + + boost::system::error_category const * pc_; + + public: + + explicit std_category( boost::system::error_category const * pc ): pc_( pc ) + { + } + + virtual const char * name() const BOOST_NOEXCEPT + { + return pc_->name(); + } + + virtual std::string message( int ev ) const + { + return pc_->message( ev ); + } + + virtual std::error_condition default_error_condition( int ev ) const + BOOST_NOEXCEPT; + virtual bool equivalent( int code, const std::error_condition & condition ) const + BOOST_NOEXCEPT; + virtual bool equivalent( const std::error_code & code, int condition ) const + BOOST_NOEXCEPT; + }; + + std_category std_cat_; + + public: + + error_category() BOOST_SYSTEM_NOEXCEPT: std_cat_( this ) {} + + operator std::error_category const & () const BOOST_SYSTEM_NOEXCEPT + { + // do not map generic to std::generic on purpose; occasionally, + // there are two std::generic categories in a program, which leads + // to error codes/conditions mysteriously not being equal to themselves + return std_cat_; + } + +#else + + // to maintain ABI compatibility between 03 and 11, + // define a class with the same layout + + private: + + class std_category + { + private: + + boost::system::error_category const * pc_; + + public: + + explicit std_category( boost::system::error_category const * pc ): pc_( pc ) + { + } + + virtual ~std_category() {} + + virtual const char * name() const BOOST_NOEXCEPT + { + return pc_->name(); + } + + // we can't define message, because (1) it returns an std::string, + // which can be different between 03 and 11, and (2) on mingw, there + // are actually two `message` functions, not one, so it doesn't work + // even if we do + + // neither can we define default_error_condition or equivalent + + // if these functions are called, it will crash, but that's still + // better than the alternative of having the class layout change + }; + + std_category std_cat_; + + public: + + error_category() BOOST_SYSTEM_NOEXCEPT: std_cat_( this ) {} + +#endif + public: virtual ~error_category(){} virtual const char * name() const BOOST_SYSTEM_NOEXCEPT = 0; virtual std::string message( int ev ) const = 0; - inline virtual error_condition default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT; + inline virtual error_condition default_error_condition( int ev ) const + BOOST_SYSTEM_NOEXCEPT; inline virtual bool equivalent( int code, - const error_condition & condition ) const BOOST_SYSTEM_NOEXCEPT; + const error_condition & condition ) const + BOOST_SYSTEM_NOEXCEPT; inline virtual bool equivalent( const error_code & code, int condition ) const BOOST_SYSTEM_NOEXCEPT; - bool operator==(const error_category & rhs) const BOOST_SYSTEM_NOEXCEPT { return this == &rhs; } - bool operator!=(const error_category & rhs) const BOOST_SYSTEM_NOEXCEPT { return this != &rhs; } + bool operator==(const error_category & rhs) const BOOST_SYSTEM_NOEXCEPT + { return this == &rhs; } + bool operator!=(const error_category & rhs) const BOOST_SYSTEM_NOEXCEPT + { return this != &rhs; } bool operator<( const error_category & rhs ) const BOOST_SYSTEM_NOEXCEPT - { - return std::less<const error_category*>()( this, &rhs ); - } + { return std::less<const error_category*>()( this, &rhs ); } }; - // predefined error categories -----------------------------------------// - -# ifdef BOOST_ERROR_CODE_HEADER_ONLY - inline const error_category & system_category() BOOST_SYSTEM_NOEXCEPT; - inline const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT; -#else - BOOST_SYSTEM_DECL const error_category & system_category() BOOST_SYSTEM_NOEXCEPT; - BOOST_SYSTEM_DECL const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT; -#endif - // deprecated synonyms --------------------------------------------------// - -# ifndef BOOST_SYSTEM_NO_DEPRECATED - inline const error_category & get_system_category() { return system_category(); } - inline const error_category & get_generic_category() { return generic_category(); } - inline const error_category & get_posix_category() { return generic_category(); } - static const error_category & posix_category BOOST_ATTRIBUTE_UNUSED = generic_category(); - static const error_category & errno_ecat BOOST_ATTRIBUTE_UNUSED = generic_category(); - static const error_category & native_ecat BOOST_ATTRIBUTE_UNUSED = system_category(); -# endif - - // class error_condition -----------------------------------------------// + // class error_condition ---------------------------------------------------------// // error_conditions are portable, error_codes are system or library specific @@ -234,11 +338,13 @@ namespace boost // constructors: error_condition() BOOST_SYSTEM_NOEXCEPT : m_val(0), m_cat(&generic_category()) {} - error_condition( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT : m_val(val), m_cat(&cat) {} + error_condition( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT + : m_val(val), m_cat(&cat) {} template <class ErrorConditionEnum> error_condition(ErrorConditionEnum e, - typename boost::enable_if<is_error_condition_enum<ErrorConditionEnum> >::type* = 0) BOOST_SYSTEM_NOEXCEPT + typename boost::enable_if<is_error_condition_enum<ErrorConditionEnum> >::type* + = 0) BOOST_SYSTEM_NOEXCEPT { *this = make_error_condition(e); } @@ -252,7 +358,8 @@ namespace boost } template<typename ErrorConditionEnum> - typename boost::enable_if<is_error_condition_enum<ErrorConditionEnum>, error_condition>::type & + typename boost::enable_if<is_error_condition_enum<ErrorConditionEnum>, + error_condition>::type & operator=( ErrorConditionEnum val ) BOOST_SYSTEM_NOEXCEPT { *this = make_error_condition(val); @@ -301,13 +408,22 @@ namespace boost || (lhs.m_cat == rhs.m_cat && lhs.m_val < rhs.m_val); } +#ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR + + operator std::error_condition () const BOOST_SYSTEM_NOEXCEPT + { + return std::error_condition( value(), category() ); + } + +#endif + private: int m_val; const error_category * m_cat; }; - // class error_code ----------------------------------------------------// + // class error_code --------------------------------------------------------------// // We want error_code to be a value type that can be copied without slicing // and without requiring heap allocation, but we also want it to have @@ -321,11 +437,13 @@ namespace boost // constructors: error_code() BOOST_SYSTEM_NOEXCEPT : m_val(0), m_cat(&system_category()) {} - error_code( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT : m_val(val), m_cat(&cat) {} + error_code( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT + : m_val(val), m_cat(&cat) {} template <class ErrorCodeEnum> error_code(ErrorCodeEnum e, - typename boost::enable_if<is_error_code_enum<ErrorCodeEnum> >::type* = 0) BOOST_SYSTEM_NOEXCEPT + typename boost::enable_if<is_error_code_enum<ErrorCodeEnum> >::type* = 0) + BOOST_SYSTEM_NOEXCEPT { *this = make_error_code(e); } @@ -354,7 +472,8 @@ namespace boost // observers: int value() const BOOST_SYSTEM_NOEXCEPT { return m_val; } const error_category & category() const BOOST_SYSTEM_NOEXCEPT { return *m_cat; } - error_condition default_error_condition() const BOOST_SYSTEM_NOEXCEPT { return m_cat->default_error_condition(value()); } + error_condition default_error_condition() const BOOST_SYSTEM_NOEXCEPT + { return m_cat->default_error_condition(value()); } std::string message() const { return m_cat->message(value()); } typedef void (*unspecified_bool_type)(); @@ -388,6 +507,15 @@ namespace boost || (lhs.m_cat == rhs.m_cat && lhs.m_val < rhs.m_val); } +#ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR + + operator std::error_code () const BOOST_SYSTEM_NOEXCEPT + { + return std::error_code( value(), category() ); + } + +#endif + private: int m_val; const error_category * m_cat; @@ -475,7 +603,7 @@ namespace boost + reinterpret_cast<std::size_t>(&ec.category()); } - // make_* functions for errc::errc_t -----------------------------// + // make_* functions for errc::errc_t ---------------------------------------------// namespace errc { @@ -488,9 +616,10 @@ namespace boost { return error_condition( e, generic_category() ); } } - // error_category default implementation -------------------------------// + // error_category default implementation -----------------------------------------// - error_condition error_category::default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT + error_condition error_category::default_error_condition( int ev ) const + BOOST_SYSTEM_NOEXCEPT { return error_condition( ev, *this ); } @@ -507,6 +636,80 @@ namespace boost return *this == code.category() && code.value() == condition; } +#ifndef BOOST_NO_CXX11_HDR_SYSTEM_ERROR + + inline std::error_condition error_category::std_category::default_error_condition( + int ev ) const BOOST_NOEXCEPT + { + return pc_->default_error_condition( ev ); + } + + inline bool error_category::std_category::equivalent( int code, + const std::error_condition & condition ) const BOOST_NOEXCEPT + { + if( condition.category() == *this ) + { + boost::system::error_condition bn( condition.value(), *pc_ ); + return pc_->equivalent( code, bn ); + } + else if( condition.category() == std::generic_category() + || condition.category() == boost::system::generic_category() ) + { + boost::system::error_condition bn( condition.value(), + boost::system::generic_category() ); + + return pc_->equivalent( code, bn ); + } +#ifndef BOOST_NO_RTTI + else if( std_category const* pc2 = dynamic_cast< std_category const* >( + &condition.category() ) ) + { + boost::system::error_condition bn( condition.value(), *pc2->pc_ ); + return pc_->equivalent( code, bn ); + } +#endif + else + { + return default_error_condition( code ) == condition; + } + } + + inline bool error_category::std_category::equivalent( const std::error_code & code, + int condition ) const BOOST_NOEXCEPT + { + if( code.category() == *this ) + { + boost::system::error_code bc( code.value(), *pc_ ); + return pc_->equivalent( bc, condition ); + } + else if( code.category() == std::generic_category() + || code.category() == boost::system::generic_category() ) + { + boost::system::error_code bc( code.value(), + boost::system::generic_category() ); + + return pc_->equivalent( bc, condition ); + } +#ifndef BOOST_NO_RTTI + else if( std_category const* pc2 = dynamic_cast< std_category const* >( + &code.category() ) ) + { + boost::system::error_code bc( code.value(), *pc2->pc_ ); + return pc_->equivalent( bc, condition ); + } +#endif + else if( *pc_ == boost::system::generic_category() ) + { + return std::generic_category().equivalent( code, condition ); + } + else + { + return false; + } + } + +#endif + } // namespace system } // namespace boost @@ -517,5 +720,3 @@ namespace boost # endif #endif // BOOST_SYSTEM_ERROR_CODE_HPP - - diff --git a/boost/system/system_error.hpp b/boost/system/system_error.hpp index d98b4bcf84..c5e7e402ba 100644 --- a/boost/system/system_error.hpp +++ b/boost/system/system_error.hpp @@ -44,10 +44,10 @@ namespace boost const char * what_arg ) : std::runtime_error(what_arg), m_error_code(ev,ecat) {} - virtual ~system_error() throw() {} + virtual ~system_error() BOOST_NOEXCEPT_OR_NOTHROW {} - const error_code & code() const throw() { return m_error_code; } - const char * what() const throw(); + const error_code & code() const BOOST_NOEXCEPT_OR_NOTHROW { return m_error_code; } + const char * what() const BOOST_NOEXCEPT_OR_NOTHROW; private: error_code m_error_code; @@ -56,7 +56,7 @@ namespace boost // implementation ------------------------------------------------------// - inline const char * system_error::what() const throw() + inline const char * system_error::what() const BOOST_NOEXCEPT_OR_NOTHROW // see http://www.boost.org/more/error_handling.html for lazy build rationale { if ( m_what.empty() ) diff --git a/boost/system/windows_error.hpp b/boost/system/windows_error.hpp index 38d628404c..0fb7ea6352 100644 --- a/boost/system/windows_error.hpp +++ b/boost/system/windows_error.hpp @@ -19,14 +19,16 @@ #include <boost/system/error_code.hpp> -// Neither MinGW or Cygwin versions of winerror.h work if used alone, so on -// either of those platforms include the full windows.h +//// Neither MinGW or Cygwin versions of winerror.h work if used alone, so on +//// either of those platforms include the full windows.h +// +//#if defined(__MINGW32__) || defined(__CYGWIN__) +//#include <windows.h> +//#else +//#include <winerror.h> +//#endif -#if defined(__MINGW32__) || defined(__CYGWIN__) -#include <windows.h> -#else -#include <winerror.h> -#endif +#include <boost/detail/winapi/error_codes.hpp> namespace boost { @@ -45,59 +47,59 @@ namespace boost { success = 0, // These names and values are based on Windows winerror.h - invalid_function = ERROR_INVALID_FUNCTION, - file_not_found = ERROR_FILE_NOT_FOUND, - path_not_found = ERROR_PATH_NOT_FOUND, - too_many_open_files = ERROR_TOO_MANY_OPEN_FILES, - access_denied = ERROR_ACCESS_DENIED, - invalid_handle = ERROR_INVALID_HANDLE, - arena_trashed = ERROR_ARENA_TRASHED, - not_enough_memory = ERROR_NOT_ENOUGH_MEMORY, - invalid_block = ERROR_INVALID_BLOCK, - bad_environment = ERROR_BAD_ENVIRONMENT, - bad_format = ERROR_BAD_FORMAT, - invalid_access = ERROR_INVALID_ACCESS, - outofmemory = ERROR_OUTOFMEMORY, - invalid_drive = ERROR_INVALID_DRIVE, - current_directory = ERROR_CURRENT_DIRECTORY, - not_same_device = ERROR_NOT_SAME_DEVICE, - no_more_files = ERROR_NO_MORE_FILES, - write_protect = ERROR_WRITE_PROTECT, - bad_unit = ERROR_BAD_UNIT, - not_ready = ERROR_NOT_READY, - bad_command = ERROR_BAD_COMMAND, - crc = ERROR_CRC, - bad_length = ERROR_BAD_LENGTH, - seek = ERROR_SEEK, - not_dos_disk = ERROR_NOT_DOS_DISK, - sector_not_found = ERROR_SECTOR_NOT_FOUND, - out_of_paper = ERROR_OUT_OF_PAPER, - write_fault = ERROR_WRITE_FAULT, - read_fault = ERROR_READ_FAULT, - gen_failure = ERROR_GEN_FAILURE, - sharing_violation = ERROR_SHARING_VIOLATION, - lock_violation = ERROR_LOCK_VIOLATION, - wrong_disk = ERROR_WRONG_DISK, - sharing_buffer_exceeded = ERROR_SHARING_BUFFER_EXCEEDED, - handle_eof = ERROR_HANDLE_EOF, - handle_disk_full= ERROR_HANDLE_DISK_FULL, - rem_not_list = ERROR_REM_NOT_LIST, - dup_name = ERROR_DUP_NAME, - bad_net_path = ERROR_BAD_NETPATH, - network_busy = ERROR_NETWORK_BUSY, + invalid_function = boost::detail::winapi::ERROR_INVALID_FUNCTION_, + file_not_found = boost::detail::winapi::ERROR_FILE_NOT_FOUND_, + path_not_found = boost::detail::winapi::ERROR_PATH_NOT_FOUND_, + too_many_open_files = boost::detail::winapi::ERROR_TOO_MANY_OPEN_FILES_, + access_denied = boost::detail::winapi::ERROR_ACCESS_DENIED_, + invalid_handle = boost::detail::winapi::ERROR_INVALID_HANDLE_, + arena_trashed = boost::detail::winapi::ERROR_ARENA_TRASHED_, + not_enough_memory = boost::detail::winapi::ERROR_NOT_ENOUGH_MEMORY_, + invalid_block = boost::detail::winapi::ERROR_INVALID_BLOCK_, + bad_environment = boost::detail::winapi::ERROR_BAD_ENVIRONMENT_, + bad_format = boost::detail::winapi::ERROR_BAD_FORMAT_, + invalid_access = boost::detail::winapi::ERROR_INVALID_ACCESS_, + outofmemory = boost::detail::winapi::ERROR_OUTOFMEMORY_, + invalid_drive = boost::detail::winapi::ERROR_INVALID_DRIVE_, + current_directory = boost::detail::winapi::ERROR_CURRENT_DIRECTORY_, + not_same_device = boost::detail::winapi::ERROR_NOT_SAME_DEVICE_, + no_more_files = boost::detail::winapi::ERROR_NO_MORE_FILES_, + write_protect = boost::detail::winapi::ERROR_WRITE_PROTECT_, + bad_unit = boost::detail::winapi::ERROR_BAD_UNIT_, + not_ready = boost::detail::winapi::ERROR_NOT_READY_, + bad_command = boost::detail::winapi::ERROR_BAD_COMMAND_, + crc = boost::detail::winapi::ERROR_CRC_, + bad_length = boost::detail::winapi::ERROR_BAD_LENGTH_, + seek = boost::detail::winapi::ERROR_SEEK_, + not_dos_disk = boost::detail::winapi::ERROR_NOT_DOS_DISK_, + sector_not_found = boost::detail::winapi::ERROR_SECTOR_NOT_FOUND_, + out_of_paper = boost::detail::winapi::ERROR_OUT_OF_PAPER_, + write_fault = boost::detail::winapi::ERROR_WRITE_FAULT_, + read_fault = boost::detail::winapi::ERROR_READ_FAULT_, + gen_failure = boost::detail::winapi::ERROR_GEN_FAILURE_, + sharing_violation = boost::detail::winapi::ERROR_SHARING_VIOLATION_, + lock_violation = boost::detail::winapi::ERROR_LOCK_VIOLATION_, + wrong_disk = boost::detail::winapi::ERROR_WRONG_DISK_, + sharing_buffer_exceeded = boost::detail::winapi::ERROR_SHARING_BUFFER_EXCEEDED_, + handle_eof = boost::detail::winapi::ERROR_HANDLE_EOF_, + handle_disk_full= boost::detail::winapi::ERROR_HANDLE_DISK_FULL_, + rem_not_list = boost::detail::winapi::ERROR_REM_NOT_LIST_, + dup_name = boost::detail::winapi::ERROR_DUP_NAME_, + bad_net_path = boost::detail::winapi::ERROR_BAD_NETPATH_, + network_busy = boost::detail::winapi::ERROR_NETWORK_BUSY_, // ... - file_exists = ERROR_FILE_EXISTS, - cannot_make = ERROR_CANNOT_MAKE, + file_exists = boost::detail::winapi::ERROR_FILE_EXISTS_, + cannot_make = boost::detail::winapi::ERROR_CANNOT_MAKE_, // ... - broken_pipe = ERROR_BROKEN_PIPE, - open_failed = ERROR_OPEN_FAILED, - buffer_overflow = ERROR_BUFFER_OVERFLOW, - disk_full= ERROR_DISK_FULL, + broken_pipe = boost::detail::winapi::ERROR_BROKEN_PIPE_, + open_failed = boost::detail::winapi::ERROR_OPEN_FAILED_, + buffer_overflow = boost::detail::winapi::ERROR_BUFFER_OVERFLOW_, + disk_full= boost::detail::winapi::ERROR_DISK_FULL_, // ... - lock_failed = ERROR_LOCK_FAILED, - busy = ERROR_BUSY, - cancel_violation = ERROR_CANCEL_VIOLATION, - already_exists = ERROR_ALREADY_EXISTS + lock_failed = boost::detail::winapi::ERROR_LOCK_FAILED_, + busy = boost::detail::winapi::ERROR_BUSY_, + cancel_violation = boost::detail::winapi::ERROR_CANCEL_VIOLATION_, + already_exists = boost::detail::winapi::ERROR_ALREADY_EXISTS_ // ... // TODO: add more Windows errors |