Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 09/14] Use gdbpy_reference in py-linetable.c
Date: Mon, 07 Nov 2016 05:57:00 -0000	[thread overview]
Message-ID: <1478497656-11832-10-git-send-email-tom@tromey.com> (raw)
In-Reply-To: <1478497656-11832-1-git-send-email-tom@tromey.com>

This changes some code in py-linetable.c to use gdbpy_reference.

2016-11-06  Tom Tromey  <tom@tromey.com>

	* python/py-linetable.c (build_line_table_tuple_from_pcs)
	(ltpy_get_all_source_lines): Use gdbpy_reference.
---
 gdb/ChangeLog             |  5 +++++
 gdb/python/py-linetable.c | 51 +++++++++++++----------------------------------
 2 files changed, 19 insertions(+), 37 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4921600..9aa7008 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2016-11-06  Tom Tromey  <tom@tromey.com>
 
+	* python/py-linetable.c (build_line_table_tuple_from_pcs)
+	(ltpy_get_all_source_lines): Use gdbpy_reference.
+
+2016-11-06  Tom Tromey  <tom@tromey.com>
+
 	* python/py-framefilter.c (extract_sym, extract_value)
 	(get_py_iter_from_func, bootstrap_python_frame_filters): Use
 	gdbpy_reference.
diff --git a/gdb/python/py-linetable.c b/gdb/python/py-linetable.c
index 662ae88..8be7e0e 100644
--- a/gdb/python/py-linetable.c
+++ b/gdb/python/py-linetable.c
@@ -19,6 +19,7 @@
 
 #include "defs.h"
 #include "python-internal.h"
+#include "py-ref.h"
 
 typedef struct {
   PyObject_HEAD
@@ -124,7 +125,6 @@ static PyObject *
 build_line_table_tuple_from_pcs (int line, VEC (CORE_ADDR) *vec)
 {
   int vec_len = 0;
-  PyObject *tuple;
   CORE_ADDR pc;
   int i;
 
@@ -132,31 +132,22 @@ build_line_table_tuple_from_pcs (int line, VEC (CORE_ADDR) *vec)
   if (vec_len < 1)
     Py_RETURN_NONE;
 
-  tuple = PyTuple_New (vec_len);
+  gdbpy_reference tuple (PyTuple_New (vec_len));
 
   if (tuple == NULL)
     return NULL;
 
   for (i = 0; VEC_iterate (CORE_ADDR, vec, i, pc); ++i)
     {
-      PyObject *obj = build_linetable_entry (line, pc);
+      gdbpy_reference obj (build_linetable_entry (line, pc));
 
       if (obj == NULL)
-	{
-	  Py_DECREF (tuple);
-	  tuple = NULL;
-	  break;
-	}
-      else if (PyTuple_SetItem (tuple, i, obj) != 0)
-	{
-	  Py_DECREF (obj);
-	  Py_DECREF (tuple);
-	  tuple = NULL;
-	  break;
-	}
+	return NULL;
+      else if (PyTuple_SetItem (tuple.get (), i, obj.release ()) != 0)
+	return NULL;
     }
 
-  return tuple;
+  return tuple.release ();
 }
 
 /* Implementation of gdb.LineTable.line (self) -> Tuple.  Returns a
@@ -236,7 +227,6 @@ ltpy_get_all_source_lines (PyObject *self, PyObject *args)
 {
   struct symtab *symtab;
   Py_ssize_t index;
-  PyObject *source_list, *source_dict, *line;
   struct linetable_entry *item;
 
   LTPY_REQUIRE_VALID (self, symtab);
@@ -248,7 +238,7 @@ ltpy_get_all_source_lines (PyObject *self, PyObject *args)
       return NULL;
     }
 
-  source_dict = PyDict_New ();
+  gdbpy_reference source_dict (PyDict_New ());
   if (source_dict == NULL)
     return NULL;
 
@@ -260,30 +250,17 @@ ltpy_get_all_source_lines (PyObject *self, PyObject *args)
 	 include in the source set. */
       if (item->line > 0)
 	{
-	  line = gdb_py_object_from_longest (item->line);
+	  gdbpy_reference line (gdb_py_object_from_longest (item->line));
 
 	  if (line == NULL)
-	    {
-	      Py_DECREF (source_dict);
-	      return NULL;
-	    }
-
-	  if (PyDict_SetItem (source_dict, line, Py_None) == -1)
-	    {
-	      Py_DECREF (line);
-	      Py_DECREF (source_dict);
-	      return NULL;
-	    }
-
-	  Py_DECREF (line);
+	    return NULL;
+
+	  if (PyDict_SetItem (source_dict.get (), line.get (), Py_None) == -1)
+	    return NULL;
 	}
     }
 
-
-  source_list = PyDict_Keys (source_dict);
-  Py_DECREF (source_dict);
-
-  return source_list;
+  return PyDict_Keys (source_dict.get ());
 }
 
 /* Implementation of gdb.LineTable.is_valid (self) -> Boolean.
-- 
2.7.4


  parent reply	other threads:[~2016-11-07  5:57 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-07  6:00 [RFA 00/14] add a smart pointer for PyObject* Tom Tromey
2016-11-07  5:48 ` [RFA 06/14] Use gdbpy_reference in gdbpy_inferiors Tom Tromey
2016-11-07  5:48 ` [RFA 13/14] Use gdbpy_reference in py-value.c Tom Tromey
2016-11-07  5:48 ` [RFA 07/14] Use gdbpy_reference in gdbpy_breakpoints Tom Tromey
2016-11-07  5:48 ` [RFA 12/14] Use gdbpy_reference in python.c Tom Tromey
2016-11-07  5:48 ` [RFA 10/14] Use gdbpy_reference in call_doc_function Tom Tromey
2016-11-07  5:48 ` [RFA 14/14] Use gdbpy_reference in gdbpy_lookup_symbol Tom Tromey
2016-11-07  5:48 ` [RFA 08/14] Use gdbpy_reference in py-framefilter.c Tom Tromey
2016-11-07  5:48 ` [RFA 11/14] Use gdbpy_reference in py-prettyprint.c Tom Tromey
2016-11-07  5:48 ` [RFA 05/14] Use gdbpy_reference in py-function.c Tom Tromey
2016-11-07  5:48 ` [RFA 03/14] Use gdbpy_reference in py-type.c Tom Tromey
2016-11-07  5:48 ` [RFA 01/14] Introduce py-ref.h Tom Tromey
2016-11-07  7:45   ` Jan Kratochvil
2016-11-07 15:48     ` Tom Tromey
2016-11-10 23:48   ` Pedro Alves
2016-11-12 17:31     ` Tom Tromey
2016-11-15 14:32       ` Pedro Alves
2016-11-16 23:18         ` Tom Tromey
2016-11-16 23:34           ` Pedro Alves
2016-11-07  5:48 ` [RFA 04/14] Use gdbpy_reference in gdbpy_string_to_argv Tom Tromey
2016-11-07  5:56 ` [RFA 02/14] Change event code to use gdbpy_reference Tom Tromey
2016-11-11  0:09   ` Pedro Alves
2016-11-11  0:51     ` Pedro Alves
2016-11-07  5:57 ` Tom Tromey [this message]
2016-11-08  4:07 ` [RFA 00/14] add a smart pointer for PyObject* Tom Tromey
2016-11-11  1:18 ` Pedro Alves
2016-11-11  3:34   ` Tom Tromey
2016-11-11  4:03     ` Pedro Alves
2016-11-11  5:49       ` Tom Tromey
2016-11-12 17:11   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1478497656-11832-10-git-send-email-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox