Fix pthread_setname_np build error
[deliverable/binutils-gdb.git] / gdb / python / py-varobj.c
index e6cf64551449f4061cfe6deb2b8d901285b2d075..611c4ca76f2a1b0206d0ef78dfb07ee51346c8e0 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2013-2018 Free Software Foundation, Inc.
+/* Copyright (C) 2013-2019 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -17,7 +17,6 @@
 #include "python-internal.h"
 #include "varobj.h"
 #include "varobj-iter.h"
-#include "py-ref.h"
 
 /* A dynamic varobj iterator "class" for python pretty-printed
    varobjs.  This inherits struct varobj_iter.  */
@@ -70,14 +69,8 @@ py_varobj_iter_next (struct varobj_iter *self)
       /* If we got a memory error, just use the text as the item.  */
       if (PyErr_ExceptionMatches (gdbpy_gdb_memory_error))
        {
-         PyObject *type, *value, *trace;
-
-         PyErr_Fetch (&type, &value, &trace);
-         gdb::unique_xmalloc_ptr<char>
-           value_str (gdbpy_exception_to_string (type, value));
-         Py_XDECREF (type);
-         Py_XDECREF (value);
-         Py_XDECREF (trace);
+         gdbpy_err_fetch fetched_error;
+         gdb::unique_xmalloc_ptr<char> value_str = fetched_error.to_string ();
          if (value_str == NULL)
            {
              gdbpy_print_stack ();
@@ -130,14 +123,14 @@ static const struct varobj_iter_ops py_varobj_iter_ops =
    whose children the iterator will be iterating over.  PYITER is the
    python iterator actually responsible for the iteration.  */
 
-static void CPYCHECKER_STEALS_REFERENCE_TO_ARG (3)
+static void
 py_varobj_iter_ctor (struct py_varobj_iter *self,
-                     struct varobj *var, PyObject *pyiter)
+                    struct varobj *var, gdbpy_ref<> &&pyiter)
 {
   self->base.var = var;
   self->base.ops = &py_varobj_iter_ops;
   self->base.next_raw_index = 0;
-  self->iter = pyiter;
+  self->iter = pyiter.release ();
 }
 
 /* Allocate and construct a pretty-printed varobj iterator.  VAR is
@@ -145,13 +138,13 @@ py_varobj_iter_ctor (struct py_varobj_iter *self,
    PYITER is the python iterator actually responsible for the
    iteration.  */
 
-static struct py_varobj_iter * CPYCHECKER_STEALS_REFERENCE_TO_ARG (2)
-py_varobj_iter_new (struct varobj *var, PyObject *pyiter)
+static struct py_varobj_iter *
+py_varobj_iter_new (struct varobj *var, gdbpy_ref<> &&pyiter)
 {
   struct py_varobj_iter *self;
 
   self = XNEW (struct py_varobj_iter);
-  py_varobj_iter_ctor (self, var, pyiter);
+  py_varobj_iter_ctor (self, var, std::move (pyiter));
   return self;
 }
 
@@ -161,7 +154,6 @@ py_varobj_iter_new (struct varobj *var, PyObject *pyiter)
 struct varobj_iter *
 py_varobj_get_iterator (struct varobj *var, PyObject *printer)
 {
-  PyObject *iter;
   struct py_varobj_iter *py_iter;
 
   gdbpy_enter_varobj enter_py (var);
@@ -177,14 +169,14 @@ py_varobj_get_iterator (struct varobj *var, PyObject *printer)
       error (_("Null value returned for children"));
     }
 
-  iter = PyObject_GetIter (children.get ());
+  gdbpy_ref<> iter (PyObject_GetIter (children.get ()));
   if (iter == NULL)
     {
       gdbpy_print_stack ();
       error (_("Could not get children iterator"));
     }
 
-  py_iter = py_varobj_iter_new (var, iter);
+  py_iter = py_varobj_iter_new (var, std::move (iter));
 
   return &py_iter->base;
 }
This page took 0.026579 seconds and 4 git commands to generate.