Serialization polymorphic iarchives & binary_object problem
Hello, All! This code: #include <fstream> #include <boost/archive/polymorphic_text_iarchive.hpp> #include <boost/archive/polymorphic_text_oarchive.hpp> #include <boost/archive/polymorphic_binary_iarchive.hpp> #include <boost/archive/polymorphic_binary_oarchive.hpp> #include <boost/serialization/binary_object.hpp> int main(int argc, char* argv[]) { { char testdata[4] = "asd"; std::ofstream os("test.txt", std::ios::binary); boost::archive::polymorphic_binary_oarchive ar(os); // boost::archive::polymorphic_text_oarchive ar(os); // boost::archive::text_oarchive ar(os); // boost::archive::binary_oarchive ar(os); ar & boost::serialization::make_binary_object(&testdata, sizeof(testdata)); assert(os.good()); } { char testdata[4] = " "; std::ifstream is("test.txt", std::ios::binary); assert(is.good()); boost::archive::polymorphic_binary_iarchive ar(is); // boost::archive::polymorphic_text_iarchive ar(is); // boost::archive::text_iarchive ar(is); // boost::archive::binary_iarchive ar(is); ar & boost::serialization::make_binary_object(&testdata, sizeof(testdata)); assert(is.good()); assert(testdata[0] == 'a'); } return 0; } does not work as expected - last assert failed. With text_iarchive/text_oarchive or binary_iarchive/binary_oarchive everything works fine. With polymorphic_text_archive another assert failed - is.good() returns false. I'm using VC 7.1 compiler. I had trying to compile this code with Intel 8.1 compiler but got errors, identical for polymorphic binary and text archives : Compiling with Intel(R) C++ 8.1 ...(Intel C++ Environment) TestPolyArchives.cpp C:\boost_1_32_0\boost/serialization/binary_object.hpp(43): error #308: function "boost::archive::polymorphic_oarchive::save_binary" is inaccessible ar.save_binary(m_t, m_size); ^ detected during: instantiation of "void boost::serialization::binary_object::save(Archive &, const unsigned int) const [with Archive=boost::archive::polymorphic_oarchive]" at line 90 of "C:\boost_1_32_0\boost/serialization/access.hpp" instantiation of "void boost::serialization::access::member_save(Archive &, const T &, const unsigned int) [with Archive=boost::archive::polymorphic_oarchive, T=boost::serialization::binary_object]" at line 42 of "C:\boost_1_32_0\boost/serialization/split_member.hpp" instantiation of "void boost::serialization::detail::member_saver<Archive, T>::invoke(Archive &, const T &, const unsigned int) [with Archive=boost::archive::polymorphic_oarchive, T=boost::serialization::binary_object]" at line 63 of "C:\boost_1_32_0\boost/serialization/split_member.hpp" instantiation of "void boost::serialization::split_member(Archive &, T &, const unsigned int) [with Archive=boost::archive::polymorphic_oarchive, T=boost::serialization::binary_object]" at line 49 instantiation of "void boost::serialization::binary_object::serialize(Archive &, const unsigned int) [with Archive=boost::archive::polymorphic_oarchive]" at line 106 of "C:\boost_1_32_0\boost/serialization/access.hpp" [ 4 instantiation contexts not shown ] instantiation of "void boost::archive::detail::save_non_pointer_type<Archive, T>::invoke(Archive &, const T &) [with Archive=boost::archive::polymorphic_oarchive, T=boost::serialization::binary_object]" at line 551 of "C:\boost_1_32_0\boost/archive/detail/oserializer.hpp" instantiation of "void boost::archive::save(Archive &, const T &) [with Archive=boost::archive::polymorphic_oarchive, T=boost::serialization::binary_object]" at line 106 of "C:\boost_1_32_0\boost/archive/polymorphic_oarchive.hpp" instantiation of "void boost::archive::polymorphic_oarchive::save_override(const T &, int) [with T=boost::serialization::binary_object]" at line 87 of "C:\boost_1_32_0\boost/archive/detail/interface_oarchive.hpp" instantiation of "Archive &boost::archive::detail::interface_oarchive<Archive>::operator&(const T &) [with Archive=boost::archive::polymorphic_oarchive, T=boost::serialization::binary_object]" at line 159 of "C:\boost_1_32_0\boost/archive/detail/polymorphic_oarchive_impl.hpp" instantiation of "boost::archive::polymorphic_oarchive &boost::archive::detail::polymorphic_oarchive_impl<ArchiveImplementation>::operator&(const T &) [with ArchiveImplementation=boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive>, T=boost::serialization::binary_object]" C:\boost_1_32_0\boost/serialization/binary_object.hpp(47): error #308: function "boost::archive::polymorphic_iarchive::load_binary" is inaccessible ar.load_binary(const_cast<void *>(m_t), m_size); ^ detected during: instantiation of "void boost::serialization::binary_object::load(Archive &, const unsigned int) [with Archive=boost::archive::polymorphic_iarchive]" at line 98 of "C:\boost_1_32_0\boost/serialization/access.hpp" instantiation of "void boost::serialization::access::member_load(Archive &, T &, const unsigned int) [with Archive=boost::archive::polymorphic_iarchive, T=boost::serialization::binary_object]" at line 53 of "C:\boost_1_32_0\boost/serialization/split_member.hpp" instantiation of "void boost::serialization::detail::member_loader<Archive, T>::invoke(Archive &, T &, const unsigned int) [with Archive=boost::archive::polymorphic_iarchive, T=boost::serialization::binary_object]" at line 63 of "C:\boost_1_32_0\boost/serialization/split_member.hpp" instantiation of "void boost::serialization::split_member(Archive &, T &, const unsigned int) [with Archive=boost::archive::polymorphic_iarchive, T=boost::serialization::binary_object]" at line 49 instantiation of "void boost::serialization::binary_object::serialize(Archive &, const unsigned int) [with Archive=boost::archive::polymorphic_iarchive]" at line 106 of "C:\boost_1_32_0\boost/serialization/access.hpp" [ 5 instantiation contexts not shown ] instantiation of "void boost::archive::load(Archive &, T &) [with Archive=boost::archive::polymorphic_iarchive, T=boost::serialization::binary_object]" at line 107 of "C:\boost_1_32_0\boost/archive/polymorphic_iarchive.hpp" instantiation of "void boost::archive::polymorphic_iarchive::load_override(T &, int) [with T=boost::serialization::binary_object]" at line 105 of "C:\boost_1_32_0\boost/archive/detail/interface_iarchive.hpp" instantiation of "Archive &boost::archive::detail::interface_iarchive<Archive>::operator>>(const T &) [with Archive=boost::archive::polymorphic_iarchive, T=boost::serialization::binary_object]" at line 111 of "C:\boost_1_32_0\boost/archive/detail/interface_iarchive.hpp" instantiation of "Archive &boost::archive::detail::interface_iarchive<Archive>::operator&(const T &) [with Archive=boost::archive::polymorphic_iarchive, T=boost::serialization::binary_object]" at line 182 of "C:\boost_1_32_0\boost/archive/detail/polymorphic_iarchive_impl.hpp" instantiation of "boost::archive::polymorphic_iarchive &boost::archive::detail::polymorphic_iarchive_impl<ArchiveImplementation>::operator&(const T &) [with ArchiveImplementation=boost::archive::binary_iarchive_impl<boost::archive::binary_iarchive>, T=boost::serialization::binary_object]" compilation aborted for .\TestPolyArchives.cpp (code 2) With best regards, Sergey.
Sergey Skorniakov wrote:
I had trying to compile this code with Intel 8.1 compiler but got errors, identical for polymorphic binary and text archives :
looks like you found a bug !. Fixed in next version. Meanwhile make save_binary and load_binary public in polymorphic_?archi ve.hpp. I'm still looking into the other question Robert Ramey
Hello, Robert! You wrote on Tue, 11 Jan 2005 08:13:55 -0800: RR> I'm still looking into the other question Are you talking about memento archive? Sorry, Robert, I forgot this idea for a while. I had big problems with scalability of my RPC - very long compile time with Intel 8.1 and C1204 error with VC. I had found that the most hard to compile code is the MPL-based handling of polymorphic types and have migrates some parts of my code from serialization library to very simplified ersatz, using your library mostly for parameters marshalling and serializing function wrappers and other helper class in non-polymorphic manner. Thus, I had imlemented almost all of the desired functionality without memento archive (however, passing pointers to non-const polymorphic classes still requires useless assignment). Also, I had found that in some situations it is more convenient to use custom-defined replacement of BOOST_CLASS_EXPORT instead of relying on including nesessary and only nesessary archives headers. May be, you will provide some macro to disable BOOST_STATIC_WARNING in iserializer.hpp, line 405 and in oserializer.hpp, line 385 for VC (I see that there are no warnings for other compilers)? In addition, among removing warnings this will slightly decrease the chances to got C1204 error. With best regards, Sergey.
participants (2)
-
Robert Ramey
-
Sergey Skorniakov