Boost logo

Boost Users :

From: Dan Leibovich (dan_at_[hidden])
Date: 2007-02-28 14:26:40


Hi,

I have added the specializations methods for short and now the serialization output is the same for both platforms (linux and solaris).

But when I try to load the dump file, the program received seg fault signal
in boost::archive::detail::basic_iarchive_impl::load_pointer()
 on: bpis_ptr->load_object_ptr(ar, t, co.file_version);

I will be happy to try any changes you suggest.

I have noticed (according to your code change suggestions) that I do not have the latest version of the lib.
I downloaded boost 1.33.1 , should I download newer version and if so how can I do it?

Thanks
 Dan Leibovich


-----Original Message-----
From: boost-users-bounces_at_[hidden] [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Robert Ramey
Sent: ד 28 פברואר 2007 18:24
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] [Serialization] issue withportable_binary_oarchive

OK - I've looked at this a little more carefully.

First - on my VC 7.1 compiler I find that the portable_binary_oarchive.hpp line #85

template<class T>
void save(const T & t){
this->primitive_base_t::save(t);
}
void save(const unsigned int t){
save_impl(t);
}
void save(const int t){
save_impl(t);
}
void save(const unsigned long t){
save_impl(t);
}
void save(const long t){
save_impl(t);
}

and the type in question is "short". It seems that on this compiler at least - and it looks like others "short" is its own type so it doesn't match any of the specializations. So I guess we should add the following:

void save(const short t){
save_impl(t);
}

void save(const unsigned short t){
save_impl(t);
}

and correspondingly for ....iarchive.hpp.

Also you might consider replacing
// default fall through for any types not specified here template<class T> void save(const T & t){
    this->primitive_base_t::save(t);
}

with
template<class T>
void save(const T & t){
    BOOST_STATIC_ASSERT( some type false here); }

void save(const unsigned char t){
        this->primitive_base_t::save(t); } ... same for all char/wchar_t types.

which would guarentee no future surprises. or that all future surprises occur sooner rather than later.


Finally, This has made me look at

basic_binary_oarchive.hpp and I'm inclined to replace

template<class T>
void save_override(T & t, BOOST_PFTO int){
this->save_override(const_cast<const T>(t), 0);
}
with

template<class T>
void save_override(const T & t, BOOST_PFTO int){
this->array_oarchive::save_override(t, 0);
}

... same for load. I'll do this on my own system but won't check it in
until
I get a chance to run some tests here. You might want to experiment with
this.

Robert Ramey


"Dan Leibovich" <dan_at_[hidden]> wrote in message
news:80726DBE398EBB4A8B77AD210C509EAA029C61F0_at_MAILEU.global.cadence.com...
Hi,
I just found this "const",
I tried it but still the program never get to the save_impl() method, hence
the output not portable.

Thanks
 Dan

p.s : I missed the initialization in the code when I copied it. It should
be: boost::archive::class_id_type const cid (100) ;



From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Robert Ramey
Sent: ã 28 ôáøåàø 2007 00:40
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] [Serialization] issue
withportable_binary_oarchive


When I make the following change it works
"Dan Leibovich" <dan_at_[hidden]> wrote in message
news:80726DBE398EBB4A8B77AD210C509EAA029C602A_at_MAILEU.global.cadence.com...
Hi Robert,

I think I found a clue.

The following simple program produce deferent binary dump on linux and
solaris.
#include "portable_binary_iarchive.hpp"
#include "portable_binary_oarchive.hpp"
#include <fstream>
int main () {
  char* file = "file" ;
  boost::archive::class_id_type const cid ; // note "const" here

  std::ofstream ofs(file) ;
  portable_binary_oarchive oar(ofs) ;
  oar << cid ;
  ofs.close();
}
The output:
linux: 65 00 00 00
solaris: 00 00 00 65

I set a break point on save_impl() in portable_binary_archive.hpp and notice
that the program never get to this method. The data is saved using the
default template method which calls to :
 boost::archive::binary_oarchive_impl<derived_t>::save(t);

