[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v1] 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>
---
 include/abg-tools-utils.h |  2 +-
 src/Makefile.am           |  2 +-
 src/abg-corpus.cc         |  1 -
 src/abg-tools-utils.cc    | 23 +++++++++--------------
 tests/Makefile.am         |  2 +-
 5 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/include/abg-tools-utils.h b/include/abg-tools-utils.h
index 3eb71cb72c90..4f67491e3dbb 100644
--- a/include/abg-tools-utils.h
+++ b/include/abg-tools-utils.h
@@ -152,7 +152,7 @@ public:
   const char*
   get_path() const;
 
-  std::iostream&
+  std::fstream&
   get_stream();
 
   static temp_file_sptr
diff --git a/src/Makefile.am b/src/Makefile.am
index 9fd74e21ff9f..7c02d538c50d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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
diff --git a/src/abg-corpus.cc b/src/abg-corpus.cc
index 7d164bdcb215..0b1ebf6e18f4 100644
--- a/src/abg-corpus.cc
+++ b/src/abg-corpus.cc
@@ -24,7 +24,6 @@
 #include <cstdio>
 #include <cstring>
 #include <cassert>
-#include <ext/stdio_filebuf.h>
 #include <stdexcept>
 #include <algorithm>
 #include <tr1/unordered_map>
diff --git a/src/abg-tools-utils.cc b/src/abg-tools-utils.cc
index 1605245e0c6b..0bee0bb29865 100644
--- a/src/abg-tools-utils.cc
+++ b/src/abg-tools-utils.cc
@@ -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,15 @@ 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 +1115,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.
 ///
@@ -1143,11 +1138,11 @@ temp_file::get_path() const
 /// temp_file::is_good() member function on it first.
 ///
 /// @return the iostream to the temporary file.
-std::iostream&
+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.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 544aa1935801..2104300aed22 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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 =
-- 
2.22.0.410.gd8fdbe21b5-goog