public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH v2 18/31] Convert ada-tasks.c to type-safe registry API
Date: Fri, 03 May 2019 23:12:00 -0000	[thread overview]
Message-ID: <20190503231231.8954-19-tom@tromey.com> (raw)
In-Reply-To: <20190503231231.8954-1-tom@tromey.com>

This changes ada-tasks.c to use the type-safe registry API.

2019-05-01  Tom Tromey  <tom@tromey.com>

	* ada-tasks.c (ada_tasks_pspace_data_handle): Change type.
	(get_ada_tasks_pspace_data): Update.
	(ada_tasks_pspace_data_cleanup): Remove.
	(_initialize_tasks): Update.
	(ada_tasks_inferior_data_handle): Change type.
	(get_ada_tasks_inferior_data): Update.
	(ada_tasks_inferior_data_cleanup): Remove.
	(struct ada_tasks_pspace_data): Add initializers.
---
 gdb/ChangeLog   | 11 +++++++++
 gdb/ada-tasks.c | 59 ++++++++++++-------------------------------------
 2 files changed, 25 insertions(+), 45 deletions(-)

diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c
index ccabc631040..762fb868e75 100644
--- a/gdb/ada-tasks.c
+++ b/gdb/ada-tasks.c
@@ -142,35 +142,27 @@ struct ada_tasks_pspace_data
   /* Nonzero if the data has been initialized.  If set to zero,
      it means that the data has either not been initialized, or
      has potentially become stale.  */
-  int initialized_p;
+  int initialized_p = 0;
 
   /* The ATCB record type.  */
-  struct type *atcb_type;
+  struct type *atcb_type = nullptr;
 
   /* The ATCB "Common" component type.  */
-  struct type *atcb_common_type;
+  struct type *atcb_common_type = nullptr;
 
   /* The type of the "ll" field, from the atcb_common_type.  */
-  struct type *atcb_ll_type;
+  struct type *atcb_ll_type = nullptr;
 
   /* The type of the "call" field, from the atcb_common_type.  */
-  struct type *atcb_call_type;
+  struct type *atcb_call_type = nullptr;
 
   /* The index of various fields in the ATCB record and sub-records.  */
-  struct atcb_fieldnos atcb_fieldno;
+  struct atcb_fieldnos atcb_fieldno {};
 };
 
 /* Key to our per-program-space data.  */
-static const struct program_space_data *ada_tasks_pspace_data_handle;
-
-/* A cleanup routine for our per-program-space data.  */
-static void
-ada_tasks_pspace_data_cleanup (struct program_space *pspace, void *arg)
-{
-  struct ada_tasks_pspace_data *data
-    = (struct ada_tasks_pspace_data *) arg;
-  xfree (data);
-}
+static const struct program_space_key<ada_tasks_pspace_data>
+  ada_tasks_pspace_data_handle;
 
 /* The kind of data structure used by the runtime to store the list
    of Ada tasks.  */
@@ -245,7 +237,8 @@ struct ada_tasks_inferior_data
 };
 
 /* Key to our per-inferior data.  */
-static const struct inferior_data *ada_tasks_inferior_data_handle;
+static const struct inferior_key<ada_tasks_inferior_data>
+  ada_tasks_inferior_data_handle;
 
 /* Return the ada-tasks module's data for the given program space (PSPACE).
    If none is found, add a zero'ed one now.
@@ -257,13 +250,9 @@ get_ada_tasks_pspace_data (struct program_space *pspace)
 {
   struct ada_tasks_pspace_data *data;
 
-  data = ((struct ada_tasks_pspace_data *)
-	  program_space_data (pspace, ada_tasks_pspace_data_handle));
+  data = ada_tasks_pspace_data_handle.get (pspace);
   if (data == NULL)
-    {
-      data = XCNEW (struct ada_tasks_pspace_data);
-      set_program_space_data (pspace, ada_tasks_pspace_data_handle, data);
-    }
+    data = ada_tasks_pspace_data_handle.emplace (pspace);
 
   return data;
 }
@@ -285,26 +274,13 @@ get_ada_tasks_inferior_data (struct inferior *inf)
 {
   struct ada_tasks_inferior_data *data;
 
-  data = ((struct ada_tasks_inferior_data *)
-	  inferior_data (inf, ada_tasks_inferior_data_handle));
+  data = ada_tasks_inferior_data_handle.get (inf);
   if (data == NULL)
-    {
-      data = new ada_tasks_inferior_data;
-      set_inferior_data (inf, ada_tasks_inferior_data_handle, data);
-    }
+    data = ada_tasks_inferior_data_handle.emplace (inf);
 
   return data;
 }
 
-/* A cleanup routine for our per-inferior data.  */
-static void
-ada_tasks_inferior_data_cleanup (struct inferior *inf, void *arg)
-{
-  struct ada_tasks_inferior_data *data
-    = (struct ada_tasks_inferior_data *) arg;
-  delete data;
-}
-
 /* Return the task number of the task whose thread is THREAD, or zero
    if the task could not be found.  */
 