Do you have any idea of how to overcome this issue.

Thank you
 Dan Leibovich




From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Robert Ramey
Sent: â 27 ôáøåàø 2007 18:15
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] [Serialization] issue
withportable_binary_oarchive


I ran your example and made it fail on my machine.

I traced this to an asymetry in the serialization of class_id_optional. I
can fix this - but
I don't think its the cause of any other problems. I changed your program
to
use class_id rather than class_id_optional and it passed fine. I also ran
it with
object_id_type and no problems. I'm not sure what to suggest now.

Robert Ramey



"Dan Leibovich" <dan_at_[hidden]> wrote in message
news:80726DBE398EBB4A8B77AD210C509EAA0291B278_at_MAILEU.global.cadence.com...
Hi,

I have tried to create tests as you described.

I assume you meant boost::archive::class_id_type
I tried it also with class_id_optional_type, class_id_reference_type,
object_id_type, object_reference_type, version_type, tracking_type . Are
there any others I should check ?

I guess I did not understand your request since almost all tests failed
(also with text archive)

For example the following simple test fails:

#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <fstream>
#include <cassert>
#include <iostream>

int main () {
  char* file = "file" ;

  boost::archive::class_id_optional_type cido ;
  boost::archive::class_id_optional_type cido_(101) ;

  std::ofstream ofs(file) ;
  boost::archive::text_oarchive oar(ofs) ;
  oar << cido_ ;
  ofs.close();

  std::ifstream ifs(file) ;
  boost::archive::text_iarchive iar(ifs) ;

  iar >> cido ;
  std::cout << cido << std::endl ;
  assert (cido_ == cido) ;
}


Could you help me understand what am I doing wrong ?

Thanks
 Dan Leibovich










From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Robert Ramey
Sent: á 26 ôáøåàø 2007 22:29
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] [Serialization] issue
withportable_binary_oarchive


Sorry, I haven't looked into it.

Looking at ...basic_binary_archive I do see that the meta data - object id,
etc
are converted to integer types so it looks like this issue was considered.
So its not a super obvious issue. I do believe that by making a small
test - serializing each of the meta data tag types, you might reveal which
one - or more - are hanging things up. Try making a small test:

boost::archive::class_id cid = 100;
ar << cid;
ar << 324;
...

boost::archive::class_id cid
ar >> cid;
assert(100 == cide);
ar >> i;
assert(i == 324);
...

That would be helpful.

Robert Ramey

"Dan Leibovich" <dan_at_[hidden]> wrote in message
news:80726DBE398EBB4A8B77AD210C509EAA0291B077_at_MAILEU.global.cadence.com...
Hi Robert,

Were you able to find some clue?

I don't think it is related to the problem but there are some compilation
warnings, do you have suggestion how to avoid it?


../boost/boost_1_33_1/boost/archive/impl/basic_binary_iarchive.ipp: In
member
   function `void boost::archive::basic_binary_iarchive<Archive>::init()
[with
   Archive = portable_binary_iarchive]':
portable_binary_iarchive.hpp:116: instantiated from here
../boost/boost_1_33_1/boost/archive/impl/basic_binary_iarchive.ipp:67:
warning: choosing
   `boost::archive::version_type::operator unsigned int&()' over `
   boost::archive::version_type::operator const unsigned int&() const'
../boost/boost_1_33_1/boost/archive/impl/basic_binary_iarchive.ipp:67:
warning:
    for conversion from `boost::archive::version_type' to `unsigned int'
../boost/boost_1_33_1/boost/archive/impl/basic_binary_iarchive.ipp:67:
warning:
    because conversion sequence for the argument is better
