Use gdbpy_enter in py-prettyprint.c

Change py-prettyprint.c to use gdbpy_enter.

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

	* python/py-prettyprint.c (gdbpy_apply_val_pretty_printer): Use
	gdbpy_enter, gdbpy_ref, unique_xmalloc_ptr.
This commit is contained in:
Tom Tromey 2016-11-08 11:38:22 -07:00
parent 6349f452e0
commit e9f0c3639f
2 changed files with 20 additions and 30 deletions

View file

@ -1,3 +1,8 @@
2017-01-10 Tom Tromey <tom@tromey.com>
* python/py-prettyprint.c (gdbpy_apply_val_pretty_printer): Use
gdbpy_enter, gdbpy_ref, unique_xmalloc_ptr.
2017-01-10 Tom Tromey <tom@tromey.com> 2017-01-10 Tom Tromey <tom@tromey.com>
* utils.h (htab_deleter): New struct. * utils.h (htab_deleter): New struct.

View file

@ -682,12 +682,7 @@ gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang,
const struct language_defn *language) const struct language_defn *language)
{ {
struct gdbarch *gdbarch = get_type_arch (type); struct gdbarch *gdbarch = get_type_arch (type);
PyObject *printer = NULL;
PyObject *val_obj = NULL;
struct value *value; 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; enum string_repr_result print_result;
const gdb_byte *valaddr = value_contents_for_printing (val); const gdb_byte *valaddr = value_contents_for_printing (val);
@ -698,52 +693,42 @@ gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang,
if (!gdb_python_initialized) if (!gdb_python_initialized)
return EXT_LANG_RC_NOP; return EXT_LANG_RC_NOP;
cleanups = ensure_python_env (gdbarch, language); gdbpy_enter enter_py (gdbarch, language);
/* Instantiate the printer. */ /* Instantiate the printer. */
value = value_from_component (val, type, embedded_offset); value = value_from_component (val, type, embedded_offset);
val_obj = value_to_value_object (value); gdbpy_ref val_obj (value_to_value_object (value));
if (! val_obj) if (val_obj == NULL)
{ {
result = EXT_LANG_RC_ERROR; print_stack_unless_memory_error (stream);
goto done; return EXT_LANG_RC_ERROR;
} }
/* Find the constructor. */ /* Find the constructor. */
printer = find_pretty_printer (val_obj); gdbpy_ref printer (find_pretty_printer (val_obj.get ()));
Py_DECREF (val_obj);
if (printer == NULL) if (printer == NULL)
{ {
result = EXT_LANG_RC_ERROR; print_stack_unless_memory_error (stream);
goto done; return EXT_LANG_RC_ERROR;
} }
make_cleanup_py_decref (printer);
if (printer == Py_None) if (printer == Py_None)
{ return EXT_LANG_RC_NOP;
result = EXT_LANG_RC_NOP;
goto done;
}
/* If we are printing a map, we want some special formatting. */ /* 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 the section */
print_result = print_string_repr (printer, hint.get (), stream, recurse, print_result = print_string_repr (printer.get (), hint.get (), stream,
options, language, gdbarch); recurse, options, language, gdbarch);
if (print_result != string_repr_error) if (print_result != string_repr_error)
print_children (printer, hint.get (), stream, recurse, options, language, print_children (printer.get (), hint.get (), stream, recurse, options,
print_result == string_repr_none); language, print_result == string_repr_none);
result = EXT_LANG_RC_OK;
done:
if (PyErr_Occurred ()) if (PyErr_Occurred ())
print_stack_unless_memory_error (stream); print_stack_unless_memory_error (stream);
do_cleanups (cleanups); return EXT_LANG_RC_OK;
return result;
} }