From fcdecd4c96d1eabd1f2d7f5529ec6420c6d6502e Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Sun, 20 Jan 2008 02:01:35 +0000 Subject: [PATCH 01/17] Remove extraneous defines since they are inherited from library build Jamfile [SVN r42873] --- test/Jamfile.v2 | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index c608255..3dc7468 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -19,31 +19,24 @@ project : # command line : # input files : # requirements - BOOST_SYSTEM_STATIC_LINK static ] [ run error_code_test.cpp - : : : BOOST_SYSTEM_DYN_LINK - : error_code_test_dll + : : : : error_code_test_dll ] [ run error_code_user_test.cpp - : : : BOOST_SYSTEM_STATIC_LINK - static + : : : static ] [ run error_code_user_test.cpp - : : : BOOST_SYSTEM_DYN_LINK - : error_code_user_test_dll + : : : : error_code_user_test_dll ] [ run system_error_test.cpp - : : : BOOST_SYSTEM_STATIC_LINK - static + : : : static ] [ run system_error_test.cpp - : : : BOOST_SYSTEM_DYN_LINK - : system_error_test_dll + : : : : system_error_test_dll ] [ run initialization_test.cpp - : : : BOOST_SYSTEM_DYN_LINK ] [ run header_only_test.cpp : : : static From 51e9c5642719641a14a7bbae6cb8f231da14ed8c Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Sat, 23 Feb 2008 14:04:02 +0000 Subject: [PATCH 02/17] Give the 1st and 2nd level index.html files a common look-and-feel. [SVN r43402] --- doc/index.html | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/doc/index.html b/doc/index.html index 3e7b50f..50a6267 100644 --- a/doc/index.html +++ b/doc/index.html @@ -11,10 +11,10 @@ - +
- + boost.png (6897 bytes) System Library @@ -132,14 +132,16 @@ Oleg Abrosimov. Christopher Kohlhoff suggested several improvements to the N2066 paper. Johan Nilsson's comments led to several of the refinements in N2066 .


-

© Copyright Beman Dawes, 1999
-Distributed under the Boost Software License, Version 1.0. See -www.boost.org/LICENSE_1_0.txt

-

Revised -November 12, 2007 +February 23, 2008

+

© Copyright Beman Dawes, 1999

+ +

Distributed under the Boost Software License, Version 1.0. +(See file LICENSE_1_0.txt +or  www.boost.org/LICENSE_1_0.txt)

+ \ No newline at end of file From 98a757dbf76f09a028e7a1333a4adc0f5d5d7cb4 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Tue, 27 May 2008 20:01:15 +0000 Subject: [PATCH 03/17] Fix ticket #1609 [SVN r45830] --- test/error_code_test.cpp | 9 +-------- test/header_only_test.cpp | 9 +-------- test/system_error_test.cpp | 9 +-------- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/test/error_code_test.cpp b/test/error_code_test.cpp index 3840823..330ddf0 100644 --- a/test/error_code_test.cpp +++ b/test/error_code_test.cpp @@ -9,14 +9,7 @@ //----------------------------------------------------------------------------// -// VC++ 8.0 warns on usage of certain Standard Library and API functions that -// can cause buffer overruns or other possible security issues if misused. -// See http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx -// But the wording of the warning is misleading and unsettling, there are no -// portable alternative functions, and VC++ 8.0's own libraries use the -// functions in question. So turn off the warnings. -#define _CRT_SECURE_NO_DEPRECATE -#define _SCL_SECURE_NO_DEPRECATE +#include #include #include diff --git a/test/header_only_test.cpp b/test/header_only_test.cpp index 0f4e17b..20d6179 100644 --- a/test/header_only_test.cpp +++ b/test/header_only_test.cpp @@ -9,14 +9,7 @@ //----------------------------------------------------------------------------// -// VC++ 8.0 warns on usage of certain Standard Library and API functions that -// can cause buffer overruns or other possible security issues if misused. -// See http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx -// But the wording of the warning is misleading and unsettling, there are no -// portable altersystem functions, and VC++ 8.0's own libraries use the -// functions in question. So turn off the warnings. -#define _CRT_SECURE_NO_DEPRECATE -#define _SCL_SECURE_NO_DEPRECATE +#include #define BOOST_ERROR_CODE_HEADER_ONLY diff --git a/test/system_error_test.cpp b/test/system_error_test.cpp index 4cbdbd0..d49ced4 100644 --- a/test/system_error_test.cpp +++ b/test/system_error_test.cpp @@ -9,14 +9,7 @@ //----------------------------------------------------------------------------// -// VC++ 8.0 warns on usage of certain Standard Library and API functions that -// can cause buffer overruns or other possible security issues if misused. -// See http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx -// But the wording of the warning is misleading and unsettling, there are no -// portable alternative functions, and VC++ 8.0's own libraries use the -// functions in question. So turn off the warnings. -#define _CRT_SECURE_NO_DEPRECATE -#define _SCL_SECURE_NO_DEPRECATE +#include #include #include From 69d2a2234ce338cde4808db1e48cb3f209a449d4 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Thu, 29 May 2008 01:34:53 +0000 Subject: [PATCH 04/17] Fix Ticket #1768 by including [SVN r45894] --- src/error_code.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/error_code.cpp b/src/error_code.cpp index 02a4cf8..f43eb9a 100644 --- a/src/error_code.cpp +++ b/src/error_code.cpp @@ -9,14 +9,7 @@ //----------------------------------------------------------------------------// -// VC++ 8.0 warns on usage of certain Standard Library and API functions that -// can be cause buffer overruns or other possible security issues if misused. -// See http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx -// But the wording of the warning is misleading and unsettling, there are no -// portable alternative functions, and VC++ 8.0's own libraries use the -// functions in question. So turn off the warnings. -#define _CRT_SECURE_NO_DEPRECATE -#define _SCL_SECURE_NO_DEPRECATE +#include // define BOOST_SYSTEM_SOURCE so that knows // the library is being built (possibly exporting rather than importing code) From 2953464e994b467592b436cdc99e7fb3e1b16953 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Tue, 24 Jun 2008 14:59:10 +0000 Subject: [PATCH 05/17] Apply LWG issue 805, using a namespace to emulate scoped enums. [SVN r46645] --- doc/reference.html | 42 ++++++++++++++--------------- include/boost/system/error_code.hpp | 38 +++++++++++++------------- src/error_code.cpp | 22 +++++++-------- 3 files changed, 52 insertions(+), 50 deletions(-) diff --git a/doc/reference.html b/doc/reference.html index 21b8489..2381252 100644 --- a/doc/reference.html +++ b/doc/reference.html @@ -132,10 +132,10 @@ provided, so users may ignore these macros if they prefer.

