aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-linetable.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2016-11-06 21:25:34 -0700
committerTom Tromey <tom@tromey.com>2017-01-10 19:13:34 -0700
commit87ce03fdc5a94f48fe62580410a099c0a0f68ee0 (patch)
tree7b4e0e662db3e8985b415d57b9e40998e7e8ab78 /gdb/python/py-linetable.c
parentee0a3fb85b33b172f704796612c4487ea368d675 (diff)
downloadgdb-87ce03fdc5a94f48fe62580410a099c0a0f68ee0.zip
gdb-87ce03fdc5a94f48fe62580410a099c0a0f68ee0.tar.gz
gdb-87ce03fdc5a94f48fe62580410a099c0a0f68ee0.tar.bz2
Use gdbpy_ref in py-linetable.c
This changes some code in py-linetable.c to use gdbpy_ref. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-linetable.c (build_line_table_tuple_from_pcs) (ltpy_get_all_source_lines): Use gdbpy_ref.
Diffstat (limited to 'gdb/python/py-linetable.c')
-rw-r--r--gdb/python/py-linetable.c51
1 files changed, 14 insertions, 37 deletions
diff --git a/gdb/python/py-linetable.c b/gdb/python/py-linetable.c
index ca1b394..1f73ff7 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_ref 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_ref 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_ref 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_ref 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.