Boost logo

Boost-Commit :

From: bdawes_at_[hidden]
Date: 2007-09-05 21:00:14


Author: bemandawes
Date: 2007-09-05 21:00:11 EDT (Wed, 05 Sep 2007)
New Revision: 39133
URL: http://svn.boost.org/trac/boost/changeset/39133

Log:
Get rid of non_posix_equivalent, fix Jamfiles, fix Linux typos, refactor so basic_filesystem_error::what() works on compilers that screw up member specializations
Text files modified:
   branches/libs/filesystem/boost/filesystem/path.hpp | 82 ++++++++++++++++++++++++++-------------
   branches/libs/filesystem/filesystem/build/Jamfile.v2 | 4
   branches/libs/filesystem/filesystem/src/path.cpp | 33 ++++++++++++++++
   branches/libs/filesystem/filesystem/test/Jamfile.v2 | 4
   branches/libs/filesystem/filesystem/test/operations_test.cpp | 12 ++++
   branches/libs/system/boost/system/error_code.hpp | 4 -
   branches/libs/system/system/src/error_code.cpp | 7 ++
   branches/libs/system/system/test/error_code_test.cpp | 20 ++++++---
   branches/libs/system/system/test/error_code_user_test.cpp | 26 ++++++-----
   branches/libs/system/system/test/header_only_test.cpp | 2
   10 files changed, 135 insertions(+), 59 deletions(-)

Modified: branches/libs/filesystem/boost/filesystem/path.hpp
==============================================================================
--- branches/libs/filesystem/boost/filesystem/path.hpp (original)
+++ branches/libs/filesystem/boost/filesystem/path.hpp 2007-09-05 21:00:11 EDT (Wed, 05 Sep 2007)
@@ -566,6 +566,53 @@
     }
 # endif
 
+ // basic_filesystem_error helpers --------------------------------------//
+
+ // Originally choice of implementation was done via specialization of
+ // basic_filesystem_error::what(). Several compilers (GCC, aCC, etc.)
+ // couldn't handle that, so the choice is now accomplished by overloading.
+
+ namespace detail
+ {
+ // BOOST_FILESYSTEM_DECL version works for VC++ but not GCC. Go figure!
+ inline
+ const char * what( const char * sys_err_what,
+ const path & path1, const path & path2, std::string & target )
+ {
+ try
+ {
+ if ( target.empty() )
+ {
+ target = sys_err_what;
+ if ( !path1.empty() )
+ {
+ target += ": \"";
+ target += path1.file_string();
+ target += "\"";
+ }
+ if ( !path2.empty() )
+ {
+ target += ", \"";
+ target += path2.file_string();
+ target += "\"";
+ }
+ }
+ return target.c_str();
+ }
+ catch (...)
+ {
+ return sys_err_what;
+ }
+ }
+
+ template<class Path>
+ const char * what( const char * sys_err_what,
+ const Path & path1, const Path & path2, std::string & target )
+ {
+ return sys_err_what;
+ }
+ }
+
     // basic_filesystem_error ----------------------------------------------//
 
     template<class Path>
@@ -599,7 +646,13 @@
         return m_imp_ptr.get() ? m_imp_ptr->m_path2 : empty_path ;
       }
 
- const char * what() const throw() { return system_error::what(); }
+ const char * what() const throw()
+ {
+ if ( !m_imp_ptr.get() )
+ return system_error::what();
+ return detail::what( system_error::what(), m_imp_ptr->m_path1,
+ m_imp_ptr->m_path2, m_imp_ptr->m_what );
+ }
 
     private:
       struct m_imp
@@ -611,33 +664,6 @@
       boost::shared_ptr<m_imp> m_imp_ptr;
     };
 
-// This specialization is causing problems with GCC, aCC (HP-UX)
-// and cxx on Alpha platforms.
-#if !(defined(__GNUC__) || defined(__HP_aCC) || \
- (defined(__DECCXX) && defined(__alpha)))
- template<> const char * basic_filesystem_error<path>::what() const throw()
- {
- if ( !m_imp_ptr.get() ) return system_error::what();
- if ( m_imp_ptr->m_what.empty() )
- {
- m_imp_ptr->m_what = system_error::what();
- if ( !path1().empty() )
- {
- m_imp_ptr->m_what += ": \"";
- m_imp_ptr->m_what += path1().file_string();
- m_imp_ptr->m_what += "\"";
- }
- if ( !path2().empty() )
- {
- m_imp_ptr->m_what += ", \"";
- m_imp_ptr->m_what += path2().file_string();
- m_imp_ptr->m_what += "\"";
- }
- }
- return m_imp_ptr->m_what.c_str();
- }
-#endif
-
     typedef basic_filesystem_error<path> filesystem_error;
 
 # ifndef BOOST_FILESYSTEM_NARROW_ONLY

