public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Simplify hppa-tdep.c use of objfile_key
@ 2022-03-05  0:17 Tom Tromey
  2022-03-06 16:31 ` Simon Marchi
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2022-03-05  0:17 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

I happened to notice a couple of unnecessary casts in hppa-tdep.c, and
then I saw that the use of objfile_key could be simplified -- removing
some code and using the default deleter rather than noop_deleter.

Tested by rebuilding.  Let me know what you think.
---
 gdb/hppa-tdep.c | 33 ++++++++++-----------------------
 1 file changed, 10 insertions(+), 23 deletions(-)

diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
index 760cb1bea13..cf84555a28c 100644
--- a/gdb/hppa-tdep.c
+++ b/gdb/hppa-tdep.c
@@ -70,12 +70,12 @@ struct hppa_unwind_info
 
 struct hppa_objfile_private
   {
-    struct hppa_unwind_info *unwind_info;	/* a pointer */
-    struct so_list *so_info;			/* a pointer  */
-    CORE_ADDR dp;
+    struct hppa_unwind_info *unwind_info = nullptr;	/* a pointer */
+    struct so_list *so_info = nullptr;			/* a pointer  */
+    CORE_ADDR dp = 0;
 
-    int dummy_call_sequence_reg;
-    CORE_ADDR dummy_call_sequence_addr;
+    int dummy_call_sequence_reg = 0;
+    CORE_ADDR dummy_call_sequence_addr = 0;
   };
 
 /* hppa-specific object data -- unwind and solib info.
@@ -84,9 +84,7 @@ struct hppa_objfile_private
    that separately and make this static. The solib data is probably hpux-
    specific, so we can create a separate extern objfile_data that is registered
    by hppa-hpux-tdep.c and shared with pa64solib.c and somsolib.c.  */
-static const struct objfile_key<hppa_objfile_private,
-				gdb::noop_deleter<hppa_objfile_private>>
-  hppa_objfile_priv_data;
+static const struct objfile_key<hppa_objfile_private> hppa_objfile_priv_data;
 
 /* Get at various relevant fields of an instruction word.  */
 #define MASK_5 0x1f
@@ -204,16 +202,6 @@ hppa_symbol_address(const char *sym)
     return (CORE_ADDR)-1;
 }
 
-static struct hppa_objfile_private *
-hppa_init_objfile_priv_data (struct objfile *objfile)
-{
-  hppa_objfile_private *priv
-    = OBSTACK_ZALLOC (&objfile->objfile_obstack, hppa_objfile_private);
-
-  hppa_objfile_priv_data.set (objfile, priv);
-
-  return priv;
-}
 \f
 
 /* Compare the start address for two unwind entries returning 1 if 
@@ -471,7 +459,7 @@ read_unwind_info (struct objfile *objfile)
   /* Keep a pointer to the unwind information.  */
   obj_private = hppa_objfile_priv_data.get (objfile);
   if (obj_private == NULL)
-    obj_private = hppa_init_objfile_priv_data (objfile);
+    obj_private = hppa_objfile_priv_data.emplace (objfile);
 
   obj_private->unwind_info = ui;
 }
@@ -485,7 +473,6 @@ struct unwind_table_entry *
 find_unwind_entry (CORE_ADDR pc)
 {
   int first, middle, last;
-  struct hppa_objfile_private *priv;
 
   if (hppa_debug)
     fprintf_unfiltered (gdb_stdlog, "{ find_unwind_entry %s -> ",
@@ -503,9 +490,9 @@ find_unwind_entry (CORE_ADDR pc)
     {
       struct hppa_unwind_info *ui;
       ui = NULL;
-      priv = hppa_objfile_priv_data.get (objfile);
+      struct hppa_objfile_private *priv = hppa_objfile_priv_data.get (objfile);
       if (priv)
-	ui = ((struct hppa_objfile_private *) priv)->unwind_info;
+	ui = priv->unwind_info;
 
       if (!ui)
 	{
@@ -513,7 +500,7 @@ find_unwind_entry (CORE_ADDR pc)
 	  priv = hppa_objfile_priv_data.get (objfile);
 	  if (priv == NULL)
 	    error (_("Internal error reading unwind information."));
-	  ui = ((struct hppa_objfile_private *) priv)->unwind_info;
+	  ui = priv->unwind_info;
 	}
 
       /* First, check the cache.  */
-- 
2.34.1


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

* Re: [PATCH] Simplify hppa-tdep.c use of objfile_key
  2022-03-05  0:17 [PATCH] Simplify hppa-tdep.c use of objfile_key Tom Tromey
@ 2022-03-06 16:31 ` Simon Marchi
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Marchi @ 2022-03-06 16:31 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches



On 2022-03-04 19:17, Tom Tromey wrote:
> I happened to notice a couple of unnecessary casts in hppa-tdep.c, and
> then I saw that the use of objfile_key could be simplified -- removing
> some code and using the default deleter rather than noop_deleter.
> 
> Tested by rebuilding.  Let me know what you think.

LGTM.

Simon

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

end of thread, other threads:[~2022-03-06 16:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-05  0:17 [PATCH] Simplify hppa-tdep.c use of objfile_key Tom Tromey
2022-03-06 16:31 ` Simon Marchi

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).