Use gdbpy_ref in enumerate_args

This changes enumerate_args to use gdbpy_ref, and gets rid of many
gotos.

2017-01-10  Tom Tromey  <tom@tromey.com>

	* python/py-framefilter.c (enumerate_args): Use gdbpy_ref.
This commit is contained in:
Tom Tromey 2016-11-20 10:57:28 -07:00
parent 830a493402
commit 06fc9bf7d9
2 changed files with 25 additions and 35 deletions

View file

@ -1,3 +1,7 @@
2017-01-10 Tom Tromey <tom@tromey.com>
* python/py-framefilter.c (enumerate_args): Use gdbpy_ref.
2017-01-10 Tom Tromey <tom@tromey.com> 2017-01-10 Tom Tromey <tom@tromey.com>
* python/py-utils.c (unicode_to_encoded_string) * python/py-utils.c (unicode_to_encoded_string)

View file

@ -497,7 +497,6 @@ enumerate_args (PyObject *iter,
int print_args_field, int print_args_field,
struct frame_info *frame) struct frame_info *frame)
{ {
PyObject *item;
struct value_print_options opts; struct value_print_options opts;
get_user_print_options (&opts); get_user_print_options (&opts);
@ -517,7 +516,7 @@ enumerate_args (PyObject *iter,
CATCH (except, RETURN_MASK_ALL) CATCH (except, RETURN_MASK_ALL)
{ {
gdbpy_convert_exception (except); gdbpy_convert_exception (except);
goto error; return EXT_LANG_BT_ERROR;
} }
END_CATCH END_CATCH
@ -525,11 +524,11 @@ enumerate_args (PyObject *iter,
commas in the argument output is correct. At the end of the commas in the argument output is correct. At the end of the
loop block collect another item from the iterator, and, if it is loop block collect another item from the iterator, and, if it is
not null emit a comma. */ not null emit a comma. */
item = PyIter_Next (iter); gdbpy_ref item (PyIter_Next (iter));
if (item == NULL && PyErr_Occurred ()) if (item == NULL && PyErr_Occurred ())
goto error; return EXT_LANG_BT_ERROR;
while (item) while (item != NULL)
{ {
const struct language_defn *language; const struct language_defn *language;
gdb::unique_xmalloc_ptr<char> sym_name; gdb::unique_xmalloc_ptr<char> sym_name;
@ -538,22 +537,14 @@ enumerate_args (PyObject *iter,
struct value *val; struct value *val;
enum ext_lang_bt_status success = EXT_LANG_BT_ERROR; enum ext_lang_bt_status success = EXT_LANG_BT_ERROR;
success = extract_sym (item, &sym_name, &sym, &sym_block, &language); success = extract_sym (item.get (), &sym_name, &sym, &sym_block,
&language);
if (success == EXT_LANG_BT_ERROR) if (success == EXT_LANG_BT_ERROR)
{ return EXT_LANG_BT_ERROR;
Py_DECREF (item);
goto error;
}
success = extract_value (item, &val); success = extract_value (item.get (), &val);
if (success == EXT_LANG_BT_ERROR) if (success == EXT_LANG_BT_ERROR)
{ return EXT_LANG_BT_ERROR;
Py_DECREF (item);
goto error;
}
Py_DECREF (item);
item = NULL;
if (sym && out->is_mi_like_p () if (sym && out->is_mi_like_p ()
&& ! mi_should_print (sym, MI_PRINT_ARGS)) && ! mi_should_print (sym, MI_PRINT_ARGS))
@ -571,7 +562,7 @@ enumerate_args (PyObject *iter,
{ {
PyErr_SetString (PyExc_RuntimeError, PyErr_SetString (PyExc_RuntimeError,
_("No symbol or value provided.")); _("No symbol or value provided."));
goto error; return EXT_LANG_BT_ERROR;
} }
TRY TRY
@ -581,7 +572,7 @@ enumerate_args (PyObject *iter,
CATCH (except, RETURN_MASK_ALL) CATCH (except, RETURN_MASK_ALL)
{ {
gdbpy_convert_exception (except); gdbpy_convert_exception (except);
goto error; return EXT_LANG_BT_ERROR;
} }
END_CATCH END_CATCH
@ -599,7 +590,7 @@ enumerate_args (PyObject *iter,
{ {
xfree (arg.error); xfree (arg.error);
xfree (entryarg.error); xfree (entryarg.error);
goto error; return EXT_LANG_BT_ERROR;
} }
} }
@ -617,7 +608,7 @@ enumerate_args (PyObject *iter,
xfree (arg.error); xfree (arg.error);
xfree (entryarg.error); xfree (entryarg.error);
gdbpy_convert_exception (except); gdbpy_convert_exception (except);
goto error; return EXT_LANG_BT_ERROR;
} }
END_CATCH END_CATCH
} }
@ -626,9 +617,9 @@ enumerate_args (PyObject *iter,
args_type, print_args_field, NULL) args_type, print_args_field, NULL)
== EXT_LANG_BT_ERROR) == EXT_LANG_BT_ERROR)
{ {
xfree (arg.error); xfree (arg.error);
xfree (entryarg.error); xfree (entryarg.error);
goto error; return EXT_LANG_BT_ERROR;
} }
} }
@ -643,14 +634,14 @@ enumerate_args (PyObject *iter,
if (py_print_single_arg (out, sym_name.get (), NULL, val, &opts, if (py_print_single_arg (out, sym_name.get (), NULL, val, &opts,
args_type, print_args_field, args_type, print_args_field,
language) == EXT_LANG_BT_ERROR) language) == EXT_LANG_BT_ERROR)
goto error; return EXT_LANG_BT_ERROR;
} }
} }
/* Collect the next item from the iterator. If /* Collect the next item from the iterator. If
this is the last item, do not print the this is the last item, do not print the
comma. */ comma. */
item = PyIter_Next (iter); item.reset (PyIter_Next (iter));
if (item != NULL) if (item != NULL)
{ {
TRY TRY
@ -659,14 +650,13 @@ enumerate_args (PyObject *iter,
} }
CATCH (except, RETURN_MASK_ALL) CATCH (except, RETURN_MASK_ALL)
{ {
Py_DECREF (item);
gdbpy_convert_exception (except); gdbpy_convert_exception (except);
goto error; return EXT_LANG_BT_ERROR;
} }
END_CATCH END_CATCH
} }
else if (PyErr_Occurred ()) else if (PyErr_Occurred ())
goto error; return EXT_LANG_BT_ERROR;
TRY TRY
{ {
@ -674,17 +664,13 @@ enumerate_args (PyObject *iter,
} }
CATCH (except, RETURN_MASK_ALL) CATCH (except, RETURN_MASK_ALL)
{ {
Py_DECREF (item);
gdbpy_convert_exception (except); gdbpy_convert_exception (except);
goto error; return EXT_LANG_BT_ERROR;
} }
END_CATCH END_CATCH
} }
return EXT_LANG_BT_OK; return EXT_LANG_BT_OK;
error:
return EXT_LANG_BT_ERROR;
} }