Modified: branches/libs/filesystem/filesystem/build/Jamfile.v2
==============================================================================
--- branches/libs/filesystem/filesystem/build/Jamfile.v2 (original)
+++ branches/libs/filesystem/filesystem/build/Jamfile.v2 2007-09-05 21:00:11 EDT (Wed, 05 Sep 2007)
@@ -21,8 +21,8 @@
     $(SOURCES).cpp
     ../../system/build//boost_system
     :
- <link>shared:<define>BOOST_FILESYSTEM_DYN_LINK=1 # tell source we're building dll's
- <link>static:<define>BOOST_FILESYSTEM_STATIC_LINK=1 # tell source we're building static lib's
+ <link>shared:<define>BOOST_ALL_DYN_LINK=1 # tell source we're building dll's
+ <link>static:<define>BOOST_All_STATIC_LINK=1 # tell source we're building static lib's
     ;
 
 install dist-lib

Modified: branches/libs/filesystem/filesystem/src/path.cpp
==============================================================================
--- branches/libs/filesystem/filesystem/src/path.cpp (original)
+++ branches/libs/filesystem/filesystem/src/path.cpp 2007-09-05 21:00:11 EDT (Wed, 05 Sep 2007)
@@ -71,6 +71,39 @@
           system::make_error_code( system::posix::not_supported ) ) );
       imbue( new_loc, std::nothrow );
     }
+
+ //namespace detail
+ //{
+ // BOOST_FILESYSTEM_DECL
+ // const char * what( const char * sys_err_what,
+ // const path & path1, const path & path2, std::string & target)
+ // {
+ // try
+ // {
+ // if ( target.empty() )
+ // {
+ // target = sys_err_what;
+ // if ( !path1.empty() )
+ // {
+ // target += ": \"";
+ // target += path1.file_string();
+ // target += "\"";
+ // }
+ // if ( !path2.empty() )
+ // {
+ // target += ", \"";
+ // target += path2.file_string();
+ // target += "\"";
+ // }
+ // }
+ // return target.c_str();
+ // }
+ // catch (...)
+ // {
+ // return sys_err_what;
+ // }
+ // }
+ //}
     
 # ifdef BOOST_POSIX_API
 

Modified: branches/libs/filesystem/filesystem/test/Jamfile.v2
==============================================================================
--- branches/libs/filesystem/filesystem/test/Jamfile.v2 (original)
+++ branches/libs/filesystem/filesystem/test/Jamfile.v2 2007-09-05 21:00:11 EDT (Wed, 05 Sep 2007)
@@ -16,7 +16,7 @@
                  <runtime-link>static <link>static
        ]
        [ run path_test.cpp ../../system/build
- : : : <define>BOOST_FILESYSTEM_DYN_LINK
+ : : : <define>BOOST_FILESYSTEM_DYN_LINK <define>BOOST_SYSTEM_DYN_LINK
                : path_test_dll
        ]
        [ run operations_test.cpp
@@ -24,7 +24,7 @@
                   <runtime-link>static <link>static
        ]
        [ run operations_test.cpp ../../system/build
- : : : <define>BOOST_FILESYSTEM_DYN_LINK
+ : : : <define>BOOST_FILESYSTEM_DYN_LINK <define>BOOST_SYSTEM_DYN_LINK
          : operations_test_dll
        ]
        [ run fstream_test.cpp

Modified: branches/libs/filesystem/filesystem/test/operations_test.cpp
==============================================================================
--- branches/libs/filesystem/filesystem/test/operations_test.cpp (original)
+++ branches/libs/filesystem/filesystem/test/operations_test.cpp 2007-09-05 21:00:11 EDT (Wed, 05 Sep 2007)
@@ -16,7 +16,7 @@
 
 #include <boost/filesystem/operations.hpp>
 #include <boost/filesystem/convenience.hpp>
-#include <boost/filesystem/cerrno.hpp>
+#include <boost/cerrno.hpp>
 namespace fs = boost::filesystem;
 
 #include <boost/config.hpp>
@@ -178,6 +178,10 @@
         bool ok ( std::strcmp( x.what(),
           "boost::filesystem::create_directory: The system cannot find the path specified: \"no-such-dir\\foo\\bar\"" ) == 0 );
         BOOST_CHECK( ok );
+ if ( !ok )
+ {
+ std::cout << "what returns \"" << x.what() << "\"" << std::endl;
+ }
       }
     }
     BOOST_CHECK( exception_thrown );
