|
Boost Users : |
Subject: Re: [Boost-users] boost 1.39 serialization via base pointer ok on gcc, but crashes on AIX V10.1
From: Avi Bahra (avibahra_at_[hidden])
Date: 2009-07-24 04:13:49
Ok first I hadn't realised my attachment was removed. So I include the
source code below. This is small and self contained.
o The compile error on AIX was removed because I saving via a non const
variable. ( Note however gcc 4.2.1. on Linux it did not complain.)
o To recap this compiles and runs on Linux with gcc 4.2.1 but
crashes/exception on AIX V10.1. Because it reckons the derived/base
relationship has not been registered.
... oserializer.hpp
// convert pointer to more derived type. if this is thrown
// it means that the base/derived relationship hasn't be
registered
vp = serialization::void_downcast(
*true_type,
*this_type,
static_cast<const void *>(&t)
);
if(NULL == vp){
boost::serialization::throw_exception(
>>>> archive_exception(archive_exception::unregistered_cast)
);
}
Note if a save via the derived ptr, then it works.
o If I explicitly register this relationship, (see code below)
Then I get past the first exception only to get an assert.
// since true_type is valid, and this only gets made if the
// pointer oserializer object has been created, this should
never
// fail
const basic_pointer_oserializer * bpos
= archive_pointer_oserializer<Archive>::find(* true_type);
>>> assert(NULL != bpos);
if(NULL == bpos)
boost::serialization::throw_exception(
archive_exception(archive_exception::unregistered_class)
);
ar.save_pointer(vp, bpos);
o Initially I thought it was compiled without rtti on AIX.
However this was not the case. Here is compile line.
xlC -c -DDEBUG -qcpluscmt -qNOOPTimize -qnoinline -g
-qfullpath
-qfuncsect
-qeh
-qrtti
-qtemplatedepth=700
-I"../SCRATCH/src"
-I"/s1a/emos_esuite/emos_data/sms/boost_1_39_0"
-o "bin/vacpp/debug/src/TestSerialisation.o"
"src/TestSerialisation.cpp"
This is show stopper bug that I must get fixed.
Are there any more things I can try to debug this ?
Any help would be much appreciated.
//=============== the example ========================
#include <fstream>
#include <assert.h>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/export.hpp>
class RepeatBase {
public:
RepeatBase() {}
virtual ~RepeatBase() {}
virtual const std::string& name() const = 0;
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {}
};
class RepeatDerived : public RepeatBase {
public:
RepeatDerived( const std::string& name) : name_(name) {}
RepeatDerived() {}
virtual const std::string& name() const { return name_;}
private:
std::string name_;
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
// save/load base class information
ar & boost::serialization::base_object<RepeatBase>(*this);
ar & name_;
}
};
class Defs {
public:
Defs(const std::string& f) : fileName_(f), repeat_(new RepeatDerived(f))
{}
Defs() : repeat_(NULL) {}
~Defs() { delete repeat_;}
bool operator==(const Defs& rhs) const { return fileName_ ==
rhs.fileName_;}
const std::string& fileName() const { return fileName_;}
private:
std::string fileName_;
RepeatBase* repeat_;
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int /*version*/) {
ar & fileName_;
ar & repeat_;
}
};
BOOST_CLASS_EXPORT(RepeatBase);
BOOST_CLASS_EXPORT(RepeatDerived);
BOOST_SERIALIZATION_ASSUME_ABSTRACT(RepeatBase)
int main()
{
// With this explicit register, we get a bit further, but still crashes
on AIX
// boost::serialization::void_cast_register<RepeatDerived,
RepeatBase>(0,0);
const Defs saveDefs("saveFile.txt");
{
// Save the defs file
std::ofstream ofs( saveDefs.fileName().c_str() );
boost::archive::text_oarchive oa( ofs );
oa << saveDefs; //
BOMBS out here on AIX V10.1
}
{
// Restore the defs file
Defs loadDefs;
std::ifstream ifs(saveDefs.fileName().c_str());
boost::archive::text_iarchive ia(ifs);
ia >> loadDefs;
assert( saveDefs == loadDefs );
}
return 0;
}
//===============================================
Best regards,
Ta,
Avi
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net