[PATCHv3,2/7] gdb: remove decref_target

Message ID 7c87022362c12d14247e3106f12018c0759848a1.1668789658.git.aburgess@redhat.com
State Committed
Commit 9678f8fe975c213c94735221dcb438395e4de9e1
Headers
Series gdb: fix target_ops reference count for some cases |

Commit Message

Andrew Burgess Nov. 18, 2022, 4:42 p.m. UTC
  The decref_target function is not really needed.  Calling
target_ops::decref will just redirect to decref_target anyway, so why
not just rename decref_target to target_ops::decref?

That's what this commit does.

It's not exactly renaming to target_ops::decref, because the decref
functionality is handled by a policy class, so the new name is now
target_ops_ref_policy::decref.

There should be no user visible change after this commit.
---
 gdb/target.c |  2 +-
 gdb/target.h | 10 +++-------
 2 files changed, 4 insertions(+), 8 deletions(-)
  

Comments

Tom Tromey Nov. 18, 2022, 5:22 p.m. UTC | #1
>>>>> "Andrew" == Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org> writes:

Andrew> The decref_target function is not really needed.  Calling
Andrew> target_ops::decref will just redirect to decref_target anyway, so why
Andrew> not just rename decref_target to target_ops::decref?

This looks good to me, but it seems like it should come after patch #3,
because that patch removes a use of decref_target -- meaning it's still
needed to compile gdb at this point in the series.

Tom
  

Patch

diff --git a/gdb/target.c b/gdb/target.c
index 74925e139dc..d7f742c83ec 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -1157,7 +1157,7 @@  to_execution_direction must be implemented for reverse async");
 /* See target.h.  */
 
 void
-decref_target (target_ops *t)
+target_ops_ref_policy::decref (target_ops *t)
 {
   t->decref ();
   if (t->refcount () == 0)
diff --git a/gdb/target.h b/gdb/target.h
index 28aa9273893..0f5038fb9b2 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -1337,9 +1337,6 @@  struct target_ops_deleter
 /* A unique pointer for target_ops.  */
 typedef std::unique_ptr<target_ops, target_ops_deleter> target_ops_up;
 
-/* Decref a target and close if, if there are no references left.  */
-extern void decref_target (target_ops *t);
-
 /* A policy class to interface gdb::ref_ptr with target_ops.  */
 
 struct target_ops_ref_policy
@@ -1349,10 +1346,9 @@  struct target_ops_ref_policy
     t->incref ();
   }
 
-  static void decref (target_ops *t)
-  {
-    decref_target (t);
-  }
+  /* Decrement the reference count on T, and, if the reference count
+     reaches zero, close the target.  */
+  static void decref (target_ops *t);
 };
 
 /* A gdb::ref_ptr pointer to a target_ops.  */