Make save_infcall_*_state return unique pointers
authorTom Tromey <tom@tromey.com>
Wed, 11 Jul 2018 19:29:59 +0000 (13:29 -0600)
committerTom Tromey <tom@tromey.com>
Mon, 17 Sep 2018 06:42:19 +0000 (00:42 -0600)
Simon pointed out that save_infcall_suspend_state and
save_infcall_control_state could return unique pointers.  This patch
implements this idea.

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

* infrun.c (save_infcall_suspend_state): Return
infcall_suspend_state_up.
(save_infcall_control_state): Return infcall_control_state_up.
* inferior.h (save_infcall_suspend_state)
(save_infcall_control_state): Declare later.  Return unique
pointers.

gdb/ChangeLog
gdb/inferior.h
gdb/infrun.c

index cfb3e7bdf1a20f882d309fa6d3675025c40942db..351dc2dab19eed58d59dba5b11c15b0d248177ef 100644 (file)
@@ -1,3 +1,12 @@
+2018-09-17  Tom Tromey  <tom@tromey.com>
+
+       * infrun.c (save_infcall_suspend_state): Return
+       infcall_suspend_state_up.
+       (save_infcall_control_state): Return infcall_control_state_up.
+       * inferior.h (save_infcall_suspend_state)
+       (save_infcall_control_state): Declare later.  Return unique
+       pointers.
+
 2018-09-17  Tom Tromey  <tom@tromey.com>
 
        * infrun.c (struct stop_context): Declare constructor,
index 5c8ef33dfefc8271021a65414994dec6cb387526..af5e920196187b3045a671761bbb02130a0b417d 100644 (file)
@@ -57,9 +57,6 @@ struct thread_info;
 struct infcall_suspend_state;
 struct infcall_control_state;
 
-extern struct infcall_suspend_state *save_infcall_suspend_state (void);
-extern struct infcall_control_state *save_infcall_control_state (void);
-
 extern void restore_infcall_suspend_state (struct infcall_suspend_state *);
 extern void restore_infcall_control_state (struct infcall_control_state *);
 
@@ -77,6 +74,8 @@ struct infcall_suspend_state_deleter
 typedef std::unique_ptr<infcall_suspend_state, infcall_suspend_state_deleter>
     infcall_suspend_state_up;
 
+extern infcall_suspend_state_up save_infcall_suspend_state ();
+
 /* A deleter for infcall_control_state that calls
    restore_infcall_control_state.  */
 struct infcall_control_state_deleter
@@ -91,6 +90,8 @@ struct infcall_control_state_deleter
 typedef std::unique_ptr<infcall_control_state, infcall_control_state_deleter>
     infcall_control_state_up;
 
+extern infcall_control_state_up save_infcall_control_state ();
+
 extern void discard_infcall_suspend_state (struct infcall_suspend_state *);
 extern void discard_infcall_control_state (struct infcall_control_state *);
 
index 3c3bb9679bee116deb2cd2f9f5548ac6468f4c53..f1cd85c8ec20ca4bd8bbdbfced9122408cdecbc4 100644 (file)
@@ -8813,10 +8813,9 @@ struct infcall_suspend_state
   gdb::unique_xmalloc_ptr<gdb_byte> siginfo_data;
 };
 
-struct infcall_suspend_state *
-save_infcall_suspend_state (void)
+infcall_suspend_state_up
+save_infcall_suspend_state ()
 {
-  struct infcall_suspend_state *inf_state;
   struct thread_info *tp = inferior_thread ();
   struct regcache *regcache = get_current_regcache ();
   struct gdbarch *gdbarch = regcache->arch ();
@@ -8837,7 +8836,7 @@ save_infcall_suspend_state (void)
        }
     }
 
-  inf_state = new struct infcall_suspend_state;
+  infcall_suspend_state_up inf_state (new struct infcall_suspend_state);
 
   if (siginfo_data)
     {
@@ -8917,10 +8916,10 @@ struct infcall_control_state
 /* Save all of the information associated with the inferior<==>gdb
    connection.  */
 
-struct infcall_control_state *
-save_infcall_control_state (void)
+infcall_control_state_up
+save_infcall_control_state ()
 {
-  struct infcall_control_state *inf_status = new struct infcall_control_state;
+  infcall_control_state_up inf_status (new struct infcall_control_state);
   struct thread_info *tp = inferior_thread ();
   struct inferior *inf = current_inferior ();