Drop requirement to compile with GNU extensions

__gnu_cxx::stdio_filebuf is a GNU extension only available in certain
std libraries. It is not e.g. in libc++. In order to be able to compile
with using libc++, replace the usage of __gnu_cxx::stdio_filebuf with
standard C++ methods. In this case, reopen the temporary file with a
std::fstream and expose that stream rather than the previously exposed
std::iostream.

	* include/abg-tools-utils.h (get_stream): Change return type to
	  std::fstream
	* src/abg-corpus.cc: remove unused #include of ext/stdio_filebuf.h
	* src/abg-tools-utils (temp_file::priv): remove filebuf_ member,
	  and replace iostream_ by fstream_ with changing the shared_ptr
	  type accordingly
	  (temp_file::priv::priv): initialize fstream_ based on
	  temporary file name
	  (temp_file::priv::~priv): adjust destruction accordingly
	  (temp_file::is_good): test the fstream rather than the fd
	  (temp_file::get_stream): adjust return type to std::fstream
	  and adjust implementation based on the changes in temp_file::priv
	* src/Makefile.am: remove gnu extension from c++ standard flag
	* tests/Makefile.am: likewise

Signed-off-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
This commit is contained in:
Matthias Maennich 2019-07-05 10:10:37 +01:00 committed by Dodji Seketeli
parent bb01e648ef
commit 42cd02a9be
5 changed files with 17 additions and 21 deletions

View File

@ -129,7 +129,7 @@ typedef shared_ptr<temp_file> temp_file_sptr;
/// This is a helper file around the mkstemp API.
///
/// Once the temporary file is created, users can interact with it
/// using an iostream. They can also get the path to the newly
/// using an fstream. They can also get the path to the newly
/// created temporary file.
///
/// When the instance of @ref temp_file is destroyed, the underlying
@ -152,7 +152,7 @@ public:
const char*
get_path() const;
std::iostream&
std::fstream&
get_stream();
static temp_file_sptr

View File

@ -7,7 +7,7 @@ if ENABLE_CXX11
CXX11_SOURCES = abg-viz-common.cc \
abg-viz-dot.cc \
abg-viz-svg.cc
AM_CXXFLAGS += "-std=gnu++11"
AM_CXXFLAGS += "-std=c++11"
else
CXX11_SOURCES =
endif

View File

@ -24,7 +24,6 @@
#include <cstdio>
#include <cstring>
#include <cassert>
#include <ext/stdio_filebuf.h>
#include <stdexcept>
#include <algorithm>
#include <tr1/unordered_map>

View File

@ -42,7 +42,6 @@
#include <ctype.h>
#include <errno.h>
#include <libgen.h>
#include <ext/stdio_filebuf.h> // For __gnu_cxx::stdio_filebuf
// If fts.h is included before config.h, its indirect inclusions may
// not give us the right LFS aliases of these functions, so map them
// manually.
@ -1071,10 +1070,9 @@ convert_char_stars_to_char_star_stars(const vector<char*> &char_stars,
/// The private data of the @ref temp_file type.
struct temp_file::priv
{
char* path_template_;
int fd_;
shared_ptr<__gnu_cxx::stdio_filebuf<char> > filebuf_;
shared_ptr<std::iostream> iostream_;
char* path_template_;
int fd_;
shared_ptr<std::fstream> fstream_;
priv()
{
@ -1088,18 +1086,17 @@ struct temp_file::priv
if (fd_ == -1)
return;
using __gnu_cxx::stdio_filebuf;
filebuf_.reset(new stdio_filebuf<char>(fd_,
std::ios::in | std::ios::out));
iostream_.reset(new std::iostream(filebuf_.get()));
fstream_.reset(new std::fstream(path_template_,
std::ios::trunc
| std::ios::in
| std::ios::out));
}
~priv()
{
if (fd_ && fd_ != -1)
{
iostream_.reset();
filebuf_.reset();
fstream_.reset();
close(fd_);
remove(path_template_);
}
@ -1120,7 +1117,7 @@ temp_file::temp_file()
/// useable.
bool
temp_file::is_good() const
{return (priv_->fd_ && priv_->fd_ != -1);}
{return priv_->fstream_->good();}
/// Return the path to the temporary file.
///
@ -1135,19 +1132,19 @@ temp_file::get_path() const
return 0;
}
/// Get the iostream to the temporary file.
/// Get the fstream to the temporary file.
///
/// Note that the current process is aborted if this member function
/// is invoked on an instance of @ref temp_file that is not usable.
/// So please test that the instance is usable by invoking the
/// temp_file::is_good() member function on it first.
///
/// @return the iostream to the temporary file.
std::iostream&
/// @return the fstream to the temporary file.
std::fstream&
temp_file::get_stream()
{
ABG_ASSERT(is_good());
return *priv_->iostream_;
return *priv_->fstream_;
}
/// Create the temporary file and return it if it's usable.

View File

@ -13,7 +13,7 @@ AM_CXXFLAGS = $(VISIBILITY_FLAGS)
CXX11_TESTS =
if ENABLE_CXX11
CXX11_TESTS += runtestsvg
AM_CXXFLAGS += "-std=gnu++11"
AM_CXXFLAGS += "-std=c++11"
endif
FEDABIPKGDIFF_TEST =