[serialization] all wide tests were failing because...

Robert, if you recall, all wide archive tests were failing for me. They still failed with #18, and now I finally (after quite some debugging) know why. The error I was getting was: Exception in "call_test_main": std::length_error: basic_string::reserve It occured even on test_vector, which is fairly simple. The generated data contained this: 22 boost::serialization .... note that this was for wide archive, where the data should have being in UCS-4 encoding, i.e. ('2' <zero> <zero> <zero> '2' ...) The reason, once found, is simple: { test_ostream os(testfile, TEST_STREAM_FLAGS); test_oarchive oa(os); } You change codecvt in archive constructors and the archive also has locale saver. The destructor for archive is called *before* destructor for 'os'. At this time, codecvt is switched back, right? So, when destructor of 'os' calls 'close' which flushes the data, you're using default codecvt. If I add explicit 'os.close()' after writing to archive, the written data is correct. What this means is that destructor of archive *really should* call 'flush' on the stream. After I've made basic_text_oprimitive's destructor to flush stream: template<class OStream> basic_text_oprimitive<OStream>::~basic_text_oprimitive(){ os.flush(); } The test_vector passed with wide stream. I'm rerunning other tests now. In fact, I'm getting suspicious about changing codecvt at all. I suppose that if somebody is using wide streams, he already deals with encoding somehow, so why serialization library should try to second-guess the user? - Volodya
participants (1)
-
Vladimir Prus