Patchwork [RFA,3/5] Use new and delete for struct infcall_control_state

login
register
mail settings
Submitter Tom Tromey
Date July 11, 2018, 2:15 p.m.
Message ID <20180711141552.10136-4-tom@tromey.com>
Download mbox | patch
Permalink /patch/28314/
State New
Headers show

Comments

Tom Tromey - July 11, 2018, 2:15 p.m.
This changes infrun.c to use new and delete for infcall_control_state.

gdb/ChangeLog
2018-07-11  Tom Tromey  <tom@tromey.com>

	* infrun.c (struct infcall_control_state): Add initializers.
	(save_infcall_control_state): Use new.
	(restore_infcall_control_state, discard_infcall_control_state):
	Use delete.
---
 gdb/ChangeLog |  7 +++++++
 gdb/infrun.c  | 17 ++++++++---------
 2 files changed, 15 insertions(+), 9 deletions(-)
Simon Marchi - July 11, 2018, 3:36 p.m.
On 2018-07-11 10:15, Tom Tromey wrote:
> diff --git a/gdb/infrun.c b/gdb/infrun.c
> index 1157b266b1a..3bc8dc03830 100644
> --- a/gdb/infrun.c
> +++ b/gdb/infrun.c
> @@ -8927,15 +8927,15 @@ get_infcall_suspend_state_regcache (struct
> infcall_suspend_state *inf_state)
> 
>  struct infcall_control_state
>  {
> -  struct thread_control_state thread_control;
> -  struct inferior_control_state inferior_control;
> +  struct thread_control_state thread_control {};
> +  struct inferior_control_state inferior_control {};

Same here, you could remove the {} here and make the 
thread/inferior_control_state objects initialize themselves.  
thread_info::control and thread_info::suspend then won't need to be 
explicitly initialized.

Simon
Simon Marchi - July 11, 2018, 3:42 p.m.
On 2018-07-11 11:36, Simon Marchi wrote:
> On 2018-07-11 10:15, Tom Tromey wrote:
>> diff --git a/gdb/infrun.c b/gdb/infrun.c
>> index 1157b266b1a..3bc8dc03830 100644
>> --- a/gdb/infrun.c
>> +++ b/gdb/infrun.c
>> @@ -8927,15 +8927,15 @@ get_infcall_suspend_state_regcache (struct
>> infcall_suspend_state *inf_state)
>> 
>>  struct infcall_control_state
>>  {
>> -  struct thread_control_state thread_control;
>> -  struct inferior_control_state inferior_control;
>> +  struct thread_control_state thread_control {};
>> +  struct inferior_control_state inferior_control {};
> 
> Same here, you could remove the {} here and make the
> thread/inferior_control_state objects initialize themselves.
> thread_info::control and thread_info::suspend then won't need to be
> explicitly initialized.

You probably got it anyway, but the last sentence should have said 
inferior::control and thread_info::control.

Simon

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d46ccf53999..95d4f51f62c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@ 
+2018-07-11  Tom Tromey  <tom@tromey.com>
+
+	* infrun.c (struct infcall_control_state): Add initializers.
+	(save_infcall_control_state): Use new.
+	(restore_infcall_control_state, discard_infcall_control_state):
+	Use delete.
+
 2018-07-11  Tom Tromey  <tom@tromey.com>
 
 	* infrun.c (struct infcall_suspend_state) <registers>: Now a
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 1157b266b1a..3bc8dc03830 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -8927,15 +8927,15 @@  get_infcall_suspend_state_regcache (struct infcall_suspend_state *inf_state)
 
 struct infcall_control_state
 {
-  struct thread_control_state thread_control;
-  struct inferior_control_state inferior_control;
+  struct thread_control_state thread_control {};
+  struct inferior_control_state inferior_control {};
 
   /* Other fields:  */
-  enum stop_stack_kind stop_stack_dummy;
-  int stopped_by_random_signal;
+  enum stop_stack_kind stop_stack_dummy = STOP_NONE;
+  int stopped_by_random_signal = 0;
 
   /* ID if the selected frame when the inferior function call was made.  */
-  struct frame_id selected_frame_id;
+  struct frame_id selected_frame_id {};
 };
 
 /* Save all of the information associated with the inferior<==>gdb
@@ -8944,8 +8944,7 @@  struct infcall_control_state
 struct infcall_control_state *
 save_infcall_control_state (void)
 {
-  struct infcall_control_state *inf_status =
-    XNEW (struct infcall_control_state);
+  struct infcall_control_state *inf_status = new struct infcall_control_state;
   struct thread_info *tp = inferior_thread ();
   struct inferior *inf = current_inferior ();
 
@@ -9031,7 +9030,7 @@  restore_infcall_control_state (struct infcall_control_state *inf_status)
       END_CATCH
     }
 
-  xfree (inf_status);
+  delete inf_status;
 }
 
 static void
@@ -9061,7 +9060,7 @@  discard_infcall_control_state (struct infcall_control_state *inf_status)
   /* See save_infcall_control_state for info on stop_bpstat.  */
   bpstat_clear (&inf_status->thread_control.stop_bpstat);
 
-  xfree (inf_status);
+  delete inf_status;
 }
 
 /* See infrun.h.  */