public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Replace xstrvprintf usages with string_vprintf
@ 2018-08-10 21:48 Simon Marchi
  2018-08-22 14:58 ` Simon Marchi
  0 siblings, 1 reply; 2+ messages in thread
From: Simon Marchi @ 2018-08-10 21:48 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Most usages of xstrvprintf in GDB can be replaced with string_vprintf,
removing some manual memory management.

gdb/ChangeLog:

	* guile/scm-string.c (gdbscm_scm_from_printf): Use
	string_vprintf.
	* guile/scm-utils.c (gdbscm_printf): Likewise.
	* serial.c (serial_printf): Likewise.
	* xml-support.c (gdb_xml_parser::vdebug): Likewise.
---
 gdb/guile/scm-string.c | 6 ++----
 gdb/guile/scm-utils.c  | 6 ++----
 gdb/serial.c           | 8 +++-----
 gdb/xml-support.c      | 8 +++-----
 4 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/gdb/guile/scm-string.c b/gdb/guile/scm-string.c
index 5779509..d09a54d 100644
--- a/gdb/guile/scm-string.c
+++ b/gdb/guile/scm-string.c
@@ -62,14 +62,12 @@ SCM
 gdbscm_scm_from_printf (const char *format, ...)
 {
   va_list args;
-  char *string;
   SCM result;
 
   va_start (args, format);
-  string = xstrvprintf (format, args);
+  std::string string = string_vprintf (format, args);
   va_end (args);
-  result = scm_from_latin1_string (string);
-  xfree (string);
+  result = scm_from_latin1_string (string.c_str ());
 
   return result;
 }
diff --git a/gdb/guile/scm-utils.c b/gdb/guile/scm-utils.c
index c24ff20..8f8ed64 100644
--- a/gdb/guile/scm-utils.c
+++ b/gdb/guile/scm-utils.c
@@ -79,13 +79,11 @@ void
 gdbscm_printf (SCM port, const char *format, ...)
 {
   va_list args;
-  char *string;
 
   va_start (args, format);
-  string = xstrvprintf (format, args);
+  std::string string = string_vprintf (format, args);
   va_end (args);
-  scm_puts (string, port);
-  xfree (string);
+  scm_puts (string.c_str (), port);
 }
 
 /* Utility for calling from gdb to "display" an SCM object.  */
diff --git a/gdb/serial.c b/gdb/serial.c
index 0239fc8..fb2b212 100644
--- a/gdb/serial.c
+++ b/gdb/serial.c
@@ -434,16 +434,14 @@ serial_write (struct serial *scb, const void *buf, size_t count)
 }
 
 void
-serial_printf (struct serial *desc, const char *format,...)
+serial_printf (struct serial *desc, const char *format, ...)
 {
   va_list args;
-  char *buf;
   va_start (args, format);
 
-  buf = xstrvprintf (format, args);
-  serial_write (desc, buf, strlen (buf));
+  std::string buf = string_vprintf (format, args);
+  serial_write (desc, buf.c_str (), buf.length ());
 
-  xfree (buf);
   va_end (args);
 }
 
diff --git a/gdb/xml-support.c b/gdb/xml-support.c
index 3775e2c..7c36ca3 100644
--- a/gdb/xml-support.c
+++ b/gdb/xml-support.c
@@ -179,16 +179,14 @@ void
 gdb_xml_parser::vdebug (const char *format, va_list ap)
 {
   int line = XML_GetCurrentLineNumber (m_expat_parser);
-  char *message;
 
-  message = xstrvprintf (format, ap);
+  std::string message = string_vprintf (format, ap);
   if (line)
     fprintf_unfiltered (gdb_stderr, "%s (line %d): %s\n",
-			m_name, line, message);
+			m_name, line, message.c_str ());
   else
     fprintf_unfiltered (gdb_stderr, "%s: %s\n",
-			m_name, message);
-  xfree (message);
+			m_name, message.c_str ());
 }
 
 void
-- 
2.7.4

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Replace xstrvprintf usages with string_vprintf
  2018-08-10 21:48 [PATCH] Replace xstrvprintf usages with string_vprintf Simon Marchi
@ 2018-08-22 14:58 ` Simon Marchi
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Marchi @ 2018-08-22 14:58 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

On 2018-08-10 17:48, Simon Marchi wrote:
> From: Simon Marchi <simon.marchi@polymtl.ca>
> 
> Most usages of xstrvprintf in GDB can be replaced with string_vprintf,
> removing some manual memory management.

I pushed this.

Simon

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-08-22 14:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-10 21:48 [PATCH] Replace xstrvprintf usages with string_vprintf Simon Marchi
2018-08-22 14:58 ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).