This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb/gdb-8.0-branch] Fix compilation errors with mingw.org's MinGW runtime 3.X


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=fefc936892e3a1058a7b89fe5bb58366bf78fe74

commit fefc936892e3a1058a7b89fe5bb58366bf78fe74
Author: Eli Zaretskii <eliz@gnu.org>
Date:   Fri May 26 10:39:57 2017 +0300

    Fix compilation errors with mingw.org's MinGW runtime 3.X
    
    gdb/ChangeLog:
    
    2017-05-26  Eli Zaretskii  <eliz@gnu.org>
    
    	* cli/cli-script.c (user_args::insert_args): Call gdb::to_string.
    
    	* common/common-utils.h (REPLACE_TO_STRING) [__MINGW32__]: Define
    	to 1 if std::to_string is not available.
    	(gdb::to_string) [REPLACE_TO_STRING]: Provide a replacement
    	implementation for std::string.

Diff:
---
 gdb/ChangeLog             |  9 +++++++++
 gdb/cli/cli-script.c      |  2 +-
 gdb/common/common-utils.h | 42 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d5a6c30..f4b2e9e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,12 @@
+2017-05-26  Eli Zaretskii  <eliz@gnu.org>
+
+	* cli/cli-script.c (user_args::insert_args): Call gdb::to_string.
+
+	* common/common-utils.h (REPLACE_TO_STRING) [__MINGW32__]: Define
+	to 1 if std::to_string is not available.
+	(gdb::to_string) [REPLACE_TO_STRING]: Provide a replacement
+	implementation for std::string.
+
 2017-05-19  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
 
 	PR tui/21482
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index e0e27ef..3a2ae15 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -806,7 +806,7 @@ user_args::insert_args (const char *line) const
 
       if (p[4] == 'c')
 	{
-	  new_line += std::to_string (m_args.size ());
+	  new_line += gdb::to_string (m_args.size ());
 	  line = p + 5;
 	}
       else
diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h
index c331f0d..e3cd66e 100644
--- a/gdb/common/common-utils.h
+++ b/gdb/common/common-utils.h
@@ -22,6 +22,7 @@
 
 #include <string>
 #include <vector>
+#include <sstream>
 
 /* If possible, define FUNCTION_NAME, a macro containing the name of
    the function being defined.  Since this macro may not always be
@@ -63,6 +64,47 @@ int xsnprintf (char *str, size_t size, const char *format, ...)
 std::string string_printf (const char* fmt, ...)
   ATTRIBUTE_PRINTF (1, 2);
 
+/* Returns a string representation of VAL.  Replacement for C++11
+   std::to_string for hosts that lack it.  */
+
+namespace gdb {
+
+#define REPLACE_TO_STRING 0
+
+#ifdef __MINGW32__
+/* mingw.org's MinGW runtime before version 5.0 needs the replacement
+   below.  Tested with mingwrt-3.22.2 and mingwrt-5.0, and with
+   libstdc++ included with MinGW GCC 5.3.0.  */
+# include <_mingw.h>
+/* We test __MINGW64_VERSION_MAJOR to exclude MinGW64, which doesn't
+   need this replacement.  */
+# if !defined __MINGW64_VERSION_MAJOR && !defined _GLIBCXX_USE_C99
+#  undef REPLACE_TO_STRING
+#  define REPLACE_TO_STRING 1
+# endif
+#endif
+
+#if REPLACE_TO_STRING
+
+template <class T>
+inline std::string
+to_string (const T &val)
+{
+  std::stringstream ss;
+
+  ss << val;
+  return ss.str ();
+}
+
+#else /* !REPLACE_TO_STRING */
+
+using std::to_string;
+
+#endif
+
+#undef REPLACE_TO_STRING
+}
+
 /* Make a copy of the string at PTR with LEN characters
    (and add a null character at the end in the copy).
    Uses malloc to get the space.  Returns the address of the copy.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]