public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Use new and delete in jit.c
@ 2022-04-05 20:45 Tom Tromey
  2022-04-05 21:18 ` John Baldwin
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2022-04-05 20:45 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes jit.c to use new and delete, rather than XCNEW.  This
simplifies the code a little.  This was useful for another patch I'm
working on, and I thought it would make sense to send it separately.

Regression tested on x86-64 Fedora 34.
---
 gdb/jit.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/gdb/jit.c b/gdb/jit.c
index a727143e68b..342b0d07114 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -935,7 +935,7 @@ struct jit_unwind_private
 {
   /* Cached register values.  See jit_frame_sniffer to see how this
      works.  */
-  detached_regcache *regcache;
+  std::unique_ptr<detached_regcache> regcache;
 
   /* The frame being unwound.  */
   struct frame_info *this_frame;
@@ -1002,10 +1002,7 @@ static void
 jit_dealloc_cache (struct frame_info *this_frame, void *cache)
 {
   struct jit_unwind_private *priv_data = (struct jit_unwind_private *) cache;
-
-  gdb_assert (priv_data->regcache != NULL);
-  delete priv_data->regcache;
-  xfree (priv_data);
+  delete priv_data;
 }
 
 /* The frame sniffer for the pseudo unwinder.
@@ -1035,11 +1032,11 @@ jit_frame_sniffer (const struct frame_unwind *self,
 
   gdb_assert (!*cache);
 
-  *cache = XCNEW (struct jit_unwind_private);
-  priv_data = (struct jit_unwind_private *) *cache;
+  priv_data = new struct jit_unwind_private;
+  *cache = priv_data;
   /* Take a snapshot of current regcache.  */
-  priv_data->regcache = new detached_regcache (get_frame_arch (this_frame),
-					       true);
+  priv_data->regcache.reset
+    (new detached_regcache (get_frame_arch (this_frame), true));
   priv_data->this_frame = this_frame;
 
   callbacks.priv_data = priv_data;
@@ -1072,7 +1069,7 @@ jit_frame_this_id (struct frame_info *this_frame, void **cache,
   struct gdb_reader_funcs *funcs;
   struct gdb_unwind_callbacks callbacks;
 
-  priv.regcache = NULL;
+  priv.regcache.reset ();
   priv.this_frame = this_frame;
 
   /* We don't expect the frame_id function to set any registers, so we
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Use new and delete in jit.c
  2022-04-05 20:45 [PATCH] Use new and delete in jit.c Tom Tromey
@ 2022-04-05 21:18 ` John Baldwin
  0 siblings, 0 replies; 2+ messages in thread
From: John Baldwin @ 2022-04-05 21:18 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 4/5/22 1:45 PM, Tom Tromey wrote:
> This changes jit.c to use new and delete, rather than XCNEW.  This
> simplifies the code a little.  This was useful for another patch I'm
> working on, and I thought it would make sense to send it separately.
> 
> Regression tested on x86-64 Fedora 34.

LGTM.

-- 
John Baldwin

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-05 21:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-05 20:45 [PATCH] Use new and delete in jit.c Tom Tromey
2022-04-05 21:18 ` John Baldwin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).