[2/4] Remove cleanup from procfs.c

Message ID 20180903190250.11599-3-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey Sept. 3, 2018, 7:02 p.m. UTC
  This removes the last remaining cleanup from procfs.c, replacing it
with a unique_ptr specialization.

gdb/ChangeLog
2018-09-03  Tom Tromey  <tom@tromey.com>

	* procfs.c (struct procinfo_deleter): New.
	(procinfo_up): New typedef.
	(do_destroy_procinfo_cleanup): Remove.
	(procfs_target::info_proc): Use procinfo_up.  Remove cleanups.
---
 gdb/ChangeLog |  7 +++++++
 gdb/procfs.c  | 21 ++++++++++++---------
 2 files changed, 19 insertions(+), 9 deletions(-)
  

Comments

Rainer Orth Sept. 4, 2018, 10:47 a.m. UTC | #1
Hi Tom,

> This removes the last remaining cleanup from procfs.c, replacing it
> with a unique_ptr specialization.

I've now regtested the patch on amd64-pc-solaris2.11.  After fixing one
compile failure

/vol/src/gnu/gdb/hg/master/dist/gdb/procfs.c:275:13: error: ‘void do_destroy_procinfo_cleanup(void*)’ declared ‘static’ but never defined [-Werror=unused-function]
 static void do_destroy_procinfo_cleanup (void *);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~

by removing the unnecessary declaration, testing passed without
regressions (as far as I can tell with racy tests etc.).

	Rainer
  
Tom Tromey Sept. 4, 2018, 4:55 p.m. UTC | #2
>>>>> "Rainer" == Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> writes:

Rainer> I've now regtested the patch on amd64-pc-solaris2.11.

Thank you for doing this.

Rainer> /vol/src/gnu/gdb/hg/master/dist/gdb/procfs.c:275:13: error: ‘void do_destroy_procinfo_cleanup(void*)’ declared ‘static’ but never defined [-Werror=unused-function]
Rainer>  static void do_destroy_procinfo_cleanup (void *);
Rainer>              ^~~~~~~~~~~~~~~~~~~~~~~~~~~

Rainer> by removing the unnecessary declaration, testing passed without
Rainer> regressions (as far as I can tell with racy tests etc.).

I've removed the declaration on my branch.

Tom
  

Patch

diff --git a/gdb/procfs.c b/gdb/procfs.c
index ec346503487..7d41907c4aa 100644
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -549,11 +549,16 @@  destroy_procinfo (procinfo *pi)
     }
 }
 
-static void
-do_destroy_procinfo_cleanup (void *pi)
+/* A deleter that calls destroy_procinfo.  */
+struct procinfo_deleter
 {
-  destroy_procinfo ((procinfo *) pi);
-}
+  void operator() (procinfo *pi) const
+  {
+    destroy_procinfo (pi);
+  }
+};
+
+typedef std::unique_ptr<procinfo, procinfo_deleter> procinfo_up;
 
 enum { NOKILL, KILL };
 
@@ -3545,7 +3550,6 @@  info_proc_mappings (procinfo *pi, int summary)
 bool
 procfs_target::info_proc (const char *args, enum info_proc_what what)
 {
-  struct cleanup *old_chain;
   procinfo *process  = NULL;
   procinfo *thread   = NULL;
   char     *tmp      = NULL;
@@ -3567,7 +3571,6 @@  procfs_target::info_proc (const char *args, enum info_proc_what what)
       error (_("Not supported on this target."));
     }
 
-  old_chain = make_cleanup (null_cleanup, 0);
   gdb_argv built_argv (args);
   for (char *arg : built_argv)
     {
@@ -3582,6 +3585,8 @@  procfs_target::info_proc (const char *args, enum info_proc_what what)
 	  tid = strtoul (arg + 1, NULL, 10);
 	}
     }
+
+  procinfo_up temporary_procinfo;
   if (pid == 0)
     pid = inferior_ptid.pid ();
   if (pid == 0)
@@ -3596,7 +3601,7 @@  procfs_target::info_proc (const char *args, enum info_proc_what what)
 	   /* No.  So open a procinfo for it, but
 	      remember to close it again when finished.  */
 	   process = create_procinfo (pid, 0);
-	   make_cleanup (do_destroy_procinfo_cleanup, process);
+	   temporary_procinfo.reset (process);
 	   if (!open_procinfo_files (process, FD_CTL))
 	     proc_error (process, "info proc, open_procinfo_files", __LINE__);
 	 }
@@ -3627,8 +3632,6 @@  procfs_target::info_proc (const char *args, enum info_proc_what what)
       info_proc_mappings (process, 0);
     }
 
-  do_cleanups (old_chain);
-
   return true;
 }