Boost logo

Boost :

From: Alexey Nikitin (reductor_at_[hidden])
Date: 2003-12-09 04:54:56


Robert Ramey wrote:

> Alexey Nikitin wrote:
>
> > // test array of objects
> > A a_array[10];
> > {
> > test_ostream os(testfile, TEST_STREAM_FLAGS);
> > test_oarchive oa(os);
> > oa << boost::serialization::make_nvp("a_array", a_array);
> > }
>
> >At exit from block happens access violation, because os tries to use
codecvt
> >object deleted in oa destructor.
>
> The archive classes use the locale statesaver to restore the the streams
> codecvt facet when the archive is destroyed. So I'm not sure why
> this is happening. Its odd to me that no one else has reported
> this problem. It would be interesting and helpful if you could trace
through
> the execution of the archive descructor ( and through the state saver
> destructor) and report your results.

I am trace the execution of the archive descructor and find that function
imbue in basic_filebuf "has no effect unless it is called before any I/O is
performed on the stream". Quotation from STLPort implementaton of STL. I am
send next message to STLPort forum:

------------------------------------------------------------------
STLPort-4.6 lack of correspondence to Standard (may be)
27.8.1.4
...
void imbue(const locale& loc);

17. Precondition: If the file is not positioned at its beginning and the
encoding of the current locale as determined by a_codecvt.encoding() is
state-dependendent (22.2.1.5.2) then that facet is the same as the
corresponding facet of loc.

file stl/_fstream.c:
--- line 424 ---
// Change the filebuf's locale. This member function has no effect
// unless it is called before any I/O is performed on the stream.
template <class _CharT, class _Traits>
void basic_filebuf<_CharT, _Traits>::imbue(const locale& __loc)
{
if (!_M_in_input_mode &&! _M_in_output_mode && !_M_in_error_mode) {
this->_M_setup_codecvt(__loc);
}
}
--- line 432 ---

This is lack of correspondence or the encoding always state-independendent?

Problem is appear in next code:
file boost/libs/serialization/test/test_array.cpp
--- line 55 ---
// test array of objects
A a_array;
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
test_oarchive oa(os);
oa << boost::serialization::make_nvp("a_array", a_array);
}
--- line 61 ---

Here object oa uses the locale statesaver to restore the streams codecvt
facet when archive is destroying. But in compliance with the code in
stl/_fstream.c restoring not happened and program crashed at exit from
block. It happens because os is deleted after oa and locale which created
inside oa and set up to os at oa ctor.
Here is an question: who is missed?
------------------------------------------------------------------

I would know you opinion.

Regards,
Alexey.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk