Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72921 - in branches/release: boost boost/filesystem boost/filesystem/v3 libs/filesystem libs/filesystem/v3/src
From: bdawes_at_[hidden]
Date: 2011-07-05 10:49:42


Author: bemandawes
Date: 2011-07-05 10:49:42 EDT (Tue, 05 Jul 2011)
New Revision: 72921
URL: http://svn.boost.org/trac/boost/changeset/72921

Log:
Merge changeset 72855. Authorized by Daniel James.
Properties modified:
   branches/release/boost/filesystem/ (props changed)
   branches/release/boost/filesystem.hpp (props changed)
   branches/release/libs/filesystem/ (props changed)
Text files modified:
   branches/release/boost/filesystem/v3/path.hpp | 13 ++++++++++++-
   branches/release/libs/filesystem/v3/src/path.cpp | 37 +++++++++++++++++++++----------------
   2 files changed, 33 insertions(+), 17 deletions(-)

Modified: branches/release/boost/filesystem/v3/path.hpp
==============================================================================
--- branches/release/boost/filesystem/v3/path.hpp (original)
+++ branches/release/boost/filesystem/v3/path.hpp 2011-07-05 10:49:42 EDT (Tue, 05 Jul 2011)
@@ -125,7 +125,7 @@
     path(){}
 
     path(const path& p) : m_pathname(p.m_pathname) {}
-
+
     template <class Source>
     path(Source const& source,
       typename boost::enable_if<path_traits::is_pathable<
@@ -134,6 +134,17 @@
       path_traits::dispatch(source, m_pathname, codecvt());
     }
 
+ // Overloads for the operating system API's native character type. Rationale:
+ // - Avoids use of codecvt() for native value_type strings. This limits the
+ // impact of locale("") initialization failures on POSIX systems to programs
+ // that actually depend on locale(""). It further ensures that exceptions thrown
+ // as a result of such failues occur after main() has started, so can be caught.
+ // This is a partial resolution of tickets 4688, 5100, and 5289.
+ // - A slight optimization for a common use case, particularly on POSIX since
+ // value_type is char and that is the most common useage.
+ path(const value_type* s) : m_pathname(s) {}
+ path(const std::basic_string<value_type>& s) : m_pathname(s) {}
+
     template <class Source>
     path(Source const& source, const codecvt_type& cvt)
     // see note above explaining why codecvt() default arguments are not used

Modified: branches/release/libs/filesystem/v3/src/path.cpp
==============================================================================
--- branches/release/libs/filesystem/v3/src/path.cpp (original)
+++ branches/release/libs/filesystem/v3/src/path.cpp 2011-07-05 10:49:42 EDT (Tue, 05 Jul 2011)
@@ -727,11 +727,6 @@
   // locale helpers //
   //------------------------------------------------------------------------------------//
 
- // std::locale construction can throw (if LC_MESSAGES is wrong, for example),
- // so a static at function scope is used to ensure that exceptions can be
- // caught. (A previous version was at namespace scope, so initialization
- // occurred before main(), preventing exceptions from being caught.)
-
   std::locale default_locale()
   {
 # ifdef BOOST_WINDOWS_API
@@ -741,32 +736,43 @@
 
 # elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
     // "All BSD system functions expect their string parameters to be in UTF-8 encoding
- // and nothing else." http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPInternational/Articles/FileEncodings.html
+ // and nothing else." See
+ // http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPInternational/Articles/FileEncodings.html
     //
     // "The kernel will reject any filename that is not a valid UTF-8 string, and it will
     // even be normalized (to Unicode NFD) before stored on disk, at least when using HFS.
     // The right way to deal with it would be to always convert the filename to UTF-8
- // before trying to open/create a file." http://lists.apple.com/archives/unix-porting/2007/Sep/msg00023.html
+ // before trying to open/create a file." See
+ // http://lists.apple.com/archives/unix-porting/2007/Sep/msg00023.html
     //
     // "How a file name looks at the API level depends on the API. Current Carbon APIs
     // handle file names as an array of UTF-16 characters; POSIX ones handle them as an
     // array of UTF-8, which is why UTF-8 works well in Terminal. How it's stored on disk
     // depends on the disk format; HFS+ uses UTF-16, but that's not important in most
- // cases." http://lists.apple.com/archives/applescript-users/2002/Sep/msg00319.html
+ // cases." See
+ // http://lists.apple.com/archives/applescript-users/2002/Sep/msg00319.html
     //
     // Many thanks to Peter Dimov for digging out the above references!
+
     std::locale global_loc = std::locale();
     std::locale loc(global_loc, new boost::filesystem::detail::utf8_codecvt_facet);
     return loc;
 
-# else
- // ISO C calls this "the locale-specific native environment":
+# else // Other POSIX
+
+ // ISO C calls std::locale("") "the locale-specific native environment", and this
+ // locale is the default for many POSIX-based operating systems such as Linux.
+
+ // std::locale("") construction can throw (if environmental variables LC_MESSAGES or
+ // or LANG are wrong, for example), so dynamic initialization is used to ensure
+ // that exceptions can be caught.
+
     return std::locale("");
 
 # endif
   }
 
- std::locale & path_locale()
+ std::locale& path_locale()
   {
     static std::locale loc(default_locale());
     return loc;
@@ -783,8 +789,7 @@
 namespace filesystem3
 {
 
- const path::codecvt_type *&
- path::wchar_t_codecvt_facet()
+ const path::codecvt_type *& path::wchar_t_codecvt_facet()
   {
    static const std::codecvt<wchar_t, char, std::mbstate_t> *
      facet(
@@ -797,12 +802,12 @@
   {
     std::locale temp(path_locale());
     path_locale() = loc;
- wchar_t_codecvt_facet() = &std::use_facet
- <std::codecvt<wchar_t, char, std::mbstate_t> >(path_locale());
+ wchar_t_codecvt_facet() =
+ &std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t> >(path_locale());
     return temp;
   }
 
 } // namespace filesystem3
 } // namespace boost
 
-#endif // no wide character support
+#endif // has wide character support


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