Re: [Serialization]: bug while serializing a std::string

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: [Serialization]: bug while serializing a std::string

RIVASSEAU Jean Noel

I am assuming you meant :

 

           std::ofstream ifs("container.mob");

boost::archive::text_oarchive ia(ofs); 

 

oa << MyObject;

ofs << std::endl;

 

and not std::ifstream ifs.

 

So if I understand well, this “patch” only adds a newline to the archive at the saving stage.

 

I tried it but it did not help in any way; in fact I cannot see how it could help, since the problem is at the point of the loading of the std::string, not at the end of the load of the whole object. What I mean here is that MyObject is, in my case, a class containing a std::vector of pointers to class containing std::strings. One of these strings is too long, which causes the crash. Maybe what you meant is appending the std::endl after the serialization of the std::string, but this is not possible since at this point I have only access to the archive, not the underlying ofstream :

 

template<class Archive>

void serialize(Archive & ar, const MyClass& m, const unsigned int version)

{          

            ar & m.a_standard_string;

}

 

I do not have access there to the underlying ofstream of the implementation. Note that here, MyObject would contain a std::vector < MyClass * >. And I am serializing directly MyObject which causes the serialization of MyClass later.

 

So, what do you mean? Have you located the bug ?

 


De : [hidden email] [mailto:[hidden email]] De la part de Robert Ramey
Envoyé : jeudi 9 février 2006 04:46
À : [hidden email]
Objet : Re: [Boost-users] [Serialization]: bug while serializing astd:string

 

Untl 1.34 comes out try the following on the output stream

 

           std::ifstream ofs("container.mob");

boost::archive::text_oarchive ia(ofs); 

 

oa << MyObject;

ofs << std::endl;

 

"RIVASSEAU Jean Noel" <[hidden email]> wrote in message <a href="news:87F60F7FA02FF749AFB02BD9FCAA6B04C87411@naserv31.nanterre.oberthurcs.com">news:87F60F7FA02FF749AFB02BD9FCAA6B04C87411@......

I have been able to test with a string stream; the bug does not occur.

 

That is, this code produces the bug:

 

            std::ifstream ifs("container.mob");

boost::archive::text_iarchive ia(ifs); 

 

ia & MyObject;

 

while the following does not:

 

            std::ifstream ifs("container.mob");

 

            std::ostringstream tmp;

           

tmp << ifs.rdbuf();

 

            std::istringstream is(tmp.str());

 

boost::archive::text_iarchive ia(is); 

 

ia & MyObject;

 

 

a)       try using a different stream buffer strstream

 

 

So do you have any clue, Robert ?? Clearly the problem has to do with buffering somewhere….

 

Jean-Noël


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [Serialization]: bug while serializing astd::string

Robert Ramey
Sorry I got mixed up with another post.
 
The main difference between strstream and other streams is that strstream doesn't do any code conversion.  This is also consistent with the idea that something in the string isn't being handled in the code conversion facet of the the stream in the expected manner.  a couple of ideas would be to investicate the code conversion facets used by the text archive.  Also look at the no_codecvt attribute on archive open.
 
Robert Ramey
 
 
"RIVASSEAU Jean Noel" <[hidden email]> wrote in message <A href="news:87F60F7FA02FF749AFB02BD9FCAA6B04CB28D4@naserv31.nanterre.oberthurcs.com">news:87F60F7FA02FF749AFB02BD9FCAA6B04CB28D4@......

I am assuming you meant :

 

           std::ofstream ifs("container.mob");

boost::archive::text_oarchive ia(ofs); 

 

oa << MyObject;

ofs << std::endl;

 

and not std::ifstream ifs.

 

So if I understand well, this “patch” only adds a newline to the archive at the saving stage.

 

I tried it but it did not help in any way; in fact I cannot see how it could help, since the problem is at the point of the loading of the std::string, not at the end of the load of the whole object. What I mean here is that MyObject is, in my case, a class containing a std::vector of pointers to class containing std::strings. One of these strings is too long, which causes the crash. Maybe what you meant is appending the std::endl after the serialization of the std::string, but this is not possible since at this point I have only access to the archive, not the underlying ofstream :

 

template<class Archive>

void serialize(Archive & ar, const MyClass& m, const unsigned int version)

{          

            ar & m.a_standard_string;

}

 

I do not have access there to the underlying ofstream of the implementation. Note that here, MyObject would contain a std::vector < MyClass * >. And I am serializing directly MyObject which causes the serialization of MyClass later.

 

So, what do you mean? Have you located the bug ?

 


De : [hidden email] [mailto:[hidden email]] De la part de Robert Ramey
Envoyé : jeudi 9 février 2006 04:46
À : [hidden email]
Objet : Re: [Boost-users] [Serialization]: bug while serializing astd:string

 

Untl 1.34 comes out try the following on the output stream

 

           std::ifstream ofs("container.mob");

boost::archive::text_oarchive ia(ofs); 

 

oa << MyObject;

ofs << std::endl;

 

"RIVASSEAU Jean Noel" <[hidden email]> wrote in message <A href="news:87F60F7FA02FF749AFB02BD9FCAA6B04C87411@naserv31.nanterre.oberthurcs.com">news:87F60F7FA02FF749AFB02BD9FCAA6B04C87411@......

I have been able to test with a string stream; the bug does not occur.

 

That is, this code produces the bug:

 

            std::ifstream ifs("container.mob");

boost::archive::text_iarchive ia(ifs); 

 

ia & MyObject;

 

while the following does not:

 

            std::ifstream ifs("container.mob");

 

            std::ostringstream tmp;

           

tmp << ifs.rdbuf();

 

            std::istringstream is(tmp.str());

 

boost::archive::text_iarchive ia(is); 

 

ia & MyObject;

 

 

a)       try using a different stream buffer – strstream

 

 

So do you have any clue, Robert ?? Clearly the problem has to do with buffering somewhere….

 

Jean-Noël


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users