summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-09-12 21:44:19 -0600
committerTom Tromey <tom@tromey.com>2018-09-16 07:25:56 -0600
commit3c7aa30778a1615d88c13508c04138ef2499112d (patch)
treecdfc313d4149467e51b5495cd1e41a416b9653be
parent8743a9cdd20055e02a20c24c37b5312e3e626691 (diff)
downloadbinutils-gdb-3c7aa30778a1615d88c13508c04138ef2499112d.tar.gz
Change pspace_to_pspace_object to return a new reference
This changes pspace_to_pspace_object to return a new reference and fixes up all the callers. gdb/ChangeLog 2018-09-16 Tom Tromey <tom@tromey.com> * python/py-inferior.c (infpy_get_progspace): Update. * python/python-internal.h (pspace_to_pspace_object): Change return type. * python/py-newobjfileevent.c (create_clear_objfiles_event_object): Update. * python/py-xmethods.c (gdbpy_get_matching_xmethod_workers): Update. * python/python.c (gdbpy_get_current_progspace): Update. (gdbpy_progspaces): Update. * python/py-progspace.c (pspace_to_pspace_object): Return a new reference. * python/py-objfile.c (objfpy_get_progspace): Update. * python/py-prettyprint.c (find_pretty_printer_from_progspace): Update.
-rw-r--r--gdb/ChangeLog17
-rw-r--r--gdb/python/py-inferior.c4
-rw-r--r--gdb/python/py-newobjfileevent.c10
-rw-r--r--gdb/python/py-objfile.c7
-rw-r--r--gdb/python/py-prettyprint.c6
-rw-r--r--gdb/python/py-progspace.c29
-rw-r--r--gdb/python/py-xmethods.c6
-rw-r--r--gdb/python/python-internal.h3
-rw-r--r--gdb/python/python.c4
9 files changed, 47 insertions, 39 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index deb3f67054d..717d37bc2b0 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,22 @@
2018-09-16 Tom Tromey <tom@tromey.com>
+ * python/py-inferior.c (infpy_get_progspace): Update.
+ * python/python-internal.h (pspace_to_pspace_object): Change
+ return type.
+ * python/py-newobjfileevent.c
+ (create_clear_objfiles_event_object): Update.
+ * python/py-xmethods.c (gdbpy_get_matching_xmethod_workers):
+ Update.
+ * python/python.c (gdbpy_get_current_progspace): Update.
+ (gdbpy_progspaces): Update.
+ * python/py-progspace.c (pspace_to_pspace_object): Return a new
+ reference.
+ * python/py-objfile.c (objfpy_get_progspace): Update.
+ * python/py-prettyprint.c (find_pretty_printer_from_progspace):
+ Update.
+
+2018-09-16 Tom Tromey <tom@tromey.com>
+
* python/lib/gdb/__init__.py (current_progspace, objfiles)
(solib_name, block_for_pc, find_pc_line): New functions.
(execute_unwinders): Update.
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 6db3df412eb..512d9392d43 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -471,9 +471,7 @@ infpy_get_progspace (PyObject *self, void *closure)
program_space *pspace = inf->inferior->pspace;
gdb_assert (pspace != nullptr);
- PyObject *py_pspace = pspace_to_pspace_object (pspace);
- Py_XINCREF (py_pspace);
- return py_pspace;
+ return pspace_to_pspace_object (pspace).release ();
}
static int
diff --git a/gdb/python/py-newobjfileevent.c b/gdb/python/py-newobjfileevent.c
index a9341a3be18..aa31fb4849b 100644
--- a/gdb/python/py-newobjfileevent.c
+++ b/gdb/python/py-newobjfileevent.c
@@ -66,12 +66,10 @@ create_clear_objfiles_event_object (void)
if (objfile_event == NULL)
return NULL;
- /* Note that pspace_to_pspace_object returns a borrowed reference,
- so we don't need a decref here. */
- PyObject *py_progspace = pspace_to_pspace_object (current_program_space);
- if (!py_progspace || evpy_add_attribute (objfile_event.get (),
- "progspace",
- py_progspace) < 0)
+ gdbpy_ref<> py_progspace = pspace_to_pspace_object (current_program_space);
+ if (py_progspace == NULL || evpy_add_attribute (objfile_event.get (),
+ "progspace",
+ py_progspace.get ()) < 0)
return NULL;
return objfile_event;
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index 61d3a158198..722c9b053d8 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -166,12 +166,7 @@ objfpy_get_progspace (PyObject *self, void *closure)
objfile_object *obj = (objfile_object *) self;
if (obj->objfile)
- {
- PyObject *pspace = pspace_to_pspace_object (obj->objfile->pspace);
-
- Py_XINCREF (pspace);
- return pspace;
- }
+ return pspace_to_pspace_object (obj->objfile->pspace).release ();
Py_RETURN_NONE;
}
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index 7da0f2d9af2..9aadd3b27c9 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -128,11 +128,11 @@ find_pretty_printer_from_objfiles (PyObject *value)
static PyObject *
find_pretty_printer_from_progspace (PyObject *value)
{
- PyObject *obj = pspace_to_pspace_object (current_program_space);
+ gdbpy_ref<> obj = pspace_to_pspace_object (current_program_space);
- if (!obj)
+ if (obj == NULL)
return NULL;
- gdbpy_ref<> pp_list (pspy_get_printers (obj, NULL));
+ gdbpy_ref<> pp_list (pspy_get_printers (obj.get (), NULL));
return search_pp_list (pp_list.get (), value);
}
diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c
index b88ad3c1773..3c468475b15 100644
--- a/gdb/python/py-progspace.c
+++ b/gdb/python/py-progspace.c
@@ -492,30 +492,31 @@ py_free_pspace (struct program_space *pspace, void *datum)
object->pspace = NULL;
}
-/* Return a borrowed reference to the Python object of type Pspace
+/* Return a new reference to the Python object of type Pspace
representing PSPACE. If the object has already been created,
return it. Otherwise, create it. Return NULL and set the Python
error on failure. */
-PyObject *
+gdbpy_ref<>
pspace_to_pspace_object (struct program_space *pspace)
{
- gdbpy_ref<pspace_object> object
- ((pspace_object *) program_space_data (pspace, pspy_pspace_data_key));
- if (object == NULL)
+ PyObject *result
+ ((PyObject *) program_space_data (pspace, pspy_pspace_data_key));
+ if (result == NULL)
{
- object.reset (PyObject_New (pspace_object, &pspace_object_type));
- if (object != NULL)
- {
- if (!pspy_initialize (object.get ()))
- return NULL;
+ gdbpy_ref<pspace_object> object
+ ((pspace_object *) PyObject_New (pspace_object, &pspace_object_type));
+ if (object == NULL)
+ return NULL;
+ if (!pspy_initialize (object.get ()))
+ return NULL;
- object->pspace = pspace;
- set_program_space_data (pspace, pspy_pspace_data_key, object.get ());
- }
+ object->pspace = pspace;
+ set_program_space_data (pspace, pspy_pspace_data_key, object.get ());
+ result = (PyObject *) object.release ();
}
- return (PyObject *) object.release ();
+ return gdbpy_ref<>::new_reference (result);
}
int
diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c
index f7e3c37210c..c568295a165 100644
--- a/gdb/python/py-xmethods.c
+++ b/gdb/python/py-xmethods.c
@@ -122,7 +122,6 @@ gdbpy_get_matching_xmethod_workers
std::vector<xmethod_worker_up> *dm_vec)
{
struct objfile *objfile;
- PyObject *py_progspace;
gdb_assert (obj_type != NULL && method_name != NULL);
@@ -170,10 +169,11 @@ gdbpy_get_matching_xmethod_workers
/* Gather debug methods matchers registered with the current program
space. */
- py_progspace = pspace_to_pspace_object (current_program_space);
+ gdbpy_ref<> py_progspace = pspace_to_pspace_object (current_program_space);
if (py_progspace != NULL)
{
- gdbpy_ref<> pspace_matchers (pspy_get_xmethods (py_progspace, NULL));
+ gdbpy_ref<> pspace_matchers (pspy_get_xmethods (py_progspace.get (),
+ NULL));
gdbpy_ref<> temp (PySequence_Concat (py_xmethod_matcher_list.get (),
pspace_matchers.get ()));
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 1c526af1586..58baa11ee45 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -516,8 +516,7 @@ PyObject *value_to_value_object (struct value *v);
PyObject *type_to_type_object (struct type *);
PyObject *frame_info_to_frame_object (struct frame_info *frame);
PyObject *symtab_to_linetable_object (PyObject *symtab);
-PyObject *pspace_to_pspace_object (struct program_space *)
- CPYCHECKER_RETURNS_BORROWED_REF;
+gdbpy_ref<> pspace_to_pspace_object (struct program_space *);
PyObject *pspy_get_printers (PyObject *, void *);
PyObject *pspy_get_frame_filters (PyObject *, void *);
PyObject *pspy_get_frame_unwinders (PyObject *, void *);
diff --git a/gdb/python/python.c b/gdb/python/python.c
index f541a987894..66b6631f93a 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1293,9 +1293,9 @@ gdbpy_progspaces (PyObject *unused1, PyObject *unused2)
ALL_PSPACES (ps)
{
- PyObject *item = pspace_to_pspace_object (ps);
+ gdbpy_ref<> item = pspace_to_pspace_object (ps);
- if (!item || PyList_Append (list.get (), item) == -1)
+ if (item == NULL || PyList_Append (list.get (), item.get ()) == -1)
return NULL;
}