Remove more uses of explicit reference counting in Python
[deliverable/binutils-gdb.git] / gdb / python / py-value.c
index fe2adcc19c348846bd80e2b0098c33ff8aaf07b8..ebd7ef1a47e8ed95902048a31cf8473ed18c8471 100644 (file)
@@ -1,6 +1,6 @@
 /* Python interface to values.
 
-   Copyright (C) 2008-2018 Free Software Foundation, Inc.
+   Copyright (C) 2008-2019 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -90,17 +90,8 @@ valpy_dealloc (PyObject *obj)
 
   value_decref (self->value);
 
-  if (self->address)
-    /* Use braces to appease gcc warning.  *sigh*  */
-    {
-      Py_DECREF (self->address);
-    }
-
-  if (self->type)
-    {
-      Py_DECREF (self->type);
-    }
-
+  Py_XDECREF (self->address);
+  Py_XDECREF (self->type);
   Py_XDECREF (self->dynamic_type);
 
   Py_TYPE (self)->tp_free (self);
@@ -917,10 +908,10 @@ valpy_call (PyObject *self, PyObject *args, PyObject *keywords)
   TRY
     {
       scoped_value_mark free_values;
-      struct value *return_value;
 
-      return_value = call_function_by_hand (function, NULL,
-                                           args_count, vargs);
+      value *return_value
+       = call_function_by_hand (function, NULL,
+                                gdb::make_array_view (vargs, args_count));
       result = value_to_value_object (return_value);
     }
   CATCH (except, RETURN_MASK_ALL)
@@ -1661,9 +1652,7 @@ convert_value_from_python (PyObject *obj)
                 ULONGEST instead.  */
              if (PyErr_ExceptionMatches (PyExc_OverflowError))
                {
-                 PyObject *etype, *evalue, *etraceback;
-
-                 PyErr_Fetch (&etype, &evalue, &etraceback);
+                 gdbpy_err_fetch fetched_error;
                  gdbpy_ref<> zero (PyInt_FromLong (0));
 
                  /* Check whether obj is positive.  */
@@ -1676,8 +1665,10 @@ convert_value_from_python (PyObject *obj)
                        value = value_from_ulongest (builtin_type_upylong, ul);
                    }
                  else
-                   /* There's nothing we can do.  */
-                   PyErr_Restore (etype, evalue, etraceback);
+                   {
+                     /* There's nothing we can do.  */
+                     fetched_error.restore ();
+                   }
                }
            }
          else
@@ -1732,9 +1723,7 @@ convert_value_from_python (PyObject *obj)
     }
   CATCH (except, RETURN_MASK_ALL)
     {
-      PyErr_Format (except.reason == RETURN_QUIT
-                   ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
-                   "%s", except.message);
+      gdbpy_convert_exception (except);
       return NULL;
     }
   END_CATCH
This page took 0.029881 seconds and 4 git commands to generate.