template< class T="" > struct is_error_condition_enum { static const bool value = false; }; - // portable error_conditions - namespace posix_error + // generic error_conditions + namespace errc { - enum posix_errno + enum errc_t { success = 0, address_family_not_supported, //EAFNOSUPPORT @@ -218,9 +218,9 @@ provided, so users may ignore these macros if they prefer.

wrong_protocol_type //EPROTOTYPE }; - } // namespace posix_error + } // namespace errc - template<> struct is_error_condition_enum<posix_error::posix_errno> + template<> struct is_error_condition_enum<errc::errc_t> { static const bool value = true; }; bool operator==( const error_code & lhs, const error_code & rhs ); @@ -236,8 +236,8 @@ provided, so users may ignore these macros if they prefer.

bool operator<( const error_code & lhs, const error_code & rhs ); bool operator<( const error_condition & lhs, const error_condition & rhs ); - error_code make_error_code( posix_error::posix_errno e ); - error_condition make_error_condition( posix_error::posix_errno e ); + error_code make_error_code( errc::errc_t e ); + error_condition make_error_condition( errc::errc_t e ); template <class charT, class traits> std::basic_ostream<charT,traits>& @@ -247,7 +247,7 @@ provided, so users may ignore these macros if they prefer.

} } -

The value of each posix_errno constant shall be the same as the +

The value of each errc_t constant shall be the same as the value of the <cerrno> macro shown in the above synopsis.

Users may specialize is_error_code_enum and is_error_condition_enum templates to indicate that a type is eligible for @@ -290,10 +290,10 @@ types should create a single object of each such type. }; const error_category & get_system_category(); - const error_category & get_posix_category(); + const error_category & get_generic_category(); static const error_category & system_category = get_system_category(); - static const error_category & posix_category = get_posix_category(); + static const error_category & generic_category = get_generic_category(); } } @@ -316,7 +316,7 @@ this subclause.

Returns:  error_condition( ev, *this ).

 [--Note: Derived classes will typically convert ev - to some portable error_category, such as posix_category, + to some portable error_category, such as generic_category, and return it as an error_condition for that category. --end note]

@@ -361,7 +361,7 @@ non-member functions identifying errors originating from the operating system.

Throws: Nothing.

-
const error_category & get_posix_category();
+
const error_category & get_generic_category();

Returns: A reference to a error_category object identifying portable error conditions.

@@ -370,7 +370,7 @@ non-member functions

Class error_category predefined objects

Predefined objects system_category -and posix_category identify operating system error codes and portable error conditions, respectively.

+and generic_category identify operating system error codes and portable error conditions, respectively.

Class error_code

The class error_code describes an object used to hold error code @@ -454,7 +454,7 @@ error_code modifiers

void clear();

-

postcondition: value() == 0 && category() == posix_category

+

postcondition: value() == 0 && category() == generic_category

Class error_code observers

@@ -538,7 +538,7 @@ constructors
error_condition(); 

Effects: Constructs an object of type error_condition.

-

Postconditions: val_ == 0 and cat_ == posix_category.

+

Postconditions: val_ == 0 and cat_ == generic_category.

Throws: Nothing.

error_condition( value_type val, const error_category & cat );
@@ -571,7 +571,7 @@ modifiers

void clear();

-

postcondition: value() == 0 && category() == posix_category

+

postcondition: value() == 0 && category() == generic_category

Class error_condition observers

