}
#ifdef HAVE_PYTHON
-/* Helper function to install a Python environment suitable for
- use during operations on VAR. */
-struct cleanup *
-varobj_ensure_python_env (const struct varobj *var)
-{
- return ensure_python_env (var->root->exp->gdbarch,
- var->root->exp->language_defn);
-}
/* See python-internal.h. */
gdbpy_enter_varobj::gdbpy_enter_varobj (const struct varobj *var)
if (var->saved_item != NULL)
{
value_free (var->saved_item->value);
- xfree (var->saved_item);
+ delete var->saved_item;
var->saved_item = NULL;
}
}
can_mention ? cchanged : NULL, i,
item);
- xfree (item);
+ delete item;
}
else
{
gdbpy_enter_varobj enter_py (var);
mainmod = PyImport_AddModule ("__main__");
- gdbpy_ref globals (PyModule_GetDict (mainmod));
+ gdbpy_ref<> globals (PyModule_GetDict (mainmod));
Py_INCREF (globals.get ());
- gdbpy_ref constructor (PyRun_String (visualizer, Py_eval_input,
- globals.get (), globals.get ()));
+ gdbpy_ref<> constructor (PyRun_String (visualizer, Py_eval_input,
+ globals.get (), globals.get ()));
if (constructor == NULL)
{
type = check_typedef (type);
- if (TYPE_CODE (type) == TYPE_CODE_REF)
+ if (TYPE_IS_REFERENCE (type))
type = get_target_type (type);
type = check_typedef (type);
enum varobj_display_formats format,
const struct varobj *var)
{
- struct ui_file *stb;
- struct cleanup *old_chain;
struct value_print_options opts;
struct type *type = NULL;
long len = 0;
if (value == NULL)
return std::string ();
- stb = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (stb);
-
+ string_file stb;
std::string thevalue;
#if HAVE_PYTHON
{
PyObject *value_formatter = var->dynamic->pretty_printer;
- varobj_ensure_python_env (var);
+ gdbpy_enter_varobj enter_py (var);
if (value_formatter)
{
/* First check to see if we have any children at all. If so,
we simply return {...}. */
if (dynamic_varobj_has_child_method (var))
- {
- do_cleanups (old_chain);
- return xstrdup ("{...}");
- }
+ return "{...}";
if (PyObject_HasAttr (value_formatter, gdbpy_to_string_cst))
{
struct value *replacement;
- PyObject *output = NULL;
- output = apply_varobj_pretty_printer (value_formatter,
- &replacement,
- stb);
+ gdbpy_ref<> output (apply_varobj_pretty_printer (value_formatter,
+ &replacement,
+ &stb));
/* If we have string like output ... */
- if (output)
+ if (output != NULL)
{
- make_cleanup_py_decref (output);
-
/* If this is a lazy string, extract it. For lazy
strings we always print as a string, so set
string_print. */
- if (gdbpy_is_lazy_string (output))
+ if (gdbpy_is_lazy_string (output.get ()))
{
- gdbpy_extract_lazy_string (output, &str_addr, &type,
- &len, &encoding);
+ gdbpy_extract_lazy_string (output.get (), &str_addr,
+ &type, &len, &encoding);
string_print = 1;
}
else
string as a value. */
gdb::unique_xmalloc_ptr<char> s
- = python_string_to_target_string (output);
+ = python_string_to_target_string (output.get ());
if (s)
{
type = builtin_type (gdbarch)->builtin_char;
if (!string_print)
- {
- do_cleanups (old_chain);
- return thevalue;
- }
+ return thevalue;
}
else
gdbpy_print_stack ();
/* If the THEVALUE has contents, it is a regular string. */
if (!thevalue.empty ())
- LA_PRINT_STRING (stb, type, (gdb_byte *) thevalue.c_str (),
+ LA_PRINT_STRING (&stb, type, (gdb_byte *) thevalue.c_str (),
len, encoding.get (), 0, &opts);
else if (string_print)
/* Otherwise, if string_print is set, and it is not a regular
string, it is a lazy string. */
- val_print_string (type, encoding.get (), str_addr, len, stb, &opts);
+ val_print_string (type, encoding.get (), str_addr, len, &stb, &opts);
else
/* All other cases. */
- common_val_print (value, stb, 0, &opts, current_language);
-
- thevalue = ui_file_as_string (stb);
+ common_val_print (value, &stb, 0, &opts, current_language);
- do_cleanups (old_chain);
- return thevalue;
+ return std::move (stb.string ());
}
int