[iostreams] Problems using filtering_stream and code_converter

Hi, I'm using boost 1.33.0 on windows (VC++6). I would like to use a code_converter to convert internal std::wstring's (which I understand are ucs2 in windows/vstudio, but that shouldn't matter here I guess) to utf-8 when saving to file. Here is the failing code: <code> void main() { typedef boost::iostreams::code_converter<boost::iostreams::file_sink, WideCharToUtf8Cvt> my_sink; std::wstring teststr(L"Blah blah."); boost::iostreams::filtering_wostream out; boost::iostreams::file_sink myFile("out.txt"); out.push(my_sink(myFile)); out << teststr; } </code> WideCharToUtf8Cvt is my own codecvt implementation. The problem is that I get a crash as the stream is being destroyed. The call stack is too deep to include here, but one of the last things are: policy_type& dev() { return **dev_; } in boost.iostreams.detail.code_converter_impl which calls boost::iostreams::detail::optional<boost::iostreams::detail::concept_adapter<boost::iostreams::basic_file_sink<char>
::operator*()
operator*() asserts on initialized_ which is false in this case. I've tried both with vc++6 sp5 and vc++ 7.1 with the same results. Also, there is no difference if I use this typedef for my_sink: typedef boost::iostreams::code_converter<boost::iostreams::file_sink> my_sink; so I don't think my codecvt implementation is to blame... The file out.txt actually gets filled with the expected data. Am I going about this the completely wrong way or am I just missing some important detail? Any help would be greatly appreciated, Niklas Wiberg

Niklas Wiberg wrote:
Hi, I'm using boost 1.33.0 on windows (VC++6). I would like to use a code_converter to convert internal std::wstring's (which I understand are ucs2 in windows/vstudio, but that shouldn't matter here I guess) to utf-8 when saving to file. Here is the failing code:
The problem is that I get a crash as the stream is being destroyed. The call stack is too deep to include here, but one of the last things are: policy_type& dev() { return **dev_; } in boost.iostreams.detail.code_converter_impl which calls
Am I going about this the completely wrong way or am I just missing some important detail?
It sounds like a bug in Iostreams; I'll look into it.
Any help would be greatly appreciated, Niklas Wiberg
-- Jonathan Turkanis www.kangaroologic.com

Niklas Wiberg wrote:
Hi,
Here is the failing code: <code> void main() { typedef boost::iostreams::code_converter<boost::iostreams::file_sink, WideCharToUtf8Cvt> my_sink;
std::wstring teststr(L"Blah blah."); boost::iostreams::filtering_wostream out; boost::iostreams::file_sink myFile("out.txt"); out.push(my_sink(myFile)); out << teststr; } </code>
There's a bug in boost/iostreams/chain.hpp which can be fixed as follows. The fix will appear in 1.33.1. Thanks for bringing the problem to my attention. *** chain.hpp 9 Sep 2005 18:08:40 -0000 1.14.2.4 --- chain.hpp 11 Oct 2005 16:40:24 -0000 *************** *** 566,572 **** pimpl_->close(); streambuf_type* buf = 0; std::swap(buf, list().back()); ! buf->set_auto_close(auto_close()); buf->set_next(0); delete buf; list().pop_back(); --- 566,572 ---- pimpl_->close(); streambuf_type* buf = 0; std::swap(buf, list().back()); ! buf->set_auto_close(false); buf->set_next(0); delete buf; list().pop_back(); -- Jonathan Turkanis www.kangaroologic.com
participants (2)
-
Jonathan Turkanis
-
Niklas Wiberg