@@ -651,13 +651,13 @@ bool operator!=( const error_condition & condition, const error_code & c   || (lhs.category() == rhs.category() && lhs.value() < rhs.value()).

Throws: Nothing.

-
error_code make_error_code( posix_error::posix_errno e );
+
error_code make_error_code( errc::errc_t e );
-

Returns: error_code( e, posix_category).

+

Returns: error_code( e, generic_category).

-
error_condition make_error_condition( posix_error::posix_errno e );
+
error_condition make_error_condition( errc::errc_t e );
-

Returns: error_condition( e, posix_category).

+

Returns: error_condition( e, generic_category).

template <class charT, class traits>
@@ -743,7 +743,7 @@ Distributed under the Boost Software License, Version 1.0. See
 www.boost.org/LICENSE_1_0.txt

Revised -November 12, 2007 +June 24, 2008

diff --git a/include/boost/system/error_code.hpp b/include/boost/system/error_code.hpp index d06ddef..a5db008 100644 --- a/include/boost/system/error_code.hpp +++ b/include/boost/system/error_code.hpp @@ -47,11 +47,11 @@ namespace boost template< class T > struct is_error_condition_enum { static const bool value = false; }; - // portable error_conditions -------------------------------------------// + // generic error_conditions --------------------------------------------// - namespace posix_error + namespace errc { - enum posix_errno + enum errc_t { success = 0, address_family_not_supported = EAFNOSUPPORT, @@ -134,13 +134,14 @@ namespace boost wrong_protocol_type = EPROTOTYPE }; - } // namespace posix_error + } // namespace errc # ifndef BOOST_SYSTEM_NO_DEPRECATED - namespace posix = posix_error; + namespace posix = errc; + namespace posix_error = errc; # endif - template<> struct is_error_condition_enum + template<> struct is_error_condition_enum { static const bool value = true; }; @@ -199,15 +200,16 @@ namespace boost // predefined error categories -----------------------------------------// BOOST_SYSTEM_DECL const error_category & get_system_category(); - BOOST_SYSTEM_DECL const error_category & get_posix_category(); + BOOST_SYSTEM_DECL const error_category & get_generic_category(); static const error_category & system_category = get_system_category(); - static const error_category & posix_category = get_posix_category(); + static const error_category & generic_category = get_generic_category(); # ifndef BOOST_SYSTEM_NO_DEPRECATED // deprecated synonyms - static const error_category & errno_ecat = get_posix_category(); - static const error_category & native_ecat = get_system_category(); + static const error_category & posix_category = get_generic_category(); + static const error_category & errno_ecat = get_generic_category(); + static const error_category & native_ecat = get_system_category(); # endif // class error_condition -----------------------------------------------// @@ -219,7 +221,7 @@ namespace boost public: // constructors: - error_condition() : m_val(0), m_cat(&get_posix_category()) {} + error_condition() : m_val(0), m_cat(&get_generic_category()) {} error_condition( int val, const error_category & cat ) : m_val(val), m_cat(&cat) {} template @@ -248,7 +250,7 @@ namespace boost void clear() { m_val = 0; - m_cat = &get_posix_category(); + m_cat = &get_generic_category(); } // observers: @@ -436,17 +438,17 @@ namespace boost + reinterpret_cast(&ec.category()); } - // make_* functions for posix_error::posix_errno -----------------------------// + // make_* functions for errc::errc_t -----------------------------// - namespace posix_error + namespace errc { // explicit conversion: - inline error_code make_error_code( posix_errno e ) - { return error_code( e, get_posix_category() ); } + inline error_code make_error_code( errc_t e ) + { return error_code( e, get_generic_category() ); } // implicit conversion: - inline error_condition make_error_condition( posix_errno e ) - { return error_condition( e, get_posix_category() ); } + inline error_condition make_error_condition( errc_t e ) + { return error_condition( e, get_generic_category() ); } } // error_category default implementation -------------------------------// diff --git a/src/error_code.cpp b/src/error_code.cpp index f43eb9a..f2623fc 100644 --- a/src/error_code.cpp +++ b/src/error_code.cpp @@ -38,12 +38,12 @@ using namespace boost::system::posix_error; namespace { - // standard error categories -------------------------------------------// + // standard error categories ---------------------------------------------// - class posix_error_category : public error_category + class generic_error_category : public error_category { public: - posix_error_category(){} + generic_error_category(){} const char * name() const; std::string message( int ev ) const; }; @@ -57,14 +57,14 @@ namespace error_condition default_error_condition( int ev ) const; }; - // posix_error_category implementation ---------------------------------// + // generic_error_category implementation ---------------------------------// - const char * posix_error_category::name() const + const char * generic_error_category::name() const { - return "POSIX"; + return "GENERIC"; } - std::string posix_error_category::message( int ev ) const + std::string generic_error_category::message( int ev ) const { // strerror_r is preferred because it is always thread safe, // however, we fallback to strerror in certain cases because: @@ -318,7 +318,7 @@ namespace std::string system_error_category::message( int ev ) const { - return posix_category.message( ev ); + return generic_category.message( ev ); } # else // TODO: @@ -402,10 +402,10 @@ namespace boost return system_category_const; } - BOOST_SYSTEM_DECL const error_category & get_posix_category() + BOOST_SYSTEM_DECL const error_category & get_generic_category() { - static const posix_error_category posix_category_const; - return posix_category_const; + static const generic_error_category generic_category_const; + return generic_category_const; } } // namespace system From a97517585c0b1f4602ce56d3b7f250f2b9cea0aa Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Wed, 25 Jun 2008 14:16:59 +0000 Subject: [PATCH 06/17] Add const char* constructors to system_error, rationalize test coverage [SVN r46678] --- doc/reference.html | 18 ++++++++- include/boost/system/system_error.hpp | 14 ++++++- test/system_error_test.cpp | 57 +++++++++++++++++++-------- 3 files changed, 70 insertions(+), 19 deletions(-) diff --git a/doc/reference.html b/doc/reference.html index 2381252..be513cd 100644 --- a/doc/reference.html +++ b/doc/reference.html @@ -689,7 +689,10 @@ application program interfaces.

{ public: system_error( error_code ec ); + system_error( error_code ec, const char * what_arg ); system_error( error_code ec, const std::string & what_arg ); + system_error( error_code::value_type ev, const error_category & ecat, + const char * what_arg ); system_error( error_code::value_type ev, const error_category & ecat, const std::string & what_arg ); system_error( error_code::value_type ev, const error_category & ecat); @@ -706,12 +709,25 @@ application program interfaces.

Postcondition: code() == ec
  && std::strcmp( this->runtime_error::what(), "" ) == 0

+
system_error( error_code ec, const char * what_arg );
+
+

Effects: Constructs an object of class system_error.

+

Postcondition: code() == ec
+  && std::strcmp( this->runtime_error::what(), what_arg ) == 0

+
system_error( error_code ec, const std::string & what_arg );

Effects: Constructs an object of class system_error.

Postcondition: code() == ec
  && std::strcmp( this->runtime_error::what(), what_arg.c_str() ) == 0

+
system_error( error_code::value_type ev, const error_category & ecat,
+             const char * what_arg );
+
+

Effects: Constructs an object of class system_error.

+

Postcondition: code() == error_code( ev, ecat )
+  && std::strcmp( this->runtime_error::what(), what_arg ) == 0

+
system_error( error_code::value_type ev, const error_category & ecat,
              const std::string & what_arg );
@@ -743,7 +759,7 @@ Distributed under the Boost Software License, Version 1.0. See www.boost.org/LICENSE_1_0.txt

Revised -June 24, 2008 +June 25, 2008

diff --git a/include/boost/system/system_error.hpp b/include/boost/system/system_error.hpp index 3b4204b..4091647 100644 --- a/include/boost/system/system_error.hpp +++ b/include/boost/system/system_error.hpp @@ -24,13 +24,23 @@ namespace boost public: system_error( error_code ec ) : std::runtime_error(""), m_error_code(ec) {} + system_error( error_code ec, const std::string & what_arg ) : std::runtime_error(what_arg), m_error_code(ec) {} + + system_error( error_code ec, const char* what_arg ) + : std::runtime_error(what_arg), m_error_code(ec) {} + + system_error( int ev, const error_category & ecat ) + : std::runtime_error(""), m_error_code(ev,ecat) {} + system_error( int ev, const error_category & ecat, const std::string & what_arg ) : std::runtime_error(what_arg), m_error_code(ev,ecat) {} - system_error( int ev, const error_category & ecat ) - : std::runtime_error(""), m_error_code(ev,ecat) {} + + system_error( int ev, const error_category & ecat, + const char * what_arg ) + : std::runtime_error(what_arg), m_error_code(ev,ecat) {} virtual ~system_error() throw() {} diff --git a/test/system_error_test.cpp b/test/system_error_test.cpp index d49ced4..269fb5d 100644 --- a/test/system_error_test.cpp +++ b/test/system_error_test.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #ifdef BOOST_WINDOWS_API #include @@ -22,6 +23,7 @@ using boost::system::system_error; using boost::system::error_code; using boost::system::system_category; +using std::string; #define TEST(x,v,w) test(#x,x,v,w) @@ -51,29 +53,52 @@ namespace # endif } - const boost::uint_least32_t uvalue = 1u; + const boost::uint_least32_t uvalue = 2u; } int test_main( int, char *[] ) { - // all combinations of constructors: + // all constructors, in the same order as they appear in the header: - system_error se_0_m( error_code(0, system_category), "se_0_m" ); - system_error se_1_m( 1, system_category, "se_1_m" ); - system_error se_0_nm( error_code(0, system_category), "" ); - system_error se_1_nm( 1, system_category, "" ); - system_error se_0_nmx( error_code(0, system_category), "" ); - system_error se_1_nmx( 1, system_category, "" ); - system_error se_1u_m( uvalue, system_category, "se_1u_m" ); + system_error c1_0( error_code(0, system_category) ); + system_error c1_1( error_code(1, system_category) ); + system_error c1_2u( error_code(uvalue, system_category) ); - TEST( se_0_m, 0, "se_0_m" ); - TEST( se_1_m, 1, "se_1_m: Incorrect function" ); - TEST( se_0_nm, 0, "" ); - TEST( se_1_nm, 1, "Incorrect function" ); - TEST( se_0_nmx, 0, "" ); - TEST( se_1_nmx, 1, "Incorrect function" ); - TEST( se_1u_m, 1, "se_1u_m: Incorrect function" ); + system_error c2_0( error_code(0, system_category), string("c2_0") ); + system_error c2_1( error_code(1, system_category), string("c2_1") ); + system_error c3_0( error_code(0, system_category), "c3_0" ); + system_error c3_1( error_code(1, system_category), "c3_1" ); + + system_error c4_0( 0, system_category ); + system_error c4_1( 1, system_category ); + system_error c4_2u( uvalue, system_category ); + + system_error c5_0( 0, system_category, string("c5_0") ); + system_error c5_1( 1, system_category, string("c5_1") ); + + system_error c6_0( 0, system_category, "c6_0" ); + system_error c6_1( 1, system_category, "c6_1" ); + + TEST( c1_0, 0, "" ); + TEST( c1_1, 1, "Incorrect function" ); + TEST( c1_2u, 2, "The system cannot find the file specified" ); + + TEST( c2_0, 0, "c2_0" ); + TEST( c2_1, 1, "c2_1: Incorrect function" ); + + TEST( c3_0, 0, "c3_0" ); + TEST( c3_1, 1, "c3_1: Incorrect function" ); + + TEST( c4_0, 0, "" ); + TEST( c4_1, 1, "Incorrect function" ); + TEST( c4_2u, 2, "The system cannot find the file specified" ); + + TEST( c5_0, 0, "c5_0" ); + TEST( c5_1, 1, "c5_1: Incorrect function" ); + + TEST( c6_0, 0, "c6_0" ); + TEST( c6_1, 1, "c6_1: Incorrect function" ); return 0; } From d6446d1cfb30f9e96d4ee8ca8e46117ec364cc74 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Thu, 4 Sep 2008 17:36:56 +0000 Subject: [PATCH 07/17] Add error_code throws [SVN r48577] --- include/boost/system/error_code.hpp | 3 +++ src/error_code.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/include/boost/system/error_code.hpp b/include/boost/system/error_code.hpp index a5db008..9f5a207 100644 --- a/include/boost/system/error_code.hpp +++ b/include/boost/system/error_code.hpp @@ -382,6 +382,9 @@ namespace boost }; + // predefined error_code object used as "throw on error" tag + BOOST_SYSTEM_DECL extern error_code throws; + // non-member functions ------------------------------------------------// inline bool operator!=( const error_code & lhs, diff --git a/src/error_code.cpp b/src/error_code.cpp index f2623fc..3c4c762 100644 --- a/src/error_code.cpp +++ b/src/error_code.cpp @@ -396,6 +396,12 @@ namespace boost namespace system { + BOOST_SYSTEM_DECL error_code throws; // "throw on error" special error_code; + // note that it doesn't matter if this + // isn't initialized before use since + // the only use is to take its + // address for comparison purposes + BOOST_SYSTEM_DECL const error_category & get_system_category() { static const system_error_category system_category_const; From b7cd247b64c17f659599e515b986633454fde6f5 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Wed, 1 Oct 2008 14:14:58 +0000 Subject: [PATCH 08/17] Remove redundant Jamfile s [SVN r49080] --- test/Jamfile.v2 | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 3dc7468..7b14c76 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -10,7 +10,6 @@ project : requirements /boost/system//boost_system - BOOST_ALL_NO_LIB msvc:on ; From 84ff2d0f0429ae8f06d08e6262e4c22b173639f7 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Wed, 1 Oct 2008 18:24:20 +0000 Subject: [PATCH 09/17] Initial commit: system/test/msvc_system [SVN r49090] --- test/msvc_system/common.vsprops | 18 ++ .../error_code_test/error_code_test.vcproj | 199 ++++++++++++++++++ test/msvc_system/msvc_system.sln | 20 ++ 3 files changed, 237 insertions(+) create mode 100644 test/msvc_system/common.vsprops create mode 100644 test/msvc_system/error_code_test/error_code_test.vcproj create mode 100644 test/msvc_system/msvc_system.sln diff --git a/test/msvc_system/common.vsprops b/test/msvc_system/common.vsprops new file mode 100644 index 0000000..9a558f8 --- /dev/null +++ b/test/msvc_system/common.vsprops @@ -0,0 +1,18 @@ + + + + + diff --git a/test/msvc_system/error_code_test/error_code_test.vcproj b/test/msvc_system/error_code_test/error_code_test.vcproj new file mode 100644 index 0000000..5857539 --- /dev/null +++ b/test/msvc_system/error_code_test/error_code_test.vcproj @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/msvc_system/msvc_system.sln b/test/msvc_system/msvc_system.sln new file mode 100644 index 0000000..71b8a8e --- /dev/null +++ b/test/msvc_system/msvc_system.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual C++ Express 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "error_code_test", "error_code_test\error_code_test.vcproj", "{81960557-E9A9-4E81-AC96-9E11C33CB058}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {81960557-E9A9-4E81-AC96-9E11C33CB058}.Debug|Win32.ActiveCfg = Debug|Win32 + {81960557-E9A9-4E81-AC96-9E11C33CB058}.Debug|Win32.Build.0 = Debug|Win32 + {81960557-E9A9-4E81-AC96-9E11C33CB058}.Release|Win32.ActiveCfg = Release|Win32 + {81960557-E9A9-4E81-AC96-9E11C33CB058}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal From 463cefcf941478e0414600f379acce8a298e2d10 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Wed, 1 Oct 2008 18:57:48 +0000 Subject: [PATCH 10/17] system: reduce chance of message() throwing in response to ticket #2098 [SVN r49093] --- src/error_code.cpp | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/error_code.cpp b/src/error_code.cpp index 3c4c762..e043a55 100644 --- a/src/error_code.cpp +++ b/src/error_code.cpp @@ -61,11 +61,12 @@ namespace const char * generic_error_category::name() const { - return "GENERIC"; + return "generic"; } std::string generic_error_category::message( int ev ) const { + static std::string unknown_err( "Unknown error" ); // strerror_r is preferred because it is always thread safe, // however, we fallback to strerror in certain cases because: // -- Windows doesn't provide strerror_r. @@ -81,15 +82,19 @@ namespace || (defined(__osf__) && !defined(_REENTRANT))\ || (defined(__vms)) const char * c_str = std::strerror( ev ); - return std::string( c_str ? c_str : "Unknown error" ); - # else + return c_str + ? std::string( c_str ) + : unknown_err; + # else // use strerror_r char buf[64]; char * bp = buf; std::size_t sz = sizeof(buf); # if defined(__CYGWIN__) || defined(__USE_GNU) // Oddball version of strerror_r const char * c_str = strerror_r( ev, bp, sz ); - return std::string( c_str ? c_str : "Unknown error" ); + return c_str + ? std::string( c_str ) + : unknown_err; # else // POSIX version of strerror_r int result; @@ -100,7 +105,9 @@ namespace # if defined (__sgi) const char * c_str = strerror( ev ); result = 0; - return std::string( c_str ? c_str : "Unknown error" ); + return c_str + ? std::string( c_str ) + : unknown_err; # else result = strerror_r( ev, bp, sz ); # endif @@ -113,26 +120,27 @@ namespace result = errno; # endif if ( result != ERANGE ) break; - if ( sz > sizeof(buf) ) std::free( bp ); - sz *= 2; - if ( (bp = static_cast(std::malloc( sz ))) == 0 ) - return std::string( "ENOMEM" ); + if ( sz > sizeof(buf) ) std::free( bp ); + sz *= 2; + if ( (bp = static_cast(std::malloc( sz ))) == 0 ) + return std::string( "ENOMEM" ); } } + std::string msg(); try { - std::string msg( ( result == invalid_argument ) ? "Unknown error" : bp ); - if ( sz > sizeof(buf) ) std::free( bp ); - sz = 0; - return msg; + msg = ( ( result == invalid_argument ) ? "Unknown error" : bp ); } catch(...) { - if ( sz > sizeof(buf) ) std::free( bp ); - throw; + // just eat the exception } - # endif - # endif + + if ( sz > sizeof(buf) ) std::free( bp ); + sz = 0; + return msg; + # endif // else POSIX version of strerror_r + # endif // else use strerror_r } // system_error_category implementation --------------------------------// From ee16863a40e52db69a55894ee823aadeff5a60de Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Wed, 1 Oct 2008 19:08:08 +0000 Subject: [PATCH 11/17] system: add #ifndef as requested by #2098 [SVN r49094] --- src/error_code.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/error_code.cpp b/src/error_code.cpp index e043a55..fa36dc9 100644 --- a/src/error_code.cpp +++ b/src/error_code.cpp @@ -131,10 +131,14 @@ namespace { msg = ( ( result == invalid_argument ) ? "Unknown error" : bp ); } + +# ifndef BOOST_NO_EXCEPTIONS + // See ticket #2098 catch(...) { // just eat the exception } +# endif if ( sz > sizeof(buf) ) std::free( bp ); sz = 0; From a753ffd26f95ceb66555bc1b8f57c8dea8c1ceb1 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Sun, 5 Oct 2008 13:02:01 +0000 Subject: [PATCH 12/17] System: add throws object specification, including semantics [SVN r49138] --- doc/reference.html | 47 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/doc/reference.html b/doc/reference.html index be513cd..68a737a 100644 --- a/doc/reference.html +++ b/doc/reference.html @@ -57,6 +57,8 @@    Class error_condition constructors
   Class error_condition modifiers
   Class error_condition observers
+ throws object
+ Semantics of throws object
Non-member functions
Header <boost/system/system_error.hpp>
   Class system_error
@@ -223,6 +225,11 @@ provided, so users may ignore these macros if they prefer.

template<> struct is_error_condition_enum<errc::errc_t> { static const bool value = true; }; + // predefined error_code object used as "throw on error" tag + extern error_code throws; + + // non-member functions + bool operator==( const error_code & lhs, const error_code & rhs ); bool operator==( const error_code & code, const error_condition & condition ); bool operator==( const error_condition & condition, const error_code & code ); @@ -370,7 +377,7 @@ non-member functions

Class error_category predefined objects

Predefined objects system_category -and generic_category identify operating system error codes and portable error conditions, respectively.

+and generic_category identify system specific error codes and portable error conditions, respectively.

Class error_code

The class error_code describes an object used to hold error code @@ -603,7 +610,29 @@ observers eliminating some sources of user error. One possible implementation choice for this type is pointer to member. --end note ]

-

Non-member functions

+

throws object

+
extern error_code throws;
+

The predefined error_code object throws is supplied +for use as a "throw on error" tag.

+

Semantics of throws object

+

Functions that specify an argument in the form error_code& ec=throws, +with appropriate namespace qualifiers, have the following error handling +semantics:

+
+

Effects: If ec != throws:

+
    +
  • If an error occurs, and sets ec to an appropriate + error_code that identifies the error + value and category. The category should be the most specific + error_category applicable to the + particular error.
  • +
  • if an error does not occur, ec.clear().
  • +
+

Throws: If ec == throws, throws an exception of type + system_error or of a type + derived from system_error.

+
+

Non-member functions

bool operator==( const error_code & lhs, const error_code & rhs );

Returns: lhs.category() == rhs.category() && lhs.value() == @@ -677,8 +706,7 @@ bool operator!=( const error_condition & condition, const error_code & c

Class system_error

The class system_error describes an exception object used to -report error conditions that have an associated error code. Such error -conditions typically originate from the operating system or other low-level +report errors that have an associated error_code. Such errors typically originate from operating system or other low-level application program interfaces.

namespace boost
@@ -754,14 +782,15 @@ application program interfaces.


-

© Copyright Beman Dawes, 2006, 2007
-Distributed under the Boost Software License, Version 1.0. See -www.boost.org/LICENSE_1_0.txt

-

Revised -June 25, 2008 +October 05, 2008

+

© Copyright Beman Dawes, 2006, 2007, 2008

+ +

Distributed under the Boost Software License, Version 1.0. See +www.boost.org/LICENSE_1_0.txt

+ \ No newline at end of file From b4cc2892389e6354ebce1c29371b8d9852ebe742 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Tue, 7 Oct 2008 01:57:24 +0000 Subject: [PATCH 13/17] System: fix typo that is apparent cause of Mac OS X compile failures [SVN r49157] --- src/error_code.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/error_code.cpp b/src/error_code.cpp index fa36dc9..0124665 100644 --- a/src/error_code.cpp +++ b/src/error_code.cpp @@ -126,7 +126,7 @@ namespace return std::string( "ENOMEM" ); } } - std::string msg(); + std::string msg; try { msg = ( ( result == invalid_argument ) ? "Unknown error" : bp ); From 214ed40b22fd47a0f3e00d8bd714a06ced286836 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Wed, 8 Oct 2008 14:16:05 +0000 Subject: [PATCH 14/17] System: refine docs for semantics of throws object [SVN r49177] --- doc/reference.html | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/doc/reference.html b/doc/reference.html index 68a737a..78182dd 100644 --- a/doc/reference.html +++ b/doc/reference.html @@ -619,18 +619,26 @@ for use as a "throw on error" tag.

with appropriate namespace qualifiers, have the following error handling semantics:

-

Effects: If ec != throws:

-
    -
  • If an error occurs, and sets ec to an appropriate - error_code that identifies the error - value and category. The category should be the most specific - error_category applicable to the - particular error.
  • -
  • if an error does not occur, ec.clear().
  • -
-

Throws: If ec == throws, throws an exception of type +

Postconditions:

+
+

If &ec != &throws and an error occurred:

+
    +
  • ec.value() returns the implementation specific error + number for the particular error that occurred.
  • +
  • ec.category() returns the + error_category for ec.value().
  • +
+

if &ec != &throws and an error did not occur, ec.clear().

+
+

Throws:

+
+

If an error occurs and &ec == &throws, throws an exception of type system_error or of a type - derived from system_error.

+ derived from system_error. The + exception's code() member function returns a reference to an + error_code object with the behavior specified in + Postconditions.

+

Non-member functions

bool operator==( const error_code & lhs, const error_code & rhs );
@@ -783,7 +791,7 @@ application program interfaces.


Revised -October 05, 2008 +October 08, 2008

© Copyright Beman Dawes, 2006, 2007, 2008

From 4dc986ca039cf75cc9cfaa3c4b083eb94f61a54c Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Thu, 9 Oct 2008 19:01:57 +0000 Subject: [PATCH 15/17] System: Only supply case EALREADY if EALREADY != EBUSY, to close a portion of ticket #2288 [SVN r49220] --- src/error_code.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/error_code.cpp b/src/error_code.cpp index 0124665..55fcfc6 100644 --- a/src/error_code.cpp +++ b/src/error_code.cpp @@ -166,7 +166,9 @@ namespace case EADDRNOTAVAIL: return make_error_condition( address_not_available ); case EAFNOSUPPORT: return make_error_condition( address_family_not_supported ); case EAGAIN: return make_error_condition( resource_unavailable_try_again ); +# if EALREADY != EBUSY // EALREADY and EBUSY are the same on QNX Neutrino case EALREADY: return make_error_condition( connection_already_in_progress ); +# endif case EBADF: return make_error_condition( bad_file_descriptor ); case EBADMSG: return make_error_condition( bad_message ); case EBUSY: return make_error_condition( device_or_resource_busy ); From d19e139e1181cd191f7ca2616279da167a024cb7 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Sun, 12 Oct 2008 13:07:11 +0000 Subject: [PATCH 16/17] Change names to ErrorCodeEnum and ErrorConditionEnum to conform to N2798 [SVN r49290] --- include/boost/system/error_code.hpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/include/boost/system/error_code.hpp b/include/boost/system/error_code.hpp index 9f5a207..c79c26c 100644 --- a/include/boost/system/error_code.hpp +++ b/include/boost/system/error_code.hpp @@ -224,9 +224,9 @@ namespace boost error_condition() : m_val(0), m_cat(&get_generic_category()) {} error_condition( int val, const error_category & cat ) : m_val(val), m_cat(&cat) {} - template - error_condition(ConditionEnum e, - typename boost::enable_if >::type* = 0) + template + error_condition(ErrorConditionEnum e, + typename boost::enable_if >::type* = 0) { *this = make_error_condition(e); } @@ -239,9 +239,9 @@ namespace boost m_cat = &cat; } - template - typename boost::enable_if, error_condition>::type & - operator=( ConditionEnum val ) + template + typename boost::enable_if, error_condition>::type & + operator=( ErrorConditionEnum val ) { *this = make_error_condition(val); return *this; @@ -311,9 +311,9 @@ namespace boost error_code() : m_val(0), m_cat(&get_system_category()) {} error_code( int val, const error_category & cat ) : m_val(val), m_cat(&cat) {} - template - error_code(CodeEnum e, - typename boost::enable_if >::type* = 0) + template + error_code(ErrorCodeEnum e, + typename boost::enable_if >::type* = 0) { *this = make_error_code(e); } @@ -325,9 +325,9 @@ namespace boost m_cat = &cat; } - template - typename boost::enable_if, error_code>::type & - operator=( CodeEnum val ) + template + typename boost::enable_if, error_code>::type & + operator=( ErrorCodeEnum val ) { *this = make_error_code(val); return *this; From dca57ac132c679b38c10f04e1372825f021e0c3b Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Sun, 12 Oct 2008 13:27:59 +0000 Subject: [PATCH 17/17] System: Upgrade docs to reflect N2798 (and thus CD1), fix ticket #2125, and provide a table of deprecated names and their replacements. [SVN r49291] --- doc/reference.html | 90 +++++++++++++++++++++++++++++++++------------- 1 file changed, 65 insertions(+), 25 deletions(-) diff --git a/doc/reference.html b/doc/reference.html index 78182dd..a451c82 100644 --- a/doc/reference.html +++ b/doc/reference.html @@ -39,6 +39,7 @@
Introduction
Macros
+ Deprecated names
Header <boost/system/error_code.hpp>
Class error_category
   Class error_category synopsis
@@ -116,6 +117,45 @@ provided, so users may ignore these macros if they prefer.

Deprecated features are excluded.
+

Deprecated names

+

In the process of adding Boost.System to C++0x standard library, some of the +names are being changed. To ease transition, Boost.System deprecates the old +names, but continues to provide them unless macro BOOST_SYSTEM_NO_DEPRECATED +is defined.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Old name, now deprecatedNew name
namespace posixnamespace errc
namespace posix_errornamespace errc
enum posix_errnoenum errc_t
get_posix_category()get_generic_category()
posix_categorygeneric_category
errno_ecatgeneric_category
native_ecatsystem_category

Header <boost/system/error_code.hpp>

<boost/system/error_code.hpp> synopsis

@@ -286,7 +326,7 @@ types should create a single object of each such type. virtual ~error_category(); virtual const char * name() const = 0; - virtual string message( error_code::value_type ev ) const = 0; + virtual string message( int ev ) const = 0; virtual error_condition default_error_condition( int ev ) const; virtual bool equivalent( int code, const error_condition & condition ) const; virtual bool equivalent( const error_code & code, int condition ) const; @@ -312,7 +352,7 @@ this subclause.

Returns: a string naming the error category.

Throws: Nothing.

-
virtual string message( error_code::value_type ev ) const=0;
+
virtual string message( int ev ) const=0;

Returns: A string that describes the error denoted by ev.

@@ -399,7 +439,7 @@ error_code synopsis error_code(); error_code( val, const error_category & cat ); template <class ErrorCodeEnum> - error_code( errorCodeEnum e, + error_code( ErrorCodeEnum e, typename enable_if<is_error_code_enum<ErrorCodeEnum> >::type* = 0); // modifiers: @@ -418,7 +458,7 @@ error_code synopsis private: int val_; // exposition only - const error_category & cat_; // exposition only + const error_category * cat_; // exposition only }; } } @@ -449,7 +489,7 @@ error_code constructors error_code modifiers
void assign( int val, const error_category & cat );
-

Postconditions: val_ == val && cat_ == cat.

+

Postconditions: val_ == val && cat_ == &cat.

Throws: Nothing.

template<typename ErrorCodeEnum>
@@ -470,9 +510,9 @@ error_code observers
 

Returns: val_.

Throws: Nothing.

-

error_category category() const;

+

const error_category & category() const;

-

Returns: cat_.

+

Returns: *cat_.

Throws: Nothing.

error_condition default_error_condition() const;
@@ -487,7 +527,7 @@ error_code observers

operator unspecified-bool-type() const;

-

Returns: if value() != value_type(), returns a value that will evaluate +

Returns: if value() != 0, returns a value that will evaluate true in a boolean context; otherwise, returns a value that will evaluate false in a boolean context. The value type returned shall not be convertible to int.

@@ -534,8 +574,8 @@ implementation specific. --end note ]

operator unspecified-bool-type () const; private: - int val_; // exposition only - const error_category & cat_; // exposition only + int val_; // exposition only + const error_category * cat_; // exposition only }; } } @@ -545,13 +585,13 @@ constructors
error_condition(); 

Effects: Constructs an object of type error_condition.

-

Postconditions: val_ == 0 and cat_ == generic_category.

+

Postconditions: val_ == 0 and cat_ == &generic_category.

Throws: Nothing.

-
error_condition( value_type val, const error_category & cat );
+
error_condition( int val, const error_category & cat );

Effects: Constructs an object of type error_condition.

-

Postconditions: val_ == val and cat_ == cat.

+

Postconditions: val_ == val and cat_ == &cat.

Throws: Nothing.

template <class ErrorConditionEnum>
@@ -564,9 +604,9 @@ constructors
 

Class error_condition modifiers

-
void assign( value_type val, const error_category & cat ); 
+
void assign( int val, const error_category & cat ); 
-

Postconditions: val_ == val and cat_ == cat.

+

Postconditions: val_ == val and cat_ == &cat.

Throws: Nothing.

template<typename ErrorConditionEnum>
@@ -582,14 +622,14 @@ modifiers
 
 

Class error_condition observers

-
value_type value() const;
+
int value() const;

Returns: val_.

Throws: Nothing

const error_category & category() const;
-

Returns: cat_.

+

Returns: *cat_.

Throws: Nothing.

string message() const;
@@ -694,7 +734,7 @@ bool operator!=( const error_condition & condition, const error_code & c
error_condition make_error_condition( errc::errc_t e );
-

Returns: error_condition( e, generic_category).

+

Returns: error_condition( static_cast<int>( e ), generic_category).

template <class charT, class traits>
@@ -727,11 +767,11 @@ application program interfaces.

system_error( error_code ec ); system_error( error_code ec, const char * what_arg ); system_error( error_code ec, const std::string & what_arg ); - system_error( error_code::value_type ev, const error_category & ecat, + system_error( int ev, const error_category & ecat, const char * what_arg ); - system_error( error_code::value_type ev, const error_category & ecat, + system_error( int ev, const error_category & ecat, const std::string & what_arg ); - system_error( error_code::value_type ev, const error_category & ecat); + system_error( int ev, const error_category & ecat); const error_code & code() const throw(); const char * what() const throw(); @@ -757,21 +797,21 @@ application program interfaces.

Postcondition: code() == ec
  && std::strcmp( this->runtime_error::what(), what_arg.c_str() ) == 0

-
system_error( error_code::value_type ev, const error_category & ecat,
+
system_error( int ev, const error_category & ecat,
              const char * what_arg );

Effects: Constructs an object of class system_error.

Postcondition: code() == error_code( ev, ecat )
  && std::strcmp( this->runtime_error::what(), what_arg ) == 0

-
system_error( error_code::value_type ev, const error_category & ecat,
+
system_error( int ev, const error_category & ecat,
              const std::string & what_arg );

Effects: Constructs an object of class system_error.

Postcondition: code() == error_code( ev, ecat )
  && std::strcmp( this->runtime_error::what(), what_arg.c_str() ) == 0

-
system_error( error_code::value_type ev, const error_category & ecat );
+
system_error( int ev, const error_category & ecat );

Effects: Constructs an object of class system_error.

Postcondition: code() == error_code( ev, ecat )
@@ -791,7 +831,7 @@ application program interfaces.


Revised -October 08, 2008 +October 11, 2008

© Copyright Beman Dawes, 2006, 2007, 2008