[Boost-bugs] [Boost C++ Libraries] #2271: Cannot load version 1.35.0 xml archives that contain vectors of primitive types

Subject: [Boost-bugs] [Boost C++ Libraries] #2271: Cannot load version 1.35.0 xml archives that contain vectors of primitive types
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-08-29 15:33:23


#2271: Cannot load version 1.35.0 xml archives that contain vectors of primitive
types
---------------------------------------------+------------------------------
 Reporter: Ryan Mulder <rjmyst3_at_[hidden]> | Owner: ramey
     Type: Patches | Status: new
Milestone: Boost 1.37.0 | Component: serialization
  Version: Boost 1.36.0 | Severity: Problem
 Keywords: |
---------------------------------------------+------------------------------
 Version 1.35.0 xml archives are missing the <item_version> element in
 vectors of primitive types.

 This is obviously a known issue, because version 1.36.0 includes the
 compatibility header vector_135.hpp.

 The problem is, that even when vector_135.hpp is included, it makes no
 difference because the appropriate load method is not called.

 The load method in vector.hpp that is aware of the 1.35.0 bug is this:
 {{{
 template<class Archive, class U, class Allocator>
 inline void load(
     Archive & ar,
     std::vector<U, Allocator> &t,
     const unsigned int /* file_version */,
     mpl::true_
 ){
     collection_size_type count(t.size());
     ar >> BOOST_SERIALIZATION_NVP(count);
     t.resize(count);
     unsigned int item_version=0;
     if(BOOST_SERIALIZATION_VECTOR_VERSION < ar.get_library_version())
         ar >> BOOST_SERIALIZATION_NVP(item_version);
     if (!t.empty())
       ar >> make_array(detail::get_data(t),t.size());
   }
 }}}

 It works correctly, when called.
 The problem is that the load method which dispatches to either the default
 or the optimized version chooses the wrong version for vectors of
 primitive types.

 {{{
 template<class Archive, class U, class Allocator>
 inline void load(
     Archive & ar,
     std::vector<U, Allocator> &t,
     const unsigned int file_version
 ){
         load(ar,t,file_version, BOOST_DEDUCED_TYPENAME
 use_array_optimization<Archive>::template apply<U>::type() );
 }
 }}}

 For some reason, use_array_optimization does not work with primitive
 types.

 Version 1.35.0 used boost::detail::has_default_constructor<U>() to
 dispatch.

 My patch changes the dispatching load method to this:
 {{{
 template<class Archive, class U, class Allocator>
 inline void load(
     Archive & ar,
     std::vector<U, Allocator> &t,
     const unsigned int file_version
 ){
         if(BOOST_SERIALIZATION_VECTOR_VERSION < ar.get_library_version())
         {
                 load(ar,t,file_version, BOOST_DEDUCED_TYPENAME
 use_array_optimization<Archive>::template apply<U>::type() );
         }
         else
         {
                 load(ar,t,file_version,
 boost::detail::has_default_constructor<U>() );
         }
 }
 }}}

 It works well, but I do not fully why use_array_optimization did not work
 alone.

 I used a vector< unsigned char > as a test case.

-- 
Ticket URL: <http://svn.boost.org/trac/boost/ticket/2271>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:58 UTC