Boost logo

Boost :

Subject: Re: [boost] [serialization] Massive failures in develop?
From: John Maddock (jz.maddock_at_[hidden])
Date: 2015-10-18 03:47:34


> This sound correct - as far as it goes.
>
> Previously, I used stream_buffer_saver - which is now not in there.
> This saved the current locale when created and restored upon
> termination of the archive. The motivation was to permit a user to
> have his ostream settings unchanged if the serization i/o was
> introduced in the middle of the stream.
>
I think this is the correct way to do things (and is what my patch does,
but I'm fine if you revert to the old way).

If you do any other thing then you introduce facet-lifetime issues as
the archive is destroyed before the iostream leaving the iostream's
locale with a dangling pointer (even making the facet lifetime global in
the serialization lib doesn't work, because if someone writes an archive
to cout, then the serialization lib is unloaded before the std lib and
cout is left with a dangling pointer again).

> This worked as advertised - accept on some gcc configurations. I
> tracked the problem (in my mind anyway) to the standard system where
> by one creates a new codecvt facet on the heap and passes it to the
> streambuffer that manages the life time of this object. I spent a lot
> of time trying to make this work but couldn't get to the bottom of it.
> Thinking about it, I built the facet into the archive class so that
> the lifetime managements issues would be resolved. In the course of
> making this work, I dropped the streambuffer_saver. My intention is
> to put that back in now that I think I've got everything else sorted out.
>
> It's sounds simple now - but the original problem I was trying solve
> only appeared when using the utf8_codecvt facet to convert strings
> with russian characters in it. Somewhere it seems there is a coupling
> that is hard to discern. But anyway, I think I've got it almost where
> I want it to be.
>
Let me know if you have a test case you want me to try and debug,

Best, John.


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