From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 13/20] Use gdbpy_enter in py-prettyprint.c
Date: Thu, 10 Nov 2016 22:20:00 -0000 [thread overview]
Message-ID: <1478816387-27064-14-git-send-email-tom@tromey.com> (raw)
In-Reply-To: <1478816387-27064-1-git-send-email-tom@tromey.com>
Change py-prettyprint.c to use gdbpy_enter.
2016-11-10 Tom Tromey <tom@tromey.com>
* python/py-prettyprint.c (gdbpy_apply_val_pretty_printer): Use
gdbpy_enter, gdbpy_reference, unique_xmalloc_ptr.
---
gdb/ChangeLog | 5 +++++
gdb/python/py-prettyprint.c | 45 +++++++++++++++------------------------------
2 files changed, 20 insertions(+), 30 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 80d4329..a8237a8 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2016-11-10 Tom Tromey <tom@tromey.com>
+ * python/py-prettyprint.c (gdbpy_apply_val_pretty_printer): Use
+ gdbpy_enter, gdbpy_reference, unique_xmalloc_ptr.
+
+2016-11-10 Tom Tromey <tom@tromey.com>
+
* utils.h (htab_deleter): New struct.
(htab_up): New typedef.
* python/py-framefilter.c (gdbpy_apply_frame_filter): Use
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index 58f43e7..d2ef920 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -684,12 +684,7 @@ gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang,
const struct language_defn *language)
{
struct gdbarch *gdbarch = get_type_arch (type);
- PyObject *printer = NULL;
- PyObject *val_obj = NULL;
struct value *value;
- gdb::unique_xmalloc_ptr<char> hint;
- struct cleanup *cleanups;
- enum ext_lang_rc result = EXT_LANG_RC_NOP;
enum string_repr_result print_result;
/* No pretty-printer support for unavailable values. */
@@ -699,7 +694,7 @@ gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang,
if (!gdb_python_initialized)
return EXT_LANG_RC_NOP;
- cleanups = ensure_python_env (gdbarch, language);
+ gdbpy_enter enter_py (gdbarch, language);
/* Instantiate the printer. */
if (valaddr)
@@ -715,47 +710,37 @@ gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang,
&& VALUE_LVAL (value) != lval_computed)
set_value_address (value, address + embedded_offset);
- val_obj = value_to_value_object (value);
- if (! val_obj)
+ gdbpy_reference val_obj (value_to_value_object (value));
+ if (val_obj == NULL)
{
- result = EXT_LANG_RC_ERROR;
- goto done;
+ print_stack_unless_memory_error (stream);
+ return EXT_LANG_RC_ERROR;
}
/* Find the constructor. */
- printer = find_pretty_printer (val_obj);
- Py_DECREF (val_obj);
-
+ gdbpy_reference printer (find_pretty_printer (val_obj.get ()));
if (printer == NULL)
{
- result = EXT_LANG_RC_ERROR;
- goto done;
+ print_stack_unless_memory_error (stream);
+ return EXT_LANG_RC_ERROR;
}
- make_cleanup_py_decref (printer);
if (printer == Py_None)
- {
- result = EXT_LANG_RC_NOP;
- goto done;
- }
+ return EXT_LANG_RC_NOP;
/* If we are printing a map, we want some special formatting. */
- hint = gdbpy_get_display_hint (printer);
+ gdb::unique_xmalloc_ptr<char> hint (gdbpy_get_display_hint (printer.get ()));
/* Print the section */
- print_result = print_string_repr (printer, hint.get (), stream, recurse,
- options, language, gdbarch);
+ print_result = print_string_repr (printer.get (), hint.get (), stream,
+ recurse, options, language, gdbarch);
if (print_result != string_repr_error)
- print_children (printer, hint.get (), stream, recurse, options, language,
- print_result == string_repr_none);
+ print_children (printer.get (), hint.get (), stream, recurse, options,
+ language, print_result == string_repr_none);
- result = EXT_LANG_RC_OK;
-
- done:
if (PyErr_Occurred ())
print_stack_unless_memory_error (stream);
- do_cleanups (cleanups);
- return result;
+ return EXT_LANG_RC_OK;
}
--
2.7.4
next prev parent reply other threads:[~2016-11-10 22:20 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-10 22:20 [RFA 00/20] more use of C++ in the Python layer Tom Tromey
2016-11-10 22:20 ` [RFA 04/20] Use gdbpy_enter in py-finishbreakpoint.c Tom Tromey
2016-11-10 22:20 ` [RFA 15/20] Use gdbpy_enter in python_interactive_command Tom Tromey
2016-11-10 22:20 ` [RFA 07/20] Use gdbpy_enter in py-progspace.c Tom Tromey
2016-11-10 22:20 ` [RFA 08/20] Use gdbpy_enter in python.c Tom Tromey
2016-11-10 22:20 ` [RFA 01/20] Introduce gdbpy_enter Tom Tromey
2016-11-10 23:19 ` Pedro Alves
2016-11-10 22:20 ` [RFA 14/20] Use gdbpy_enter in gdbpy_before_prompt_hook Tom Tromey
2016-11-10 23:19 ` Pedro Alves
2016-11-12 17:04 ` Tom Tromey
2016-11-10 22:20 ` [RFA 05/20] Use gdbpy_enter in py-inferior.c Tom Tromey
2016-11-10 22:20 ` [RFA 02/20] Use gdbpy_enter in py-breakpoint.c Tom Tromey
2016-11-10 22:20 ` [RFA 06/20] Use gdbpy_enter in py-objfile.c Tom Tromey
2016-11-10 22:20 ` Tom Tromey [this message]
2016-11-10 22:20 ` [RFA 11/20] Use gdbpy_enter in py-unwind.c Tom Tromey
2016-11-10 22:20 ` [RFA 16/20] Use gdbpy_enter in gdbpy_get_matching_xmethod_workers Tom Tromey
2016-11-10 23:19 ` Pedro Alves
2016-11-11 3:19 ` Tom Tromey
2016-11-11 3:24 ` Pedro Alves
2016-11-12 17:09 ` Tom Tromey
2016-11-10 22:20 ` [RFA 09/20] Use gdbpy_enter in py-type.c Tom Tromey
2016-11-10 22:20 ` [RFA 17/20] Use gdbpy_reference in invoke_match_method Tom Tromey
2016-11-10 22:20 ` [RFA 10/20] Use gdbpy_enter in py-xmethods.c Tom Tromey
2016-11-10 22:20 ` [RFA 03/20] Use gdbpy_enter in py-cmd.c Tom Tromey
2016-11-10 22:26 ` [RFA 12/20] Introduce htab_up and use gdbpy_enter in py-framefilter.c Tom Tromey
2016-11-10 22:26 ` [RFA 19/20] Introduce gdbpy_enter_varobj and use it Tom Tromey
2016-11-10 22:26 ` [RFA 20/20] Use gdbpy_enter_varobj in py-varobj.c Tom Tromey
2016-11-10 22:26 ` [RFA 18/20] Use gdbpy_enter in py-xmethod.c Tom Tromey
2016-11-10 23:52 ` [RFA 00/20] more use of C++ in the Python layer Pedro Alves
2016-11-11 3:19 ` Tom Tromey
2016-11-12 17:24 ` Tom Tromey
2016-11-15 14:57 ` 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=1478816387-27064-14-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