@@ -196,6 +200,10 @@
         bool ok ( std::strcmp( x.what(),
           "boost::filesystem::create_directory: The system cannot find the path specified: \"no-such-dir\\foo\\bar\"" ) == 0 );
         BOOST_CHECK( ok );
+ if ( !ok )
+ {
+ std::cout << "what returns \"" << x.what() << "\"" << std::endl;
+ }
       }
     }
     BOOST_CHECK( exception_thrown );
@@ -222,7 +230,7 @@
                ? "Windows"
                : "POSIX";
 # endif
- std::cout << "API is " << platform << '\n';
+ std::cout << "API is " << platform << std::endl;
 
   exception_tests();
 

Modified: branches/libs/system/boost/system/error_code.hpp
==============================================================================
--- branches/libs/system/boost/system/error_code.hpp (original)
+++ branches/libs/system/boost/system/error_code.hpp 2007-09-05 21:00:11 EDT (Wed, 05 Sep 2007)
@@ -133,8 +133,6 @@
         too_many_synbolic_link_levels = ELOOP,
         value_too_large = EOVERFLOW,
         wrong_protocol_type = EPROTOTYPE,
-
- no_posix_equivalent = -1 // TODO: is this a safe value?
       };
 
     } // namespace posix
@@ -548,7 +546,7 @@
       };
     } // namespace Linux
 
- template<> struct is_error_code_enum<Linux::linux_errno>
+ template<> struct is_error_code_enum<Linux::linux_error>
       { static const bool value = true; };
 
     inline error_code make_error_code(Linux::linux_error e)

Modified: branches/libs/system/system/src/error_code.cpp
==============================================================================
--- branches/libs/system/system/src/error_code.cpp (original)
+++ branches/libs/system/system/src/error_code.cpp 2007-09-05 21:00:11 EDT (Wed, 05 Sep 2007)
@@ -304,12 +304,15 @@
       ++cur;
     } while ( cur != system_to_posix
       + sizeof(system_to_posix)/sizeof(system_to_posix_t) );
- return boost::system::posix::no_posix_equivalent;
+ return static_cast<posix::posix_errno>(-1);
   }
 
   error_condition system_error_category::default_error_condition( int ev ) const
   {
- return error_condition( posix(ev), posix_category );
+ int tmp = posix(ev);
+ return tmp >= 0
+ ? error_condition( tmp, posix_category )
+ : error_condition( ev, system_category );
   }
 
 # if !defined( BOOST_WINDOWS_API )

Modified: branches/libs/system/system/test/error_code_test.cpp
==============================================================================
--- branches/libs/system/system/test/error_code_test.cpp (original)
+++ branches/libs/system/system/test/error_code_test.cpp 2007-09-05 21:00:11 EDT (Wed, 05 Sep 2007)
@@ -133,30 +133,34 @@
   BOOST_CHECK( ec.value() == ERROR_FILE_NOT_FOUND );
   BOOST_CHECK( ec == posix::no_such_file_or_directory );
   BOOST_CHECK( ec.default_error_condition().value() == posix::no_such_file_or_directory );
+ BOOST_CHECK( ec.default_error_condition().category() == posix_category );
 
   // test the second entry in the decoder table:
   ec = error_code( ERROR_PATH_NOT_FOUND, system_category );
   BOOST_CHECK( ec.value() == ERROR_PATH_NOT_FOUND );
   BOOST_CHECK( ec == posix::no_such_file_or_directory );
   BOOST_CHECK( ec.default_error_condition().value() == posix::no_such_file_or_directory );
+ BOOST_CHECK( ec.default_error_condition().category() == posix_category );
 
   // test the third entry in the decoder table:
   ec = error_code( ERROR_ACCESS_DENIED, system_category );
   BOOST_CHECK( ec.value() == ERROR_ACCESS_DENIED );
   BOOST_CHECK( ec == posix::permission_denied );
   BOOST_CHECK( ec.default_error_condition().value() == posix::permission_denied );
+ BOOST_CHECK( ec.default_error_condition().category() == posix_category );
 
   // test the last regular entry in the decoder table:
   ec = error_code( ERROR_WRITE_PROTECT, system_category );
   BOOST_CHECK( ec.value() == ERROR_WRITE_PROTECT );
   BOOST_CHECK( ec == posix::permission_denied );
   BOOST_CHECK( ec.default_error_condition().value() == posix::permission_denied );
+ BOOST_CHECK( ec.default_error_condition().category() == posix_category );
 
   // test not-in-table condition:
   ec = error_code( 1234567890, system_category );
   BOOST_CHECK( ec.value() == 1234567890 );
- BOOST_CHECK( ec == posix::no_posix_equivalent );
- BOOST_CHECK( ec.default_error_condition().value() == posix::no_posix_equivalent );
+ BOOST_CHECK( ec.default_error_condition().value() == 1234567890 );
+ BOOST_CHECK( ec.default_error_condition().category() == system_category );
 
 #else // POSIX
 
@@ -166,6 +170,8 @@
   BOOST_CHECK( error_code( posix::permission_denied, system_category ) == ec );
   BOOST_CHECK( ec == posix::permission_denied );
   BOOST_CHECK( posix::permission_denied == ec );
+ BOOST_CHECK( ec.default_error_condition().value() == posix::permission_denied );
+ BOOST_CHECK( ec.default_error_condition().category() == posix_category );
 
 # ifdef __CYGWIN__
 
@@ -174,16 +180,16 @@
   BOOST_CHECK( ec == cygwin::no_package );
   BOOST_CHECK( ec == error_code( ENOPKG, system_category ) );
   BOOST_CHECK( ec == error_code( cygwin::no_package, system_category ) );
- BOOST_CHECK( ec == posix::no_posix_equivalent );
+ BOOST_CHECK( ec.default_error_condition().category() == system_category );
 
 # elif defined(linux) || defined(__linux) || defined(__linux__)
 
   std::cout << "Linux tests...\n";
- ec = lnx::dot_dot_error;
- BOOST_CHECK( ec == lnx::dot_dot_error );
+ ec = Linux::dot_dot_error;
+ BOOST_CHECK( ec == Linux::dot_dot_error );
   BOOST_CHECK( ec == error_code( EDOTDOT, system_category ) );
- BOOST_CHECK( ec == error_code( lnx::dot_dot_error, system_category ) );
- BOOST_CHECK( ec == posix::no_posix_equivalent );
+ BOOST_CHECK( ec == error_code( Linux::dot_dot_error, system_category ) );
+ BOOST_CHECK( ec.default_error_condition().category() == posix_category );
 
 # endif
 

Modified: branches/libs/system/system/test/error_code_user_test.cpp
==============================================================================
--- branches/libs/system/system/test/error_code_user_test.cpp (original)
+++ branches/libs/system/system/test/error_code_user_test.cpp 2007-09-05 21:00:11 EDT (Wed, 05 Sep 2007)
@@ -112,11 +112,11 @@
 
       boost::system::error_condition default_error_condition( int ev ) const
       {
- return boost::system::error_condition(
- ev == boo_boo
- ? boost::system::posix::io_error
- : boost::system::posix::no_posix_equivalent,
- boost::system::posix_category );
+ return ev == boo_boo
+ ? boost::system::error_condition( boost::system::posix::io_error,
+ boost::system::posix_category )
+ : boost::system::error_condition( ev,
+ boost::lib3::lib3_error_category );
       }
       
       std::string message( int ev ) const
@@ -169,11 +169,10 @@
 
     boost::system::error_condition default_error_condition( int ev ) const
     {
- return boost::system::error_condition(
- ev == boo_boo.value()
- ? boost::system::posix::io_error
- : boost::system::posix::no_posix_equivalent,
- boost::system::posix_category );
+ return ev == boo_boo.value()
+ ? boost::system::error_condition( boost::system::posix::io_error,
+ boost::system::posix_category )
+ : boost::system::error_condition( ev, lib4::lib4_error_category );
     }
     
     std::string message( int ev ) const
@@ -363,7 +362,9 @@
 
   boost::system::error_code ec3( boost::lib3::boo_boo+100,
     boost::lib3::lib3_error_category );
- BOOST_CHECK( ec3 == boost::system::posix::no_posix_equivalent );
+ BOOST_CHECK( ec3.category() == boost::lib3::lib3_error_category );
+ BOOST_CHECK( ec3.default_error_condition().category()
+ == boost::lib3::lib3_error_category );
 
   // Library 4 tests:
 
@@ -379,7 +380,8 @@
 
   boost::system::error_code ec4( lib4::boo_boo.value()+100,
     lib4::lib4_error_category );
- BOOST_CHECK( ec4 == boost::system::posix::no_posix_equivalent );
+ BOOST_CHECK( ec4.default_error_condition().category()
+ == lib4::lib4_error_category );
 
   // Test 3
 

Modified: branches/libs/system/system/test/header_only_test.cpp
==============================================================================
--- branches/libs/system/system/test/header_only_test.cpp (original)
+++ branches/libs/system/system/test/header_only_test.cpp 2007-09-05 21:00:11 EDT (Wed, 05 Sep 2007)
@@ -28,4 +28,4 @@
 {
   boost::system::error_code ec( 0, boost::system::system_category );
   return 0;
-}
\ No newline at end of file
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk