Subject: [Boost-bugs] [Boost C++ Libraries] #5299: Serialization throws an exception for loading binary archive on windows
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-03-13 14:31:01
#5299: Serialization throws an exception for loading binary archive on windows
-----------------------------------------------+----------------------------
Reporter: Wang Peng <wangp.thu@â¦> | Owner: ramey
Type: Bugs | Status: new
Milestone: To Be Determined | Component: serialization
Version: Boost 1.46.0 | Severity: Problem
Keywords: serialization windows binary load |
-----------------------------------------------+----------------------------
Serialization throws an exception for loading binary archive on windows.
THere is no error when using text or xml archive. No error on Ubuntu when
using binary, text or xml archive.
I have tested the cpp file on both Window XP-x86 and Window 7-x64. The
errors are the same.
A minimal and complete example is the following:
(in s11n_bug.cpp):
{{{
#include <fstream>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/nvp.hpp>
typedef std::vector<int> B;
class A;
typedef boost::shared_ptr<A> a_ptr;
typedef boost::shared_ptr<B> b_ptr;
class A{
public:
A(){}
A(b_ptr b) : b_(b){}
virtual ~A(){}
b_ptr b_;
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version){
ar & BOOST_SERIALIZATION_NVP(b_);
}
};
class DA : public A{
public:
DA(){}
DA(b_ptr b) : A(b){}
template<class Archive>
void serialize(Archive & ar, const unsigned int version){
ar & boost::serialization::make_nvp("base",
boost::serialization::base_object<A>(*this));
}
};
typedef std::vector<a_ptr> VA;
typedef boost::shared_ptr<VA> va_ptr;
typedef std::vector<va_ptr> VVA;
typedef boost::shared_ptr<VVA> vva_ptr;
template <typename Archive>
void register_types(Archive& ar){
ar.template register_type<DA>();
}
b_ptr make_b(){
return b_ptr(new B);
}
a_ptr make_a(){
return a_ptr(new DA(make_b()));
}
va_ptr make_va(){
VA va;
va.push_back(make_a());
va.push_back(make_a());
return va_ptr(new VA(va));
}
vva_ptr make_vva(){
VVA vva;
vva.push_back(make_va());
vva.push_back(make_va());
return vva_ptr(new VVA(vva));
}
int main(){
std::string filename = "tmp";
std::vector<vva_ptr> thing;
thing.push_back(make_vva());
thing.push_back(make_vva());
{
std::ofstream ofs(filename.c_str());
boost::archive::binary_oarchive oa(ofs);
register_types(oa);
oa << BOOST_SERIALIZATION_NVP(thing);
}
{
std::ifstream ifs(filename.c_str());
boost::archive::binary_iarchive ia(ifs);
register_types(ia);
ia >> BOOST_SERIALIZATION_NVP(thing);
}
return 0;
}
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/5299> 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:50:05 UTC