../boost/boost_1_33_1/boost/archive/impl/basic_binary_iarchive.ipp: In
member
   function `void boost::archive::basic_binary_iarchive<Archive>::init()
[with
   Archive = boost::archive::binary_iarchive]':
../boost/boost_1_33_1/boost/archive/binary_iarchive.hpp:51: instantiated
from `void boost::archive::binary_iarchive_impl<Archive>::init() [with
Archive = boost::archive::binary_iarchive]'
../boost/boost_1_33_1/boost/archive/binary_iarchive.hpp:66: instantiated
from
`boost::archive::binary_iarchive_impl<Archive>::binary_iarchive_impl(std::istream&,
unsigned int) [with Archive = boost::archive::binary_iarchive]'
../boost/boost_1_33_1/boost/archive/binary_iarchive.hpp:80: instantiated
from here
../boost/boost_1_33_1/boost/archive/impl/basic_binary_iarchive.ipp:67:
warning: choosing
   `boost::archive::version_type::operator unsigned int&()' over `
   boost::archive::version_type::operator const unsigned int&() const'
../boost/boost_1_33_1/boost/archive/impl/basic_binary_iarchive.ipp:67:
warning:
    for conversion from `boost::archive::version_type' to `unsigned int'
../boost/boost_1_33_1/boost/archive/impl/basic_binary_iarchive.ipp:67:
warning:
    because conversion sequence for the argument is better

Thank you
 Dan





From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Robert Ramey
Sent: ã 21 ôáøåàø 2007 21:54
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] [Serialization] issue
withportable_binary_oarchive


We'll look into it. If you get any more information, feel free to share it.

Robert Ramey

"Dan Leibovich" <dan_at_[hidden]> wrote in message
news:80726DBE398EBB4A8B77AD210C509EAA0291A579_at_MAILEU.global.cadence.com...
Hi,
I am trying to use the portable binary archive example.
I need to serialize only integers and strings.

I tried it on linux and solaris5.8. The result binary stream is not the same
and deserialization fails.

I used hex viewer and notice that the files are very similar except for some
few differences which results from endienness issues. Can it be that the
metadata is written differently on each platform.

This is happens when I serialize derived class through a pointer to base
class. (I used BOOS_CLASS_EXPORT)

Below you will find a test case. It produce differ output on linux and
solaris.

Am I missing something?

Thanks in advance
 Dan Leibovich




#include <fstream>
#include "portable_binary_oarchive.hpp"

#include <boost/serialization/base_object.hpp>
#include <boost/serialization/export.hpp>


class Base {
private:
    friend class boost::serialization::access;
    template<class Archive>
    void serialize(Archive & ar, const unsigned int version)
    {
        ar & x;
    }

protected:
    int x;

public:
  Base() {} ;
  Base(int x_) : x(x_) {} ;
  virtual void foo() {} ;
};


class Derived1 : public Base {
private:
  friend class boost::serialization::access;
  template<class Archive>
  void serialize(Archive & ar, const unsigned int version)
  {
    ar & boost::serialization::base_object<Base>(*this);
    ar & y;
  }
protected:
  int y;

public:
  Derived1() {} ;
  Derived1(int x_, int y_) : Base(x_), y(y_) {} ;
  virtual void foo() {x++;}
};

class Derived2 : public Base {
private:
  friend class boost::serialization::access;
  template<class Archive>
  void serialize(Archive & ar, const unsigned int version)
  {
    ar & boost::serialization::base_object<Base>(*this);
    ar & z;
  }
protected:
  bool z;

public:
  Derived2() {} ;
  Derived2(int x_) : Base(x_), z(true) {} ;
  virtual void foo() {x--;}
};



class Container {
  Base* b1 ;
  Base* b2 ;
  friend class boost::serialization::access;
  template<class Archive>
  void serialize(Archive & ar, const unsigned int version)
  {
    ar & b1;
    ar & b2 ;
  }
public:
  Container() {} ;
  Container(int x, int y) {
    b1 = new Derived1(x,y) ;
    b2 = new Derived2(x) ;
  }
};


BOOST_CLASS_EXPORT(Derived1) ;
BOOST_CLASS_EXPORT(Derived2) ;

int main() {
    std::ofstream ofs("filename");
    const Container c(1,2) ;
    portable_binary_oarchive oa(ofs);
    oa << c;
}




_______________________________________________
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 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 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