[iostreams] Hang when constructing an xml_iarchive with non-existent source

I have a function that uses a chain of filters that I am using to read encrypted, bzipped data from file. It is working fine. However, I have just discovered that if I call my function with a file that does not exist, the code hangs in the constructor for xml_iarchive. Of course, I have since edited my code to trap non-existent files before the code gets that far, but I am surprised that: * is_complete() returns true when the source is a non-existent file * the constructor for xml_iarchive hangs when it is given a stream that has a non-existent file as its source Is this correct behaviour or a bug? Of course, it is the programmer's responsibility to ensure the source exists, but a hang rather than an exception seems suggests to me that something has been overlooked in the library. The (edited) function exhibiting this behaviour is given below. I am using gcc 3.2.3 and Boost 1.33.1. Paul void load(const std::string& filename) { //my revised tests "filename" here and bails out if the file does not exist try { boost::iostreams::filtering_istream in; in.push(boost::iostreams::bzip2_decompressor()); in.push(MyInputEncryptionFilter()); in.push(boost::iostreams::bzip2_decompressor()); in.push(boost::iostreams::file_source(filename, BOOST_IOS::in | BOOST_IOS::binary)); if (!in.is_complete()) { std::cerr << "Error creating filtering input stream" << std::endl; return; } boost::archive::xml_iarchive input_archive(in); //deserialise file here return; } //various catches removed }

Paul Giaccone wrote:
* is_complete() returns true when the source is a non-existent file * the constructor for xml_iarchive hangs when it is given a stream that has a non-existent file as its source
Is this correct behaviour or a bug? Of course, it is the programmer's responsibility to ensure the source exists, but a hang rather than an exception seems suggests to me that something has been overlooked in the library.
without more information its hard to know. inside of what function is it hanging? Robert Ramey

Robert Ramey wrote:
Paul Giaccone wrote:
* is_complete() returns true when the source is a non-existent file * the constructor for xml_iarchive hangs when it is given a stream that has a non-existent file as its source
Is this correct behaviour or a bug?
without more information its hard to know. inside of what function is it hanging?
The hang is on this line:
boost::archive::xml_iarchive input_archive(in); //HANGS
The attached complete program, based on the code I posted originally,
hangs in the same place in Windows (Visual C++ .NET 7.1.3088). I
haven't tested it in Linux (gcc 3.2.3) but the program I was running
when I encountered the problem hung in the same place and is more or
less the same as the one attached.
Note that the attached program deliberately does not check for the
existence of the file in order to enforce the observed behaviour.
Additional info (although this might not be relevant):
Compiler flags:
/Od /I "W:\boost\boost_1_33_1\include" /D "WIN32" /D "_DEBUG" /D
"_CONSOLE" /D "_MBCS" /Gm /EHsc /RTC1 /MDd /Fo"Debug/"
/Fd"Debug/vc70.pdb" /W4 /nologo /c /Wp64 /ZI /TP
Link flags:
/OUT:"Debug/IostreamsTest.exe" /INCREMENTAL /NOLOGO
/LIBPATH:"W:\boost\boost_1_33_1\lib" /DEBUG
/PDB:"Debug/IostreamsTest.pdb" /SUBSYSTEM:CONSOLE /MACHINE:X86
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib
shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
Paul
#include <iostream>
#include

I wonder if this is bzip-related. If you comment out the bzip line, the program throws an exception: Exception thrown: First-chance exception at 0x7c59bbf3 in IostreamsTest.exe: Microsoft C++ exception: boost::archive::xml_archive_exception @ 0x0012fad0. Breaks at: this->restore() in: ios_flags_saver::~ios_flags_saver() Call stack: KERNEL32.DLL!7c59bbf3() KERNEL32.DLL!7c59bbf3()
IostreamsTest.exe!boost::io::ios_flags_saver::~ios_flags_saver() Line 44 + 0xf C++
IostreamsTest.exe!boost::archive::basic_xml_grammar<char>::my_parse(std::basic_istream & is={...}, const
boost::spirit::rule Paul Giaccone wrote: Robert Ramey wrote: Paul Giaccone wrote: * is_complete() returns true when the source is a non-existent file
* the constructor for xml_iarchive hangs when it is given a stream
that has a non-existent file as its source Is this correct behaviour or a bug?
participants (2)
-
Paul Giaccone
-
Robert Ramey