Use gdb_argv in Python

This changes one spot in the Python code to use gdb_argv.  This
removes the last cleanup from the Python layer.

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

	* python/py-param.c (compute_enum_values): Use gdb_argv.
This commit is contained in:
Tom Tromey 2017-04-30 23:03:58 -06:00
parent 773a1edcd1
commit 1c034b67a0
2 changed files with 11 additions and 17 deletions

View File

@ -1,3 +1,7 @@
2017-08-03 Tom Tromey <tom@tromey.com>
* python/py-param.c (compute_enum_values): Use gdb_argv.
2017-08-03 Tom Tromey <tom@tromey.com> 2017-08-03 Tom Tromey <tom@tromey.com>
* utils.h (struct gdb_argv_deleter): New. * utils.h (struct gdb_argv_deleter): New.

View File

@ -555,7 +555,6 @@ static int
compute_enum_values (parmpy_object *self, PyObject *enum_values) compute_enum_values (parmpy_object *self, PyObject *enum_values)
{ {
Py_ssize_t size, i; Py_ssize_t size, i;
struct cleanup *back_to;
if (! enum_values) if (! enum_values)
{ {
@ -581,36 +580,27 @@ compute_enum_values (parmpy_object *self, PyObject *enum_values)
return 0; return 0;
} }
self->enumeration = XCNEWVEC (const char *, size + 1); gdb_argv holder (XCNEWVEC (char *, size + 1));
back_to = make_cleanup (free_current_contents, &self->enumeration); char **enumeration = holder.get ();
for (i = 0; i < size; ++i) for (i = 0; i < size; ++i)
{ {
gdbpy_ref<> item (PySequence_GetItem (enum_values, i)); gdbpy_ref<> item (PySequence_GetItem (enum_values, i));
if (item == NULL) if (item == NULL)
{ return 0;
do_cleanups (back_to);
return 0;
}
if (! gdbpy_is_string (item.get ())) if (! gdbpy_is_string (item.get ()))
{ {
do_cleanups (back_to);
PyErr_SetString (PyExc_RuntimeError, PyErr_SetString (PyExc_RuntimeError,
_("The enumeration item not a string.")); _("The enumeration item not a string."));
return 0; return 0;
} }
self->enumeration[i] enumeration[i] = python_string_to_host_string (item.get ()).release ();
= python_string_to_host_string (item.get ()).release (); if (enumeration[i] == NULL)
if (self->enumeration[i] == NULL) return 0;
{
do_cleanups (back_to);
return 0;
}
make_cleanup (xfree, (char *) self->enumeration[i]);
} }
discard_cleanups (back_to); self->enumeration = const_cast<const char**> (holder.release ());
return 1; return 1;
} }