Use gdbpy_enter_varobj in varobj_value_get_print_value
authorTom Tromey <tom@tromey.com>
Sat, 12 Nov 2016 18:51:59 +0000 (11:51 -0700)
committerTom Tromey <tom@tromey.com>
Wed, 11 Jan 2017 02:13:56 +0000 (19:13 -0700)
This changes the last function in varobj.c to use gdbpy_enter_varobj.

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

* varobj.c (varobj_value_get_print_value): Use
gdbpy_enter_varobj.

gdb/ChangeLog
gdb/varobj.c

index 8eb4390e6cadb3214fe2eb048c3ba18bc713da8a..275e50751fa1cf32cc5dd369d10eb543e2c19000 100644 (file)
@@ -1,3 +1,8 @@
+2017-01-10  Tom Tromey  <tom@tromey.com>
+
+       * varobj.c (varobj_value_get_print_value): Use
+       gdbpy_enter_varobj.
+
 2017-01-10  Tom Tromey  <tom@tromey.com>
 
        * python/py-prettyprint.c (print_string_repr, print_children):
index d75c9b84934c4cde3c462f2c0005c486caa30f33..f93e930ed4e81f2cc2bcc24774a94aae7103137e 100644 (file)
@@ -2431,7 +2431,7 @@ varobj_value_get_print_value (struct value *value,
     {
       PyObject *value_formatter =  var->dynamic->pretty_printer;
 
-      varobj_ensure_python_env (var);
+      gdbpy_enter_varobj enter_py (var);
 
       if (value_formatter)
        {
@@ -2446,24 +2446,21 @@ varobj_value_get_print_value (struct value *value,
          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
@@ -2475,7 +2472,7 @@ varobj_value_get_print_value (struct value *value,
                         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)
                        {