Patchwork [RFA,v3,22/23] Use gdb_argv in Python

login
register
mail settings
Submitter Tom Tromey
Date Aug. 2, 2017, 3:02 p.m.
Message ID <20170802150227.24460-23-tom@tromey.com>
Download mbox | patch
Permalink /patch/21862/
State New
Headers show

Comments

Tom Tromey - Aug. 2, 2017, 3:02 p.m.
This changes one spot in the Python code to use gdb_argv.  This
removes the last cleanup from the Python layer.

ChangeLog
2017-08-02  Tom Tromey  <tom@tromey.com>

	* python/py-param.c (compute_enum_values): Use gdb_argv.
---
 gdb/ChangeLog         |  4 ++++
 gdb/python/py-param.c | 24 +++++++-----------------
 2 files changed, 11 insertions(+), 17 deletions(-)

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ccce44c..259c37c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,9 @@ 
 2017-08-02  Tom Tromey  <tom@tromey.com>
 
+	* python/py-param.c (compute_enum_values): Use gdb_argv.
+
+2017-08-02  Tom Tromey  <tom@tromey.com>
+
 	* utils.h (struct gdb_argv_deleter): New.
 	(gdb_argv): New class.
 	* utils.c (gdb_argv::reset): New method.
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index f0d3423..455c99e 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -555,7 +555,6 @@  static int
 compute_enum_values (parmpy_object *self, PyObject *enum_values)
 {
   Py_ssize_t size, i;
-  struct cleanup *back_to;
 
   if (! enum_values)
     {
@@ -581,36 +580,27 @@  compute_enum_values (parmpy_object *self, PyObject *enum_values)
       return 0;
     }
 
-  self->enumeration = XCNEWVEC (const char *, size + 1);
-  back_to = make_cleanup (free_current_contents, &self->enumeration);
+  gdb_argv holder (XCNEWVEC (char *, size + 1));
+  char **enumeration = holder.get ();
 
   for (i = 0; i < size; ++i)
     {
       gdbpy_ref<> item (PySequence_GetItem (enum_values, i));
 
       if (item == NULL)
-	{
-	  do_cleanups (back_to);
-	  return 0;
-	}
+	return 0;
       if (! gdbpy_is_string (item.get ()))
 	{
-	  do_cleanups (back_to);
 	  PyErr_SetString (PyExc_RuntimeError,
 			   _("The enumeration item not a string."));
 	  return 0;
 	}
-      self->enumeration[i]
-	= python_string_to_host_string (item.get ()).release ();
-      if (self->enumeration[i] == NULL)
-	{
-	  do_cleanups (back_to);
-	  return 0;
-	}
-      make_cleanup (xfree, (char *) self->enumeration[i]);
+      enumeration[i] = python_string_to_host_string (item.get ()).release ();
+      if (enumeration[i] == NULL)
+	return 0;
     }
 
-  discard_cleanups (back_to);
+  self->enumeration = const_cast<const char**> (holder.release ());
   return 1;
 }