I'm using Boost v. 1.44 on Linux and gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9)
I'm trying to serialize derived class object through base class shared-pointer. After reading tons of documentation from
www.boost.org and checking all posible solutions (with macros) I turned to the simplest one which still doesn't work.
1) I register derived class with the archive by the code:
ar.register_type((PrefsMachineHash*)0); // PrefsMachineHash is a class derived from AHash class
2) I try to serialize boost::shared_ptr<AHash> object by the code:
ar & ptr; // ptr is of type: boost::shared_ptr<AHash>
After
all, the assert (oserializer.hpp:436, assert(NULL != bpos)) triggers. The stack-trace is below. What is really weird
is that on the small example everything works correctly. How is this
possible? AFTER 7 HOURS I GAVE UP. ANY HELP, please?
----
Small example that works:
namespace X {
class A {
int x;
public:
virtual ~A() { }
template<class Archive>
void serialize(Archive & ar, const unsigned int /*version*/) {
ar & x;
}
};
class B : public A {
public:
template<class Archive>
void serialize(Archive & ar, const unsigned int /*version*/) {
ar & boost::serialization::base_object<A>(*this);
}
};
}//namespace
int main() {
try {
boost::shared_ptr<X::A> ptr(new X::B);
std::ostringstream os;
Borg::SafeBinOutArchive ar(os);
ar.register_type((X::B*)0);
ar & ptr;
}
catch(std::exception& e) {
cout << "Err: " << e.what() << endl;
}
return 0;
}
----
BACK-TRACE from my project:
tuiD:
/usr/local/boost/1.44/include/boost/archive/detail/oserializer.hpp:436:
static void
boost::archive::detail::save_pointer_type<Archive>::polymorphic::save(Archive&,
T&) [with T = Borg::AHash, Archive = Borg::SafeBinOutArchive]:
Assertion `__null != bpos' failed.
Program received signal SIGABRT, Aborted.
0xb7fe2430 in __kernel_vsyscall ()
(gdb) bt
#0 0xb7fe2430 in __kernel_vsyscall ()
#1 0xb7d5d4d1 in *__GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#2 0xb7d60932 in *__GI_abort () at abort.c:92
#3
0xb7d56648 in *__GI___assert_fail (assertion=0x91e8811 "__null !=
bpos", file=0x91e8790
"/usr/local/boost/1.44/include/boost/archive/detail/oserializer.hpp",
line=436,
function=0x91eca20 "static void
boost::archive::detail::save_pointer_type<Archive>::polymorphic::save(Archive&,
T&) [with T = Borg::AHash, Archive = Borg::SafeBinOutArchive]") at
assert.c:81
#4 0x08d93165 in
boost::archive::detail::save_pointer_type<Borg::SafeBinOutArchive>::polymorphic::save<Borg::AHash>
(ar=..., t=...) at
/usr/local/boost/1.44/include/boost/archive/detail/oserializer.hpp:436
#5
0x08d92c7d in
boost::archive::detail::save_pointer_type<Borg::SafeBinOutArchive>::save<Borg::AHash>
(ar=..., t=...) at
/usr/local/boost/1.44/include/boost/archive/detail/oserializer.hpp:460
#6
0x08d92b00 in
boost::archive::detail::save_pointer_type<Borg::SafeBinOutArchive>::invoke<Borg::AHash
const*> (ar=..., t=0x95868c0) at
/usr/local/boost/1.44/include/boost/archive/detail/oserializer.hpp:473
#7
0x08d92845 in boost::archive::save<Borg::SafeBinOutArchive,
Borg::AHash const* const> (ar=..., t=@0xbfffe2bc) at
/usr/local/boost/1.44/include/boost/archive/detail/oserializer.hpp:525
#8
0x08d92794 in
boost::archive::detail::common_oarchive<Borg::SafeBinOutArchive>::save_override<Borg::AHash
const* const> (this=0xbfffe904, t=@0xbfffe2bc) at
/usr/local/boost/1.44/include/boost/archive/detail/common_oarchive.hpp:69
#9
0x08d926c7 in
boost::archive::basic_binary_oarchive<Borg::SafeBinOutArchive>::save_override<Borg::AHash
const*> (this=0xbfffe904, t=@0xbfffe2bc, version=0) at
/usr/local/boost/1.44/include/boost/archive/basic_binary_oarchive.hpp:74
#10
0x08d925fc in
boost::archive::binary_oarchive_impl<Borg::SafeBinOutArchive, char,
std::char_traits<char> >::save_override<Borg::AHash const*
const> (this=0xbfffe904, t=@0xbfffe2bc) at
/usr/local/boost/1.44/include/boost/archive/binary_oarchive_impl.hpp:51
#11
0x08d92524 in
boost::archive::detail::interface_oarchive<Borg::SafeBinOutArchive>::operator<<
<Borg::AHash const* const> (this=0xbfffe904, t=@0xbfffe2bc) at
/usr/local/boost/1.44/include/boost/archive/detail/interface_oarchive.hpp:63
#12
0x08d923bc in boost::serialization::nvp<Borg::AHash
const*>::save<Borg::SafeBinOutArchive> (this=0xbfffe2b4,
ar=...) at /usr/local/boost/1.44/include/boost/serialization/nvp.hpp:79
#13
0x08d922ef in
boost::serialization::access::member_save<Borg::SafeBinOutArchive,
boost::serialization::nvp<Borg::AHash const*> const> (ar=...,
t=..., file_version=0) at
/usr/local/boost/1.44/include/boost/serialization/access.hpp:93
#14
0x08d92229 in
boost::serialization::detail::member_saver<Borg::SafeBinOutArchive,
boost::serialization::nvp<Borg::AHash const*> >::invoke
(ar=..., t=..., file_version=0) at
/usr/local/boost/1.44/include/boost/serialization/split_member.hpp:43
#15
0x08d92163 in
boost::serialization::split_member<Borg::SafeBinOutArchive,
boost::serialization::nvp<Borg::AHash const*> > (ar=..., t=...,
file_version=0) at
/usr/local/boost/1.44/include/boost/serialization/split_member.hpp:69
#16
0x08d9209d in boost::serialization::nvp<Borg::AHash
const*>::serialize<Borg::SafeBinOutArchive> (this=0xbfffe2b4,
ar=..., file_version=0) at
/usr/local/boost/1.44/include/boost/serialization/nvp.hpp:89
#17
0x08d91fc6 in
boost::serialization::access::serialize<Borg::SafeBinOutArchive,
boost::serialization::nvp<Borg::AHash const*> > (ar=..., t=...,
file_version=0) at
/usr/local/boost/1.44/include/boost/serialization/access.hpp:118
#18
0x08d91edd in
boost::serialization::serialize<Borg::SafeBinOutArchive,
boost::serialization::nvp<Borg::AHash const*> > (ar=..., t=...,
file_version=0) at
/usr/local/boost/1.44/include/boost/serialization/serialization.hpp:70
#19
0x08d91df6 in
boost::serialization::serialize_adl<Borg::SafeBinOutArchive,
boost::serialization::nvp<Borg::AHash const*> > (ar=..., t=...,
file_version=0) at
/usr/local/boost/1.44/include/boost/serialization/serialization.hpp:129
#20
0x08d91c67 in
boost::archive::detail::save_non_pointer_type<Borg::SafeBinOutArchive>::save_only::invoke<boost::serialization::nvp<Borg::AHash
const*> > (ar=..., t=...) at
/usr/local/boost/1.44/include/boost/archive/detail/oserializer.hpp:241
#21
0x08d91b57 in
boost::archive::detail::save_non_pointer_type<Borg::SafeBinOutArchive>::invoke<boost::serialization::nvp<Borg::AHash
const*> > (ar=..., t=...) at
/usr/local/boost/1.44/include/boost/archive/detail/oserializer.hpp:308
#22
0x08d91a5d in boost::archive::save<Borg::SafeBinOutArchive,
boost::serialization::nvp<Borg::AHash const*> const> (ar=...,
t=...) at
/usr/local/boost/1.44/include/boost/archive/detail/oserializer.hpp:525
#23
0x08d9194c in
boost::archive::detail::common_oarchive<Borg::SafeBinOutArchive>::save_override<boost::serialization::nvp<Borg::AHash
const*> const> (this=0xbfffe904, t=...) at
/usr/local/boost/1.44/include/boost/archive/detail/common_oarchive.hpp:69
#24
0x08d917f1 in
boost::archive::basic_binary_oarchive<Borg::SafeBinOutArchive>::save_override<boost::serialization::nvp<Borg::AHash
const*> > (this=0xbfffe904, t=..., version=0) at
/usr/local/boost/1.44/include/boost/archive/basic_binary_oarchive.hpp:74
#25
0x08d91676 in
boost::archive::binary_oarchive_impl<Borg::SafeBinOutArchive, char,
std::char_traits<char>
>::save_override<boost::serialization::nvp<Borg::AHash
const*> const> (this=0xbfffe904, t=...)
at /usr/local/boost/1.44/include/boost/archive/binary_oarchive_impl.hpp:51
#26
0x08d91358 in
boost::archive::detail::interface_oarchive<Borg::SafeBinOutArchive>::operator<<
<boost::serialization::nvp<Borg::AHash const*> const>
(this=0xbfffe904, t=...) at
/usr/local/boost/1.44/include/boost/archive/detail/interface_oarchive.hpp:63
#27
0x08d90fcb in boost::serialization::save<Borg::SafeBinOutArchive,
Borg::AHash> (ar=..., t=...) at
/usr/local/boost/1.44/include/boost/serialization/shared_ptr.hpp:107
#28
0x08d90ddb in
boost::serialization::free_saver<Borg::SafeBinOutArchive,
boost::shared_ptr<Borg::AHash> >::invoke (ar=..., t=...,
file_version=1) at
/usr/local/boost/1.44/include/boost/serialization/split_free.hpp:45
#29
0x08d90a17 in
boost::serialization::split_free<Borg::SafeBinOutArchive,
boost::shared_ptr<Borg::AHash> > (ar=..., t=...,
file_version=1) at
/usr/local/boost/1.44/include/boost/serialization/split_free.hpp:74
#30
0x08d90890 in
boost::serialization::serialize<Borg::SafeBinOutArchive,
Borg::AHash> (ar=..., t=..., file_version=1) at
/usr/local/boost/1.44/include/boost/serialization/shared_ptr.hpp:171
#31
0x08d905c3 in
boost::serialization::serialize_adl<Borg::SafeBinOutArchive,
boost::shared_ptr<Borg::AHash> > (ar=..., t=...,
file_version=1) at
/usr/local/boost/1.44/include/boost/serialization/serialization.hpp:129
#32
0x08d90175 in
boost::archive::detail::oserializer<Borg::SafeBinOutArchive,
boost::shared_ptr<Borg::AHash> >::save_object_data
(this=0x94e6b3c, ar=..., x=0x9581a44) at
/usr/local/boost/1.44/include/boost/archive/detail/oserializer.hpp:148
#33
0x08eda0e3 in boost::archive::detail::basic_oarchive::save_object(void
const*, boost::archive::detail::basic_oserializer const&) ()
#34
0x08d8cc22 in
boost::archive::detail::save_non_pointer_type<Borg::SafeBinOutArchive>::save_standard::invoke<boost::shared_ptr<Borg::AHash>
> (ar=..., t=...) at
/usr/local/boost/1.44/include/boost/archive/detail/oserializer.hpp:253
#35
0x08d8ca0f in
boost::archive::detail::save_non_pointer_type<Borg::SafeBinOutArchive>::invoke<boost::shared_ptr<Borg::AHash>
> (ar=..., t=...) at
/usr/local/boost/1.44/include/boost/archive/detail/oserializer.hpp:308
#36
0x08d8c866 in boost::archive::save<Borg::SafeBinOutArchive,
boost::shared_ptr<Borg::AHash> const> (ar=..., t=...) at
/usr/local/boost/1.44/include/boost/archive/detail/oserializer.hpp:525
#37
0x08d8c670 in
boost::archive::detail::common_oarchive<Borg::SafeBinOutArchive>::save_override<boost::shared_ptr<Borg::AHash>
const> (this=0xbfffe904, t=...) at
/usr/local/boost/1.44/include/boost/archive/detail/common_oarchive.hpp:69
#38
0x08d8c43d in
boost::archive::basic_binary_oarchive<Borg::SafeBinOutArchive>::save_override<boost::shared_ptr<Borg::AHash>
> (this=0xbfffe904, t=..., version=0) at
/usr/local/boost/1.44/include/boost/archive/basic_binary_oarchive.hpp:74
#39
0x08d8c18c in
boost::archive::binary_oarchive_impl<Borg::SafeBinOutArchive, char,
std::char_traits<char>
>::save_override<boost::shared_ptr<Borg::AHash> const>
(this=0xbfffe904, t=...) at
/usr/local/boost/1.44/include/boost/archive/binary_oarchive_impl.hpp:51
#40
0x08d8be0e in
boost::archive::detail::interface_oarchive<Borg::SafeBinOutArchive>::operator<<
<boost::shared_ptr<Borg::AHash> const> (this=0xbfffe904,
t=...) at
/usr/local/boost/1.44/include/boost/archive/detail/interface_oarchive.hpp:63
#41
0x08d8bbc0 in
boost::archive::detail::interface_oarchive<Borg::SafeBinOutArchive>::operator&<boost::shared_ptr<Borg::AHash>
> (this=0xbfffe904, t=...) at
/usr/local/boost/1.44/include/boost/archive/detail/interface_oarchive.hpp:71
#42
0x08d8b88f in Borg::CacheItem::serialize<Borg::SafeBinOutArchive>
(this=0x9581a40, ar=..., file_version=0) at
/home/krzysiek/BORG/base/core/engine/users/new_cache.h:374
#43
0x08d8b699 in
boost::serialization::access::serialize<Borg::SafeBinOutArchive,
Borg::CacheItem> (ar=..., t=..., file_version=0) at
/usr/local/boost/1.44/include/boost/serialization/access.hpp:118
#44
0x08d8b535 in
boost::serialization::serialize<Borg::SafeBinOutArchive,
Borg::CacheItem> (ar=..., t=..., file_version=0) at
/usr/local/boost/1.44/include/boost/serialization/serialization.hpp:70
#45
0x08d8b3a6 in
boost::serialization::serialize_adl<Borg::SafeBinOutArchive,
Borg::CacheItem> (ar=..., t=..., file_version=0) at
/usr/local/boost/1.44/include/boost/serialization/serialization.hpp:129
#46
0x08d8a8db in
boost::archive::detail::oserializer<Borg::SafeBinOutArchive,
Borg::CacheItem>::save_object_data (this=0x94e6c94, ar=...,
x=0x9581a40) at
/usr/local/boost/1.44/include/boost/archive/detail/oserializer.hpp:148
#47
0x08eda0e3 in boost::archive::detail::basic_oarchive::save_object(void
const*, boost::archive::detail::basic_oserializer const&) ()
#48
0x08d87ec6 in
boost::archive::detail::save_non_pointer_type<Borg::SafeBinOutArchive>::save_standard::invoke<Borg::CacheItem>
(ar=..., t=...) at
/usr/local/boost/1.44/include/boost/archive/detail/oserializer.hpp:253
#49
0x08d87d66 in
boost::archive::detail::save_non_pointer_type<Borg::SafeBinOutArchive>::invoke<Borg::CacheItem>
(ar=..., t=...) at
/usr/local/boost/1.44/include/boost/archive/detail/oserializer.hpp:308
#50
0x08d87c42 in boost::archive::save<Borg::SafeBinOutArchive,
Borg::CacheItem const> (ar=..., t=...) at
/usr/local/boost/1.44/include/boost/archive/detail/oserializer.hpp:525
#51
0x08d87b4c in
boost::archive::detail::common_oarchive<Borg::SafeBinOutArchive>::save_override<Borg::CacheItem
const> (this=0xbfffe904, t=...) at
/usr/local/boost/1.44/include/boost/archive/detail/common_oarchive.hpp:69
#52
0x08d87901 in
boost::archive::basic_binary_oarchive<Borg::SafeBinOutArchive>::save_override<Borg::CacheItem>
(this=0xbfffe904, t=..., version=0) at
/usr/local/boost/1.44/include/boost/archive/basic_binary_oarchive.hpp:74
#53
0x08d87292 in
boost::archive::binary_oarchive_impl<Borg::SafeBinOutArchive, char,
std::char_traits<char> >::save_override<Borg::CacheItem
const> (this=0xbfffe904, t=...) at
/usr/local/boost/1.44/include/boost/archive/binary_oarchive_impl.hpp:51
#54
0x08d86bdc in
boost::archive::detail::interface_oarchive<Borg::SafeBinOutArchive>::operator<<
<Borg::CacheItem const> (this=0xbfffe904, t=...) at
/usr/local/boost/1.44/include/boost/archive/detail/interface_oarchive.hpp:63
#55
0x08d860f4 in
boost::archive::detail::interface_oarchive<Borg::SafeBinOutArchive>::operator&<Borg::CacheItem
const> (this=0xbfffe904, t=...) at
/usr/local/boost/1.44/include/boost/archive/detail/interface_oarchive.hpp:71
#56
0x08d80fa6 in Borg::CacheItem::writeTo (this=0x9581a40, ar=...) at
/home/krzysiek/BORG/base/core/engine/users/new_cache.cpp:304
#57
0x08da0200 in BdbBoxStorage::store (this=0x956ee30, p_item=...) at
/home/krzysiek/BORG/base/core/engine/users/berkeleydb/bdb_boxstorage.cpp:323
#58
0x08d84519 in Borg::Cache::write (this=0x956d038, p_hash=0xbfffed40,
type=..., data=..., human_desc=..., p_callback=..., timeout_sec=0,
p_privFSKey=0x0) at
/home/krzysiek/BORG/base/core/engine/users/new_cache.cpp:716
#59
0x0855bc3d in CPreferences::exportSaveMachinePrefs (this=0x956c9d0) at
/home/krzysiek/BORG/base/core/engine/Preferences.cpp:200
#60 0x08506bcc in GlobalData::beforeDestruct (this=0x956c830) at /home/krzysiek/BORG/base/core/engine/borg_global.cpp:131
#61 0x085b2568 in RunMainEngine (argc=1, argv=0xbffff2d4) at /home/krzysiek/BORG/base/core/engine/RunMainEngine.cpp:513
#62 0x084fcaae in main (argc=1, argv=0xbffff2d4) at /home/krzysiek/BORG/base/ui/tui/main.cpp:46