|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r62431 - in trunk/boost: archive archive/impl serialization
From: ramey_at_[hidden]
Date: 2010-06-04 16:19:28
Author: ramey
Date: 2010-06-04 16:19:27 EDT (Fri, 04 Jun 2010)
New Revision: 62431
URL: http://svn.boost.org/trac/boost/changeset/62431
Log:
Corrections in hash collections serialization
improved detection of binary archives
Text files modified:
trunk/boost/archive/basic_text_iprimitive.hpp | 1 -
trunk/boost/archive/basic_text_oprimitive.hpp | 1 -
trunk/boost/archive/impl/basic_binary_iarchive.ipp | 21 ++++++++++++++++++++-
trunk/boost/serialization/hash_collections_load_imp.hpp | 18 ++++++++++++++++--
trunk/boost/serialization/hash_collections_save_imp.hpp | 19 +++++++++++++++++--
5 files changed, 53 insertions(+), 7 deletions(-)
Modified: trunk/boost/archive/basic_text_iprimitive.hpp
==============================================================================
--- trunk/boost/archive/basic_text_iprimitive.hpp (original)
+++ trunk/boost/archive/basic_text_iprimitive.hpp 2010-06-04 16:19:27 EDT (Fri, 04 Jun 2010)
@@ -47,7 +47,6 @@
#include <boost/io/ios_state.hpp>
#include <boost/scoped_ptr.hpp>
-#include <boost/serialization/collection_size_type.hpp>
#include <boost/serialization/throw_exception.hpp>
#include <boost/archive/archive_exception.hpp>
#include <boost/archive/basic_streambuf_locale_saver.hpp>
Modified: trunk/boost/archive/basic_text_oprimitive.hpp
==============================================================================
--- trunk/boost/archive/basic_text_oprimitive.hpp (original)
+++ trunk/boost/archive/basic_text_oprimitive.hpp 2010-06-04 16:19:27 EDT (Fri, 04 Jun 2010)
@@ -29,7 +29,6 @@
#include <boost/config/no_tr1/cmath.hpp> // isnan
#include <cassert>
#include <cstddef> // size_t
-#include <boost/serialization/collection_size_type.hpp>
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
Modified: trunk/boost/archive/impl/basic_binary_iarchive.ipp
==============================================================================
--- trunk/boost/archive/impl/basic_binary_iarchive.ipp (original)
+++ trunk/boost/archive/impl/basic_binary_iarchive.ipp 2010-06-04 16:19:27 EDT (Fri, 04 Jun 2010)
@@ -16,6 +16,8 @@
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::memcpy;
+ using ::strlen;
+ using ::size_t;
}
#endif
@@ -48,7 +50,24 @@
basic_binary_iarchive<Archive>::init(){
// read signature in an archive version independent manner
std::string file_signature;
- * this->This() >> file_signature;
+ try {
+ std::size_t l;
+ this->This()->load(l);
+ if(l == std::strlen(BOOST_ARCHIVE_SIGNATURE())) {
+ // borland de-allocator fixup
+ #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
+ if(NULL != file_signature.data())
+ #endif
+ file_signature.resize(l);
+ // note breaking a rule here - could be a problem on some platform
+ if(0 < l)
+ this->This()->load_binary(&(*file_signature.begin()), l);
+ }
+ }
+ catch(archive_exception const &) { // catch stream_error archive exceptions
+ // will cause invalid_signature archive exception to be thrown below
+ file_signature = "";
+ }
if(file_signature != BOOST_ARCHIVE_SIGNATURE())
boost::serialization::throw_exception(
archive_exception(archive_exception::invalid_signature)
Modified: trunk/boost/serialization/hash_collections_load_imp.hpp
==============================================================================
--- trunk/boost/serialization/hash_collections_load_imp.hpp (original)
+++ trunk/boost/serialization/hash_collections_load_imp.hpp 2010-06-04 16:19:27 EDT (Fri, 04 Jun 2010)
@@ -42,8 +42,22 @@
ar.get_library_version()
);
// retrieve number of elements
- ar >> BOOST_SERIALIZATION_NVP(count);
- ar >> BOOST_SERIALIZATION_NVP(bucket_count);
+ if(boost::archive::library_version_type(6) != library_version){
+ ar >> BOOST_SERIALIZATION_NVP(count);
+ ar >> BOOST_SERIALIZATION_NVP(bucket_count);
+ }
+ else{
+ // note: fixup for error in version 6. collection size was
+ // changed to size_t BUT for hashed collections it was implemented
+ // as an unsigned int. This should be a problem only on win64 machines
+ // but I'll leave it for everyone just in case.
+ unsigned int c;
+ unsigned int bc;
+ ar >> BOOST_SERIALIZATION_NVP(c);
+ count = c;
+ ar >> BOOST_SERIALIZATION_NVP(bc);
+ bucket_count = bc;
+ }
if(boost::archive::library_version_type(3) < library_version){
ar >> BOOST_SERIALIZATION_NVP(item_version);
}
Modified: trunk/boost/serialization/hash_collections_save_imp.hpp
==============================================================================
--- trunk/boost/serialization/hash_collections_save_imp.hpp (original)
+++ trunk/boost/serialization/hash_collections_save_imp.hpp 2010-06-04 16:19:27 EDT (Fri, 04 Jun 2010)
@@ -41,8 +41,6 @@
const item_version_type item_version(
version<BOOST_DEDUCED_TYPENAME Container::value_type>::value
);
- ar << BOOST_SERIALIZATION_NVP(count);
- ar << BOOST_SERIALIZATION_NVP(bucket_count);
#if 0
/* should only be necessary to create archives of previous versions
@@ -51,6 +49,21 @@
boost::archive::library_version_type library_version(
ar.get_library_version()
);
+ // retrieve number of elements
+ if(boost::archive::library_version_type(6) != library_version){
+ ar << BOOST_SERIALIZATION_NVP(count);
+ ar << BOOST_SERIALIZATION_NVP(bucket_count);
+ }
+ else{
+ // note: fixup for error in version 6. collection size was
+ // changed to size_t BUT for hashed collections it was implemented
+ // as an unsigned int. This should be a problem only on win64 machines
+ // but I'll leave it for everyone just in case.
+ const unsigned int c = count;
+ const unsigned int bc = bucket_count;
+ ar << BOOST_SERIALIZATION_NVP(c);
+ ar << BOOST_SERIALIZATION_NVP(bc);
+ }
if(boost::archive::library_version_type(3) < library_version){
// record number of elements
// make sure the target type is registered so we can retrieve
@@ -58,6 +71,8 @@
ar << BOOST_SERIALIZATION_NVP(item_version);
}
#else
+ ar << BOOST_SERIALIZATION_NVP(count);
+ ar << BOOST_SERIALIZATION_NVP(bucket_count);
ar << BOOST_SERIALIZATION_NVP(item_version);
#endif
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