@@ -1431,13 +1407,6 @@ ada_tasks_new_objfile_observer (struct objfile *objfile)
 void
 _initialize_tasks (void)
 {
-  ada_tasks_pspace_data_handle
-    = register_program_space_data_with_cleanup (NULL,
-						ada_tasks_pspace_data_cleanup);
-  ada_tasks_inferior_data_handle
-    = register_inferior_data_with_cleanup (NULL,
-					   ada_tasks_inferior_data_cleanup);
-
   /* Attach various observers.  */
   gdb::observers::normal_stop.attach (ada_tasks_normal_stop_observer);
   gdb::observers::new_objfile.attach (ada_tasks_new_objfile_observer);
-- 
2.17.2

  parent reply	other threads:[~2019-05-03 23:12 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-03 23:12 [PATCH v2 00/31] Add a type-safe API to registries Tom Tromey
2019-05-03 23:12 ` [PATCH v2 16/31] Convert xcoffread.c to type-safe registry API Tom Tromey
2019-05-03 23:12 ` [PATCH v2 25/31] Convert elfread.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 03/31] Convert symbol_cache " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 21/31] Convert ada-lang.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 06/31] Convert break-catch-syscall.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 17/31] Convert probes " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 05/31] Convert inflow " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 23/31] Add a noop deleter Tom Tromey
2019-05-03 23:12 ` [PATCH v2 15/31] Convert solib-svr4.c to type-safe registry API Tom Tromey
2019-05-03 23:12 ` [PATCH v2 01/31] Add a type-safe C++ interface to a registry Tom Tromey
2019-05-03 23:12 ` [PATCH v2 24/31] Convert mdebugread.c to type-safe registry API Tom Tromey
2019-05-03 23:12 ` [PATCH v2 13/31] Convert breakpoint.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 12/31] Convert linux-tdep.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 08/31] Convert auto-load.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 07/31] Convert objfiles.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 19/31] Convert fbsd-tdep.c " Tom Tromey
2019-05-06 20:56   ` John Baldwin
2019-05-08 17:58     ` Tom Tromey
2019-05-08 22:06       ` Tom Tromey
2019-05-03 23:12 ` [PATCH v2 10/31] Convert symfile-debug.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 20/31] Convert coffread.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 04/31] Convert target dcache " Tom Tromey
2019-05-03 23:12 ` Tom Tromey [this message]
2019-05-03 23:13 ` [PATCH v2 11/31] Convert auxv.c " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 28/31] Convert stabsread.c " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 02/31] Convert main_info " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 27/31] Remove mips_pdr_data Tom Tromey
2019-05-03 23:13 ` [PATCH v2 29/31] Convert objc-lang.c to type-safe registry API Tom Tromey
2019-05-03 23:13 ` [PATCH v2 26/31] Convert hppa-tdep.c " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 09/31] Convert dwarf2_per_objfile " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 14/31] Convert remote.c " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 22/31] Convert nto-tdep.c " Tom Tromey
2019-05-03 23:31 ` [PATCH v2 30/31] Convert dwarf2-frame.c " Tom Tromey
2019-05-03 23:31 ` [PATCH v2 31/31] Convert gdbtypes.c " Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190503231231.8954-19-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).