From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 12/13] Use gdbpy_ref rather than make_cleanup_py_decref
Date: Sun, 20 Nov 2016 20:42:00 -0000 [thread overview]
Message-ID: <1479674496-14000-13-git-send-email-tom@tromey.com> (raw)
In-Reply-To: <1479674496-14000-1-git-send-email-tom@tromey.com>
This changes some spots in py-framefilter.c to use gdbpy_ref rather
than make_cleanup_py_decref or make_cleanup_py_xdecref.
2016-11-20 Tom Tromey <tom@tromey.com>
* python/py-framefilter.c (py_mi_print_variables): Use gdbpy_ref.
(py_print_locals, enumerate_locals, py_print_args): Use gdbpy_ref.
---
gdb/ChangeLog | 5 ++++
gdb/python/py-framefilter.c | 59 +++++++++++++++++++++------------------------
2 files changed, 33 insertions(+), 31 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c9671de..b974442 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2016-11-20 Tom Tromey <tom@tromey.com>
+ * python/py-framefilter.c (py_mi_print_variables): Use gdbpy_ref.
+ (py_print_locals, enumerate_locals, py_print_args): Use gdbpy_ref.
+
+2016-11-20 Tom Tromey <tom@tromey.com>
+
* python/py-framefilter.c (enumerate_args): Use gdbpy_ref.
2016-11-20 Tom Tromey <tom@tromey.com>
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index dc41790..07176cc 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -693,13 +693,12 @@ enumerate_locals (PyObject *iter,
int print_args_field,
struct frame_info *frame)
{
- PyObject *item;
struct value_print_options opts;
get_user_print_options (&opts);
opts.deref_ref = 1;
- while ((item = PyIter_Next (iter)))
+ while (true)
{
const struct language_defn *language;
gdb::unique_xmalloc_ptr<char> sym_name;
@@ -710,16 +709,21 @@ enumerate_locals (PyObject *iter,
int local_indent = 8 + (8 * indent);
struct cleanup *locals_cleanups;
- locals_cleanups = make_cleanup_py_decref (item);
+ gdbpy_ref item (PyIter_Next (iter));
+ if (item == NULL)
+ break;
+
+ locals_cleanups = make_cleanup (null_cleanup, NULL);
- 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)
{
do_cleanups (locals_cleanups);
goto error;
}
- success = extract_value (item, &val);
+ success = extract_value (item.get (), &val);
if (success == EXT_LANG_BT_ERROR)
{
do_cleanups (locals_cleanups);
@@ -827,10 +831,8 @@ enumerate_locals (PyObject *iter,
END_CATCH
}
- if (item == NULL && PyErr_Occurred ())
- goto error;
-
- return EXT_LANG_BT_OK;
+ if (!PyErr_Occurred ())
+ return EXT_LANG_BT_OK;
error:
return EXT_LANG_BT_ERROR;
@@ -846,28 +848,24 @@ py_mi_print_variables (PyObject *filter, struct ui_out *out,
struct frame_info *frame)
{
struct cleanup *old_chain;
- PyObject *args_iter;
- PyObject *locals_iter;
- args_iter = get_py_iter_from_func (filter, "frame_args");
- old_chain = make_cleanup_py_xdecref (args_iter);
+ gdbpy_ref args_iter (get_py_iter_from_func (filter, "frame_args"));
if (args_iter == NULL)
- goto error;
+ return EXT_LANG_BT_ERROR;
- locals_iter = get_py_iter_from_func (filter, "frame_locals");
+ gdbpy_ref locals_iter (get_py_iter_from_func (filter, "frame_locals"));
if (locals_iter == NULL)
- goto error;
+ return EXT_LANG_BT_ERROR;
- make_cleanup_py_decref (locals_iter);
- make_cleanup_ui_out_list_begin_end (out, "variables");
+ old_chain = make_cleanup_ui_out_list_begin_end (out, "variables");
if (args_iter != Py_None)
- if (enumerate_args (args_iter, out, args_type, 1, frame)
+ if (enumerate_args (args_iter.get (), out, args_type, 1, frame)
== EXT_LANG_BT_ERROR)
goto error;
if (locals_iter != Py_None)
- if (enumerate_locals (locals_iter, out, 1, args_type, 1, frame)
+ if (enumerate_locals (locals_iter.get (), out, 1, args_type, 1, frame)
== EXT_LANG_BT_ERROR)
goto error;
@@ -890,17 +888,16 @@ py_print_locals (PyObject *filter,
int indent,
struct frame_info *frame)
{
- PyObject *locals_iter = get_py_iter_from_func (filter,
- "frame_locals");
- struct cleanup *old_chain = make_cleanup_py_xdecref (locals_iter);
+ struct cleanup *old_chain;
+ gdbpy_ref locals_iter (get_py_iter_from_func (filter, "frame_locals"));
if (locals_iter == NULL)
- goto locals_error;
+ return EXT_LANG_BT_ERROR;
- make_cleanup_ui_out_list_begin_end (out, "locals");
+ old_chain = make_cleanup_ui_out_list_begin_end (out, "locals");
if (locals_iter != Py_None)
- if (enumerate_locals (locals_iter, out, indent, args_type,
+ if (enumerate_locals (locals_iter.get (), out, indent, args_type,
0, frame) == EXT_LANG_BT_ERROR)
goto locals_error;
@@ -923,13 +920,13 @@ py_print_args (PyObject *filter,
enum ext_lang_frame_args args_type,
struct frame_info *frame)
{
- PyObject *args_iter = get_py_iter_from_func (filter, "frame_args");
- struct cleanup *old_chain = make_cleanup_py_xdecref (args_iter);
+ struct cleanup *old_chain;
+ gdbpy_ref args_iter (get_py_iter_from_func (filter, "frame_args"));
if (args_iter == NULL)
- goto args_error;
+ return EXT_LANG_BT_ERROR;
- make_cleanup_ui_out_list_begin_end (out, "args");
+ old_chain = make_cleanup_ui_out_list_begin_end (out, "args");
TRY
{
@@ -945,7 +942,7 @@ py_print_args (PyObject *filter,
END_CATCH
if (args_iter != Py_None)
- if (enumerate_args (args_iter, out, args_type, 0, frame)
+ if (enumerate_args (args_iter.get (), out, args_type, 0, frame)
== EXT_LANG_BT_ERROR)
goto args_error;
--
2.7.4
next prev parent reply other threads:[~2016-11-20 20:42 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-20 20:42 [RFA 00/13] series #4 of c++ in python Tom Tromey
2016-11-20 20:41 ` [RFA 01/13] Use gdbpy_ref in archpy_disassemble Tom Tromey
2016-11-20 20:41 ` [RFA 06/13] Use gdbpy_ref in py-inferior.c Tom Tromey
2016-11-20 20:41 ` [RFA 05/13] Use gdbpy_ref in py_print_frame Tom Tromey
2016-11-20 20:41 ` [RFA 02/13] Use gdbpy_ref in gdbpy_breakpoint_cond_says_stop Tom Tromey
2016-11-20 20:42 ` Tom Tromey [this message]
2016-11-20 20:42 ` [RFA 09/13] Use gdbpy_ref in pyuw_object_attribute_to_pointer Tom Tromey
2016-11-20 20:42 ` [RFA 03/13] Use gdbpy_ref in py-cmd.c Tom Tromey
2016-11-21 22:46 ` Tom Tromey
2016-11-20 20:42 ` [RFA 13/13] Remove make_cleanup_py_decref and make_cleanup_py_xdecref Tom Tromey
2016-11-22 17:27 ` Pedro Alves
2016-11-20 20:42 ` [RFA 10/13] Use gdbpy_ref in py-utils.c Tom Tromey
2016-11-20 20:42 ` [RFA 04/13] Use gdbpy_ref in bpfinishpy_out_of_scope Tom Tromey
2016-11-20 20:42 ` [RFA 08/13] Use gdbpy_ref in python.c Tom Tromey
2016-11-22 17:21 ` Pedro Alves
2016-11-28 23:08 ` Tom Tromey
2016-11-20 20:42 ` [RFA 07/13] Use gdbpy_ref in py-param.c Tom Tromey
2016-11-20 20:48 ` [RFA 11/13] Use gdbpy_ref in enumerate_args Tom Tromey
2016-11-21 22:44 ` [RFA 00/13] series #4 of c++ in python Tom Tromey
2016-11-22 17:28 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1479674496-14000-13-git-send-email-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox