Boost logo

Boost Users :

Subject: Re: [Boost-users] [serialization] simple binary archive problem
From: William Oquendo (woquendo_at_[hidden])
Date: 2010-09-10 10:18:05


Hi,

I would like to recommend adding a
ofs.close();
inside the first block of reading before trying to reopen the argv[1] file
for reading in the second block. That rings some bells of an error I had
previously. Please try it and let us know.

Best regards / Cordialmente,

--
William Oquendo
Phd Candidate
Simulation Of Physical Systems Group
Universidad Nacional de Colombia
Linux User # 321481
*********************
Este correo puede carecer de tildes o eñes ya que el teclado no contiene
estos caracteres. Presento excusas por eso.
*********************
On Fri, Sep 10, 2010 at 2:40 AM, Paul Graphov <graphov_at_[hidden]> wrote:
> Hi,
>
> I've updated gcc to this:
>
> gcc (Ubuntu/Linaro 4.5.1-5ubuntu1) 4.5.1
>
> I've recompiled boost with it (and the test) and tried again but with no
> luck.
>
> Minimal test looks like: (but throws another exception...)
> -----------------------------------------------------------------
> #include <unistd.h>
> #include <cassert>
> #include <iostream>
> #include <fstream>
> #include <vector>
> #include <string>
>
> #include <boost/archive/binary_oarchive.hpp>
> #include <boost/archive/binary_iarchive.hpp>
> #include <boost/serialization/string.hpp>
> #include <boost/serialization/vector.hpp>
>
> int main(int argc, char **argv) {
>
>   if (argc != 2) {
>     std::cout << "Usage: ser_test <temp_filename>" << std::endl;
>     return -1;
>   }
>
>   std::vector<std::string> t1, t2;
>
>   t1.push_back("");
>
>   {
>     std::ofstream ofs;
>     ofs.exceptions(std::ofstream::badbit | std::ofstream::failbit);
>     ofs.open(argv[1], std::ios::binary);
>     boost::archive::binary_oarchive oa(ofs);
>     oa << t1;
>   }
>
>   {
>     std::ifstream ifs;
>     ifs.exceptions(std::ifstream::badbit | std::ifstream::failbit);
>     ifs.open(argv[1], std::ios::binary);
>     boost::archive::binary_iarchive ia(ifs);
>     ia >> t2;
>   }
>
>   unlink(argv[1]);
>
>   assert(t1 == t2);
> }
>
> --------------------------------------------------------------------------------
>
>
> and my gdb session looks like:
>
> [druid_at_druid-desktop tmp]$ g++ -g -O0 -Wall ser_test.cpp -o ser_test
> -lboost_serialization
> [druid_at_druid-desktop tmp]$ gdb ./ser_test
> GNU gdb (GDB) 7.2-ubuntu
> Copyright (C) 2010 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later <
> http://gnu.org/licenses/gpl.html>
> This is free software: you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
> and "show warranty" for details.
> This GDB was configured as "x86_64-linux-gnu".
> For bug reporting instructions, please see:
> <http://www.gnu.org/software/gdb/bugs/>...
> Reading symbols from /home/druid/tmp/ser_test...done.
> (gdb) run asdf
> Starting program: /home/druid/tmp/ser_test asdf
> [Thread debugging using libthread_db enabled]
> terminate called after throwing an instance of
> 'boost::archive::archive_exception'
>   what():  input stream error
>
> Program received signal SIGABRT, Aborted.
> 0x00007ffff707fba5 in raise (sig=<value optimized out>) at
> ../nptl/sysdeps/unix/sysv/linux/raise.c:64
> 64    ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
>     in ../nptl/sysdeps/unix/sysv/linux/raise.c
> (gdb) i s
> #0  0x00007ffff707fba5 in raise (sig=<value optimized out>) at
> ../nptl/sysdeps/unix/sysv/linux/raise.c:64
> #1  0x00007ffff70836b0 in abort () at abort.c:92
> #2  0x00007ffff79230cd in __gnu_cxx::__verbose_terminate_handler() () from
> /usr/lib/libstdc++.so.6
> #3  0x00007ffff79212e6 in ?? () from /usr/lib/libstdc++.so.6
> #4  0x00007ffff7921313 in std::terminate() () from /usr/lib/libstdc++.so.6
> #5  0x00007ffff792141e in __cxa_throw () from /usr/lib/libstdc++.so.6
> #6  0x00007ffff7bac53d in
> boost::archive::basic_binary_iprimitive<boost::archive::binary_iarchive,
> char, std::char_traits<char> >::load(std::basic_string<char,
> std::char_traits<char>, std::allocator<char> >&) ()
>    from /usr/lib/libboost_serialization.so.1.44.0
> #7  0x000000000040d015 in
> boost::archive::load_access::load_primitive<boost::archive::binary_iarchive,
> std::basic_string<char> > (ar=..., t=...) at
> //usr/include/boost/archive/detail/iserializer.hpp:107
> #8  0x000000000040cf2e in
> boost::archive::detail::load_non_pointer_type<boost::archive::binary_iarchive>::load_primitive::invoke<std::basic_string<char>
> > (ar=..., t=...)
>     at //usr/include/boost/archive/detail/iserializer.hpp:362
> #9  0x000000000040ce67 in
> boost::archive::detail::load_non_pointer_type<boost::archive::binary_iarchive>::invoke<std::basic_string<char>
> > (ar=..., t=...)
>     at //usr/include/boost/archive/detail/iserializer.hpp:439
> #10 0x000000000040cd7c in
> boost::archive::load<boost::archive::binary_iarchive,
> std::basic_string<char> > (ar=..., t=...) at
> //usr/include/boost/archive/detail/iserializer.hpp:592
> #11 0x000000000040cc9e in
> boost::archive::detail::common_iarchive<boost::archive::binary_iarchive>::load_override<std::basic_string<char>
> > (this=0x7fffffffe120, t=...)
>     at //usr/include/boost/archive/detail/common_iarchive.hpp:66
> #12 0x000000000040cbb9 in
> boost::archive::basic_binary_iarchive<boost::archive::binary_iarchive>::load_override<std::basic_string<char>
> > (this=0x7fffffffe120, t=..., version=0)
>     at //usr/include/boost/archive/basic_binary_iarchive.hpp:70
> #13 0x000000000040cad5 in
> boost::archive::binary_iarchive_impl<boost::archive::binary_iarchive, char,
> std::char_traits<char> >::load_override<std::basic_string<char> >
> (this=0x7fffffffe120, t=...)
>     at //usr/include/boost/archive/binary_iarchive_impl.hpp:50
> #14 0x000000000040c848 in
> boost::archive::detail::interface_iarchive<boost::archive::binary_iarchive>::operator>><std::basic_string<char>
> > (this=0x7fffffffe120, t=...)
>     at //usr/include/boost/archive/detail/interface_iarchive.hpp:60
> #15 0x000000000040c6f5 in boost::serialization::nvp<std::basic_string<char,
> std::char_traits<char>, std::allocator<char> >
> >::load<boost::archive::binary_iarchive> (this=0x7fffffffdca0, ar=...)
>     at //usr/include/boost/serialization/nvp.hpp:87
> #16 0x000000000040c586 in
> boost::serialization::access::member_load<boost::archive::binary_iarchive,
> boost::serialization::nvp<std::basic_string<char> > > (ar=..., t=...,
> file_version=0)
>     at //usr/include/boost/serialization/access.hpp:101
> #17 0x000000000040c473 in
> boost::serialization::detail::member_loader<boost::archive::binary_iarchive,
> boost::serialization::nvp<std::basic_string<char, std::char_traits<char>,
> std::allocator<char> > > >::invoke
>     (ar=..., t=..., file_version=0) at
> //usr/include/boost/serialization/split_member.hpp:54
> #18 0x000000000040c371 in
> boost::serialization::split_member<boost::archive::binary_iarchive,
> boost::serialization::nvp<std::basic_string<char> > > (ar=..., t=...,
> file_version=0)
>     at //usr/include/boost/serialization/split_member.hpp:69
> #19 0x000000000040c26f in boost::serialization::nvp<std::basic_string<char,
> std::char_traits<char>, std::allocator<char> >
> >::serialize<boost::archive::binary_iarchive> (this=0x7fffffffdca0, ar=...,
>     file_version=0) at //usr/include/boost/serialization/nvp.hpp:89
> #20 0x000000000040c16a in
> boost::serialization::access::serialize<boost::archive::binary_iarchive,
> boost::serialization::nvp<std::basic_string<char> > > (ar=..., t=...,
> file_version=0)
>     at //usr/include/boost/serialization/access.hpp:118
> #21 0x000000000040c067 in
> boost::serialization::serialize<boost::archive::binary_iarchive,
> boost::serialization::nvp<std::basic_string<char> > > (ar=..., t=...,
> file_version=0)
>     at //usr/include/boost/serialization/serialization.hpp:69
> #22 0x000000000040bf65 in
> boost::serialization::serialize_adl<boost::archive::binary_iarchive,
> boost::serialization::nvp<std::basic_string<char> > > (ar=..., t=...,
> file_version=0)
>     at //usr/include/boost/serialization/serialization.hpp:128
> #23 0x000000000040bdf3 in
> boost::archive::detail::load_non_pointer_type<boost::archive::binary_iarchive>::load_only::invoke<boost::serialization::nvp<std::basic_string<char>
> > > (ar=..., t=...)
>     at //usr/include/boost/archive/detail/iserializer.hpp:373
> #24 0x000000000040bc9f in
> boost::archive::detail::load_non_pointer_type<boost::archive::binary_iarchive>::invoke<boost::serialization::nvp<std::basic_string<char>
> > const> (ar=..., t=...)
>     at //usr/include/boost/archive/detail/iserializer.hpp:439
> #25 0x000000000040bb80 in
> boost::archive::load<boost::archive::binary_iarchive,
> boost::serialization::nvp<std::basic_string<char> > const> (ar=..., t=...)
>     at //usr/include/boost/archive/detail/iserializer.hpp:592
> #26 0x000000000040b9d4 in
> boost::archive::detail::common_iarchive<boost::archive::binary_iarchive>::load_override<boost::serialization::nvp<std::basic_string<char>
> > const> (this=0x7fffffffe120, t=...)
>     at //usr/include/boost/archive/detail/common_iarchive.hpp:66
> #27 0x000000000040b699 in
> boost::archive::basic_binary_iarchive<boost::archive::binary_iarchive>::load_override<boost::serialization::nvp<std::basic_string<char>
> > const> (this=0x7fffffffe120, t=..., version=0)
>     at //usr/include/boost/archive/basic_binary_iarchive.hpp:70
> #28 0x000000000040b183 in
> boost::archive::binary_iarchive_impl<boost::archive::binary_iarchive, char,
> std::char_traits<char>
> >::load_override<boost::serialization::nvp<std::basic_string<char> > const>
> (
>     this=0x7fffffffe120, t=...) at
> //usr/include/boost/archive/binary_iarchive_impl.hpp:50
> #29 0x000000000040aa58 in
> boost::archive::detail::interface_iarchive<boost::archive::binary_iarchive>::operator>><boost::serialization::nvp<std::basic_string<char>
> > const> (this=0x7fffffffe120, t=...)
>     at //usr/include/boost/archive/detail/interface_iarchive.hpp:60
> #30 0x000000000040a12a in
> boost::serialization::stl::archive_input_seq<boost::archive::binary_iarchive,
> std::vector<std::basic_string<char, std::char_traits<char>,
> std::allocator<char> >, std::allocator<std::basic_string<char,
> std::char_traits<char>, std::allocator<char> > > > >::operator()
> (this=0x7fffffffdd5e, ar=..., s=..., v=0, hint=...) at
> //usr/include/boost/serialization/collections_load_imp.hpp:64
> #31 0x0000000000409b32 in
> boost::serialization::stl::load_collection<boost::archive::binary_iarchive,
> std::vector<std::basic_string<char> >,
> boost::serialization::stl::archive_input_seq<boost::archive::binary_iarchive,
> std::vector<std::basic_string<char> > >,
> boost::serialization::stl::reserve_imp<std::vector<std::basic_string<char> >
> > > (ar=..., s=...) at
> //usr/include/boost/serialization/collections_load_imp.hpp:158
> #32 0x0000000000409702 in
> boost::serialization::load<boost::archive::binary_iarchive,
> std::basic_string<char>, std::allocator<std::basic_string<char> > > (ar=...,
> t=...)
>     at //usr/include/boost/serialization/vector.hpp:65
> #33 0x0000000000409437 in
> boost::serialization::load<boost::archive::binary_iarchive,
> std::basic_string<char>, std::allocator<std::basic_string<char> > > (ar=...,
> t=..., file_version=0)
>     at //usr/include/boost/serialization/vector.hpp:140
> #34 0x0000000000409077 in
> boost::serialization::free_loader<boost::archive::binary_iarchive,
> std::vector<std::basic_string<char, std::char_traits<char>,
> std::allocator<char> >, std::allocator<std::basic_string<char,
> std::char_traits<char>, std::allocator<char> > > > >::invoke (ar=..., t=...,
> file_version=0) at //usr/include/boost/serialization/split_free.hpp:58
> #35 0x0000000000408b0e in
> boost::serialization::split_free<boost::archive::binary_iarchive,
> std::vector<std::basic_string<char> > > (ar=..., t=..., file_version=0)
>     at //usr/include/boost/serialization/split_free.hpp:74
> #36 0x0000000000408801 in
> boost::serialization::serialize<boost::archive::binary_iarchive,
> std::basic_string<char>, std::allocator<std::basic_string<char> > > (ar=...,
> t=..., file_version=0)
>     at //usr/include/boost/serialization/vector.hpp:151
> #37 0x00000000004083f6 in
> boost::serialization::serialize_adl<boost::archive::binary_iarchive,
> std::vector<std::basic_string<char> > > (ar=..., t=..., file_version=0)
>     at //usr/include/boost/serialization/serialization.hpp:128
> #38 0x0000000000407eb4 in
> boost::archive::detail::iserializer<boost::archive::binary_iarchive,
> std::vector<std::basic_string<char, std::char_traits<char>,
> std::allocator<char> >, std::allocator<std::basic_string<char,
> std::char_traits<char>, std::allocator<char> > > > >::load_object_data
> (this=0x616750, ar=..., x=0x7fffffffe160, file_version=0) at
> //usr/include/boost/archive/detail/iserializer.hpp:188
> #39 0x00007ffff7ba61ac in
> boost::archive::detail::basic_iarchive::load_object(void*,
> boost::archive::detail::basic_iserializer const&) () from
> /usr/lib/libboost_serialization.so.1.44.0
> #40 0x0000000000407626 in
> boost::archive::detail::load_non_pointer_type<boost::archive::binary_iarchive>::load_standard::invoke<std::vector<std::basic_string<char>
> > > (ar=..., t=...)
>     at //usr/include/boost/archive/detail/iserializer.hpp:387
> #41 0x000000000040754f in
> boost::archive::detail::load_non_pointer_type<boost::archive::binary_iarchive>::invoke<std::vector<std::basic_string<char>
> > > (ar=..., t=...)
>     at //usr/include/boost/archive/detail/iserializer.hpp:439
> #42 0x0000000000407372 in
> boost::archive::load<boost::archive::binary_iarchive,
> std::vector<std::basic_string<char> > > (ar=..., t=...) at
> //usr/include/boost/archive/detail/iserializer.hpp:592
> #43 0x00000000004071e2 in
> boost::archive::detail::common_iarchive<boost::archive::binary_iarchive>::load_override<std::vector<std::basic_string<char>
> > > (this=0x7fffffffe120, t=...)
>     at //usr/include/boost/archive/detail/common_iarchive.hpp:66
> #44 0x0000000000406f57 in
> boost::archive::basic_binary_iarchive<boost::archive::binary_iarchive>::load_override<std::vector<std::basic_string<char>
> > > (this=0x7fffffffe120, t=..., version=0)
>     at //usr/include/boost/archive/basic_binary_iarchive.hpp:70
> #45 0x0000000000406aab in
> boost::archive::binary_iarchive_impl<boost::archive::binary_iarchive, char,
> std::char_traits<char> >::load_override<std::vector<std::basic_string<char>
> > > (this=0x7fffffffe120, t=...)
>     at //usr/include/boost/archive/binary_iarchive_impl.hpp:50
> #46 0x0000000000406446 in
> boost::archive::detail::interface_iarchive<boost::archive::binary_iarchive>::operator>><std::vector<std::basic_string<char>
> > > (this=0x7fffffffe120, t=...)
>     at //usr/include/boost/archive/detail/interface_iarchive.hpp:60
> #47 0x000000000040572c in main (argc=2, argv=0x7fffffffe6c8) at
> ser_test.cpp:37
>
> I hope this is useful.
>
> p.s. I switched to text_archive as preformance isn't critical at my
> project.
>
> Thanks.
>
> On 9 September 2010 20:21, Robert Ramey <ramey_at_[hidden]> wrote:
>
>> William Oquendo wrote:
>> > Hi,
>> >
>> >
>> > I am in Mac Os X, running g++ 4.5 and boost 1.44 . I have tested your
>> > code and it worked without problem. I would like to point out that
>> > recently I had some troubles with serialization, because I compiled
>> > boost with g++ 4.2 but I was compiling my code with g++ 4.5 (because
>> > I needed support for c++0x). Everything works again after recompiling
>> > boost with g++ 4.5.
>> >
>> >
>> > Best regards,
>> >
>> >
>> > William
>>
>> I should also mention (maybe I did already) that I had a problem
>> with the gcc 4.3.2 and gcc 4.2 shipped with Ubuntu 8.04.  I filed
>> a bug report and no one has responded so it may well be that this
>> compiler/platform has some problems.  Note that I also tested
>> your example on my MSVC system with no problems.
>>
>> Robert Ramey
>>
>>
>>
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


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