[PATCH 06/24] gdbsupport: make intrusive_list's disposer accept a reference

Simon Marchi
2023-10-10T20:43:17Z

All the API of intrusive_list works with references to item, I'm not
sure why the disposer used in intrusive_list::clear_and_dispose is
different and receives a pointer. Change it to accept a reference
instead. This helps simplify a bit a subsequent patch, and I don't see
any downside to it.

Change-Id: I380886cd4ddaf136fe532eb2744f9e69beb41283
---
gdb/inferior.c | 10 +++++-----
gdb/unittests/intrusive_list-selftests.c | 4 ++--
gdbsupport/intrusive_list.h | 2 +-
3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/gdb/inferior.c b/gdb/inferior.c
index efe57cceae3e..4a55970ccba1 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -262,13 +262,13 @@ inferior::find_thread (ptid_t ptid)
void
inferior::clear_thread_list ()
{
- thread_list.clear_and_dispose ([=] (thread_info *thr)
+ thread_list.clear_and_dispose ([=] (thread_info &thr)
{
threads_debug_printf ("deleting thread %s",
- thr->ptid.to_string ().c_str ());
- set_thread_exited (thr, {}, true /* silent */);
- if (thr->deletable ())
- delete thr;
+ thr.ptid.to_string ().c_str ());
+ set_thread_exited (&thr, {}, true /* silent */);
+ if (thr.deletable ())
+ delete &thr;
});
ptid_thread_map.clear ();
}
diff --git a/gdb/unittests/intrusive_list-selftests.c b/gdb/unittests/intrusive_list-selftests.c
index 1f85b3266830..d990c0878b35 100644
--- a/gdb/unittests/intrusive_list-selftests.c
+++ b/gdb/unittests/intrusive_list-selftests.c
@@ -692,9 +692,9 @@ struct intrusive_list_test
list.push_back (b);
list.push_back (c);

- auto disposer = [&] (const item_type *item)
+ auto disposer = [&] (const item_type &item)
{
- disposer_seen.insert (item);
+ disposer_seen.insert (&item);
disposer_calls++;
};
list.clear_and_dispose (disposer);
diff --git a/gdbsupport/intrusive_list.h b/gdbsupport/intrusive_list.h
index 5e9243867d27..aea1922cabee 100644
--- a/gdbsupport/intrusive_list.h
+++ b/gdbsupport/intrusive_list.h
@@ -513,7 +513,7 @@ class intrusive_list
{
while (!this->empty ())
{
- pointer p = &front ();
+ reference p = front ();
pop_front ();
disposer (p);
}
--
2.42.0