This patch changes py-inferior.c to use gdbpy_ref<> when possible,
reducing the amount of manual reference counting.
Tested on x86-64 Fedora 29.
gdb/ChangeLog
2019-07-10 Tom Tromey <tromey@adacore.com>
* python/python-internal.h (create_thread_object): Return
gdbpy_ref.
* python/py-infthread.c (create_thread_object): Return gdbpy_ref.
* python/py-inferior.c (struct threadlist_entry): Add
constructor.
<thread_obj>: Now a gdbpy_ref.
(thread_to_thread_object): Update.
(add_thread_object): Use new.
(delete_thread_object): Use delete.
(infpy_threads): Update.
(py_free_inferior): Update. Construct "inf_obj" after acquiring
GIL.
2019-07-10 Tom Tromey <tromey@adacore.com>
2019-07-10 Tom Tromey <tromey@adacore.com>
+ * python/python-internal.h (create_thread_object): Return
+ gdbpy_ref.
+ * python/py-infthread.c (create_thread_object): Return gdbpy_ref.
+ * python/py-inferior.c (struct threadlist_entry): Add
+ constructor.
+ <thread_obj>: Now a gdbpy_ref.
+ (thread_to_thread_object): Update.
+ (add_thread_object): Use new.
+ (delete_thread_object): Use delete.
+ (infpy_threads): Update.
+ (py_free_inferior): Update. Construct "inf_obj" after acquiring
+ GIL.
+
+2019-07-10 Tom Tromey <tromey@adacore.com>
+
* valops.c (value_cast): Specialize error message for Ada.
2019-07-10 Simon Marchi <simon.marchi@polymtl.ca>
* valops.c (value_cast): Specialize error message for Ada.
2019-07-10 Simon Marchi <simon.marchi@polymtl.ca>
#include "py-event.h"
#include "py-stopevent.h"
#include "py-event.h"
#include "py-stopevent.h"
-struct threadlist_entry {
- thread_object *thread_obj;
+struct threadlist_entry
+{
+ threadlist_entry (gdbpy_ref<thread_object> &&ref)
+ : thread_obj (std::move (ref))
+ {
+ }
+
+ gdbpy_ref<thread_object> thread_obj;
struct threadlist_entry *next;
};
struct threadlist_entry *next;
};
thread != NULL;
thread = thread->next)
if (thread->thread_obj->thread == thr)
thread != NULL;
thread = thread->next)
if (thread->thread_obj->thread == thr)
- return gdbpy_ref<>::new_reference ((PyObject *) thread->thread_obj);
+ return gdbpy_ref<>::new_reference ((PyObject *) thread->thread_obj.get ());
PyErr_SetString (PyExc_SystemError,
_("could not find gdb thread object"));
PyErr_SetString (PyExc_SystemError,
_("could not find gdb thread object"));
static void
add_thread_object (struct thread_info *tp)
{
static void
add_thread_object (struct thread_info *tp)
{
- thread_object *thread_obj;
inferior_object *inf_obj;
struct threadlist_entry *entry;
inferior_object *inf_obj;
struct threadlist_entry *entry;
gdbpy_enter enter_py (python_gdbarch, python_language);
gdbpy_enter enter_py (python_gdbarch, python_language);
- thread_obj = create_thread_object (tp);
- if (!thread_obj)
+ gdbpy_ref<thread_object> thread_obj = create_thread_object (tp);
+ if (thread_obj == NULL)
{
gdbpy_print_stack ();
return;
{
gdbpy_print_stack ();
return;
inf_obj = (inferior_object *) thread_obj->inf_obj;
inf_obj = (inferior_object *) thread_obj->inf_obj;
- entry = XNEW (struct threadlist_entry);
- entry->thread_obj = thread_obj;
+ entry = new threadlist_entry (std::move (thread_obj));
entry->next = inf_obj->threads;
inf_obj->threads = entry;
entry->next = inf_obj->threads;
inf_obj->threads = entry;
return;
gdbpy_ref<> event = create_thread_event_object (&new_thread_event_object_type,
return;
gdbpy_ref<> event = create_thread_event_object (&new_thread_event_object_type,
- (PyObject *) thread_obj);
+ (PyObject *) thread_obj.get ());
if (event == NULL
|| evpy_emit_event (event.get (), gdb_py_events.new_thread) < 0)
gdbpy_print_stack ();
if (event == NULL
|| evpy_emit_event (event.get (), gdb_py_events.new_thread) < 0)
gdbpy_print_stack ();
*entry = (*entry)->next;
inf_obj->nthreads--;
*entry = (*entry)->next;
inf_obj->nthreads--;
- Py_DECREF (tmp->thread_obj);
- xfree (tmp);
for (i = 0, entry = inf_obj->threads; i < inf_obj->nthreads;
i++, entry = entry->next)
{
for (i = 0, entry = inf_obj->threads; i < inf_obj->nthreads;
i++, entry = entry->next)
{
- Py_INCREF (entry->thread_obj);
- PyTuple_SET_ITEM (tuple, i, (PyObject *) entry->thread_obj);
+ PyObject *thr = (PyObject *) entry->thread_obj.get ();
+ Py_INCREF (thr);
+ PyTuple_SET_ITEM (tuple, i, thr);
static void
py_free_inferior (struct inferior *inf, void *datum)
{
static void
py_free_inferior (struct inferior *inf, void *datum)
{
- gdbpy_ref<inferior_object> inf_obj ((inferior_object *) datum);
struct threadlist_entry *th_entry, *th_tmp;
if (!gdb_python_initialized)
return;
gdbpy_enter enter_py (python_gdbarch, python_language);
struct threadlist_entry *th_entry, *th_tmp;
if (!gdb_python_initialized)
return;
gdbpy_enter enter_py (python_gdbarch, python_language);
+ gdbpy_ref<inferior_object> inf_obj ((inferior_object *) datum);
inf_obj->inferior = NULL;
/* Deallocate threads list. */
for (th_entry = inf_obj->threads; th_entry != NULL;)
{
inf_obj->inferior = NULL;
/* Deallocate threads list. */
for (th_entry = inf_obj->threads; th_entry != NULL;)
{
- Py_DECREF (th_entry->thread_obj);
-
th_tmp = th_entry;
th_entry = th_entry->next;
th_tmp = th_entry;
th_entry = th_entry->next;
+gdbpy_ref<thread_object>
create_thread_object (struct thread_info *tp)
{
create_thread_object (struct thread_info *tp)
{
- thread_object *thread_obj;
+ gdbpy_ref<thread_object> thread_obj;
gdbpy_ref<inferior_object> inf_obj = inferior_to_inferior_object (tp->inf);
if (inf_obj == NULL)
return NULL;
gdbpy_ref<inferior_object> inf_obj = inferior_to_inferior_object (tp->inf);
if (inf_obj == NULL)
return NULL;
- thread_obj = PyObject_New (thread_object, &thread_object_type);
- if (!thread_obj)
+ thread_obj.reset (PyObject_New (thread_object, &thread_object_type));
+ if (thread_obj == NULL)
return NULL;
thread_obj->thread = tp;
return NULL;
thread_obj->thread = tp;
PyObject *gdbarch_to_arch_object (struct gdbarch *gdbarch);
PyObject *gdbarch_to_arch_object (struct gdbarch *gdbarch);
-thread_object *create_thread_object (struct thread_info *tp);
+gdbpy_ref<thread_object> create_thread_object (struct thread_info *tp);
gdbpy_ref<> thread_to_thread_object (thread_info *thr);;
gdbpy_ref<inferior_object> inferior_to_inferior_object (inferior *inf);
gdbpy_ref<> thread_to_thread_object (thread_info *thr);;
gdbpy_ref<inferior_object> inferior_to_inferior_object (inferior *inf);