Use gdbpy_ref to simplify some logic

This uses the new gdbpy_ref template to simplify logic in various
parts of the Python layer; for example removing repeated error code or
removing gotos.

gdb/ChangeLog
2017-02-10  Tom Tromey  <tom@tromey.com>

	* python/py-cmd.c (cmdpy_destroyer): Use gdbpy_ref.
	* python/py-breakpoint.c (gdbpy_breakpoint_deleted): Use
	gdbpy_ref.
	* python/py-type.c (field_new): Use gdbpy_ref.
	* python/py-symtab.c (symtab_and_line_to_sal_object): Use
	gdbpy_ref.
	* python/py-progspace.c (pspy_new): Use gdbpy_ref.
	(py_free_pspace): Likewise.
	(pspace_to_pspace_object): Likewise.
	* python/py-objfile.c (objfpy_new): Use gdbpy_ref.
	(py_free_objfile): Likewise.
	(objfile_to_objfile_object): Likewise.
	* python/py-inferior.c (delete_thread_object): Use
	gdbpy_ref.
	(infpy_read_memory): Likewise.
	(py_free_inferior): Likewise.
	* python/py-evtregistry.c (create_eventregistry_object): Use
	gdbpy_ref.
	* python/py-event.c (create_event_object): Use gdbpy_ref.
This commit is contained in:
Tom Tromey 2017-01-11 16:28:43 -07:00
parent 7780f18678
commit 88b6faea99
11 changed files with 94 additions and 116 deletions

View file

@ -300,7 +300,6 @@ add_thread_object (struct thread_info *tp)
static void
delete_thread_object (struct thread_info *tp, int ignore)
{
inferior_object *inf_obj;
struct threadlist_entry **entry, *tmp;
if (!gdb_python_initialized)
@ -308,9 +307,9 @@ delete_thread_object (struct thread_info *tp, int ignore)
gdbpy_enter enter_py (python_gdbarch, python_language);
inf_obj
= (inferior_object *) find_inferior_object (ptid_get_pid (tp->ptid));
if (!inf_obj)
gdbpy_ref<inferior_object> inf_obj
((inferior_object *) find_inferior_object (ptid_get_pid (tp->ptid)));
if (inf_obj == NULL)
return;
/* Find thread entry in its inferior's thread_list. */
@ -320,10 +319,7 @@ delete_thread_object (struct thread_info *tp, int ignore)
break;
if (!*entry)
{
Py_DECREF (inf_obj);
return;
}
return;
tmp = *entry;
tmp->thread_obj->thread = NULL;
@ -332,7 +328,6 @@ delete_thread_object (struct thread_info *tp, int ignore)
inf_obj->nthreads--;
Py_DECREF (tmp->thread_obj);
Py_DECREF (inf_obj);
xfree (tmp);
}
@ -439,7 +434,6 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
{
CORE_ADDR addr, length;
gdb_byte *buffer = NULL;
membuf_object *membuf_obj;
PyObject *addr_obj, *length_obj, *result;
static char *keywords[] = { "address", "length", NULL };
@ -464,7 +458,8 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
}
END_CATCH
membuf_obj = PyObject_New (membuf_object, &membuf_object_type);
gdbpy_ref<membuf_object> membuf_obj (PyObject_New (membuf_object,
&membuf_object_type));
if (membuf_obj == NULL)
{
xfree (buffer);
@ -476,12 +471,11 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
membuf_obj->length = length;
#ifdef IS_PY3K
result = PyMemoryView_FromObject ((PyObject *) membuf_obj);
result = PyMemoryView_FromObject ((PyObject *) membuf_obj.get ());
#else
result = PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0,
result = PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj.get (), 0,
Py_END_OF_BUFFER);
#endif
Py_DECREF (membuf_obj);
return result;
}
@ -769,7 +763,7 @@ infpy_dealloc (PyObject *obj)
static void
py_free_inferior (struct inferior *inf, void *datum)
{
inferior_object *inf_obj = (inferior_object *) datum;
gdbpy_ref<inferior_object> inf_obj ((inferior_object *) datum);
struct threadlist_entry *th_entry, *th_tmp;
if (!gdb_python_initialized)
@ -790,8 +784,6 @@ py_free_inferior (struct inferior *inf, void *datum)
}
inf_obj->nthreads = 0;
Py_DECREF ((PyObject *) inf_obj);
}
/* Implementation of gdb.selected_inferior() -> gdb.Inferior.