This is the mail archive of the gdb-patches@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]

[RFA 7/8] Use unique_xmalloc_ptr in execute_gdb_command


This replaces a cleanup in execute_gdb_command with an instance of
unique_xmalloc_ptr.  std::string was not used because execute_command
and execute_command_to_string don't accept a "const char *" (in fact
the reason for copying the string at all).

2016-11-28  Tom Tromey  <tom@tromey.com>

	* python/python.c (execute_gdb_command): Use unique_xmalloc_ptr.
---
 gdb/ChangeLog       | 4 ++++
 gdb/python/python.c | 8 +++-----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index cf61306..d0d2ef6 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,9 @@
 2016-11-28  Tom Tromey  <tom@tromey.com>
 
+	* python/python.c (execute_gdb_command): Use unique_xmalloc_ptr.
+
+2016-11-28  Tom Tromey  <tom@tromey.com>
+
 	* value.h (value_freer::~value_freer): Call release.
 	(value_freer::release): New method.
 	* dwarf2loc.c (dwarf2_evaluate_loc_desc_full): Use value_freer.
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 83b9805..83894a1 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -601,8 +601,7 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
   TRY
     {
       /* Copy the argument text in case the command modifies it.  */
-      char *copy = xstrdup (arg);
-      struct cleanup *cleanup = make_cleanup (xfree, copy);
+      gdb::unique_xmalloc_ptr<char> copy (xstrdup (arg));
       struct interp *interp;
 
       scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
@@ -616,10 +615,9 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
 
       prevent_dont_repeat ();
       if (to_string)
-	to_string_res = execute_command_to_string (copy, from_tty);
+	to_string_res = execute_command_to_string (copy.get (), from_tty);
       else
-	execute_command (copy, from_tty);
-      do_cleanups (cleanup);
+	execute_command (copy.get (), from_tty);
     }
   CATCH (except, RETURN_MASK_ALL)
     {
-- 
2.7.4


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