public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Constify notif_client
@ 2022-12-21 21:16 Tom Tromey
  2023-01-20 17:50 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2022-12-21 21:16 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

It seems to me that a notif_client is read-only, so this patch changes
the code to use "const" everywhere.
---
 gdb/remote-notif.c | 12 ++++++------
 gdb/remote-notif.h | 16 ++++++++--------
 gdb/remote.c       | 22 +++++++++++-----------
 gdb/remote.h       |  2 +-
 4 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/gdb/remote-notif.c b/gdb/remote-notif.c
index 95b45e3f984..a8f4458c27f 100644
--- a/gdb/remote-notif.c
+++ b/gdb/remote-notif.c
@@ -46,7 +46,7 @@ bool notif_debug = false;
 
 /* Supported clients of notifications.  */
 
-static struct notif_client *notifs[] =
+static const notif_client *const notifs[] =
 {
   &notif_client_stop,
 };
@@ -58,7 +58,7 @@ gdb_static_assert (ARRAY_SIZE (notifs) == REMOTE_NOTIF_LAST);
 
 void
 remote_notif_ack (remote_target *remote,
-		  struct notif_client *nc, const char *buf)
+		  const notif_client *nc, const char *buf)
 {
   notif_event_up event = nc->alloc_event ();
 
@@ -74,7 +74,7 @@ remote_notif_ack (remote_target *remote,
 
 struct notif_event *
 remote_notif_parse (remote_target *remote,
-		    struct notif_client *nc, const char *buf)
+		    const notif_client *nc, const char *buf)
 {
   notif_event_up event = nc->alloc_event ();
 
@@ -91,11 +91,11 @@ remote_notif_parse (remote_target *remote,
 
 void
 remote_notif_process (struct remote_notif_state *state,
-		      struct notif_client *except)
+		      const notif_client *except)
 {
   while (!state->notif_queue.empty ())
     {
-      struct notif_client *nc = state->notif_queue.front ();
+      const notif_client *nc = state->notif_queue.front ();
       state->notif_queue.pop_front ();
 
       gdb_assert (nc != except);
@@ -120,7 +120,7 @@ remote_async_get_pending_events_handler (gdb_client_data data)
 void
 handle_notification (struct remote_notif_state *state, const char *buf)
 {
-  struct notif_client *nc;
+  const notif_client *nc;
   size_t i;
 
   for (i = 0; i < ARRAY_SIZE (notifs); i++)
diff --git a/gdb/remote-notif.h b/gdb/remote-notif.h
index db444b049b0..76287d6ebbd 100644
--- a/gdb/remote-notif.h
+++ b/gdb/remote-notif.h
@@ -60,19 +60,19 @@ struct notif_client
      function may throw exception if contents in BUF is not the
      expected event.  */
   void (*parse) (remote_target *remote,
-		 struct notif_client *self, const char *buf,
+		 const notif_client *self, const char *buf,
 		 struct notif_event *event);
 
   /* Send field <ack_command> to remote, and do some checking.  If
      something wrong, throw an exception.  */
   void (*ack) (remote_target *remote,
-	       struct notif_client *self, const char *buf,
+	       const notif_client *self, const char *buf,
 	       struct notif_event *event);
 
   /* Check this notification client can get pending events in
      'remote_notif_process'.  */
   int (*can_get_pending_events) (remote_target *remote,
-				 struct notif_client *self);
+				 const notif_client *self);
 
   /* Allocate an event.  */
   notif_event_up (*alloc_event) ();
@@ -95,7 +95,7 @@ struct remote_notif_state
 
   /* Notification queue.  */
 
-  std::list<notif_client *> notif_queue;
+  std::list<const notif_client *> notif_queue;
 
   /* Asynchronous signal handle registered as event loop source for when
      the remote sent us a notification.  The registered callback
@@ -114,20 +114,20 @@ struct remote_notif_state
   struct notif_event *pending_event[REMOTE_NOTIF_LAST] {};
 };
 
-void remote_notif_ack (remote_target *remote, notif_client *nc,
+void remote_notif_ack (remote_target *remote, const notif_client *nc,
 		       const char *buf);
 struct notif_event *remote_notif_parse (remote_target *remote,
-					notif_client *nc,
+					const notif_client *nc,
 					const char *buf);
 
 void handle_notification (struct remote_notif_state *notif_state,
 			  const char *buf);
 
 void remote_notif_process (struct remote_notif_state *state,
-			   struct notif_client *except);
+			   const notif_client *except);
 remote_notif_state *remote_notif_state_allocate (remote_target *remote);
 
-extern struct notif_client notif_client_stop;
+extern const notif_client notif_client_stop;
 
 extern bool notif_debug;
 
diff --git a/gdb/remote.c b/gdb/remote.c
index ea968ee0c59..62f99b76beb 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -845,7 +845,7 @@ class remote_target : public process_stratum_target
   void send_interrupt_sequence ();
   void interrupt_query ();
 
-  void remote_notif_get_pending_events (notif_client *nc);
+  void remote_notif_get_pending_events (const notif_client *nc);
 
   int fetch_register_using_p (struct regcache *regcache,
 			      packet_reg *reg);
@@ -4996,7 +4996,7 @@ remote_target::start_remote_1 (int from_tty, int extended_p)
 	 mechanism.  */
       if (strcmp (rs->buf.data (), "OK") != 0)
 	{
-	  struct notif_client *notif = &notif_client_stop;
+	  const notif_client *notif = &notif_client_stop;
 
 	  /* remote_notif_get_pending_replies acks this one, and gets
 	     the rest out.  */
@@ -7220,7 +7220,7 @@ remote_target::stop_reply_queue_length ()
 
 static void
 remote_notif_stop_parse (remote_target *remote,
-			 struct notif_client *self, const char *buf,
+			 const notif_client *self, const char *buf,
 			 struct notif_event *event)
 {
   remote->remote_parse_stop_reply (buf, (struct stop_reply *) event);
@@ -7228,7 +7228,7 @@ remote_notif_stop_parse (remote_target *remote,
 
 static void
 remote_notif_stop_ack (remote_target *remote,
-		       struct notif_client *self, const char *buf,
+		       const notif_client *self, const char *buf,
 		       struct notif_event *event)
 {
   struct stop_reply *stop_reply = (struct stop_reply *) event;
@@ -7245,7 +7245,7 @@ remote_notif_stop_ack (remote_target *remote,
 
 static int
 remote_notif_stop_can_get_pending_events (remote_target *remote,
-					  struct notif_client *self)
+					  const notif_client *self)
 {
   /* We can't get pending events in remote_notif_process for
      notification stop, and we have to do this in remote_wait_ns
@@ -7271,7 +7271,7 @@ remote_notif_stop_alloc_reply ()
 
 /* A client of notification Stop.  */
 
-struct notif_client notif_client_stop =
+const notif_client notif_client_stop =
 {
   "Stop",
   "vStopped",
@@ -7291,7 +7291,7 @@ struct notif_client notif_client_stop =
 void
 remote_target::remove_new_fork_children (threads_listing_context *context)
 {
-  struct notif_client *notif = &notif_client_stop;
+  const notif_client *notif = &notif_client_stop;
 
   /* For any threads stopped at a fork event, remove the corresponding
      fork child threads from the CONTEXT list.  */
@@ -7327,7 +7327,7 @@ void
 remote_target::check_pending_events_prevent_wildcard_vcont
   (bool *may_global_wildcard)
 {
-  struct notif_client *notif = &notif_client_stop;
+  const notif_client *notif = &notif_client_stop;
 
   remote_notif_get_pending_events (notif);
   for (auto &event : get_remote_state ()->stop_reply_queue)
@@ -7897,7 +7897,7 @@ Packet: '%s'\n"),
 */
 
 void
-remote_target::remote_notif_get_pending_events (notif_client *nc)
+remote_target::remote_notif_get_pending_events (const notif_client *nc)
 {
   struct remote_state *rs = get_remote_state ();
 
@@ -7935,7 +7935,7 @@ remote_target::remote_notif_get_pending_events (notif_client *nc)
    avoid having to export the whole remote_target class.  */
 
 void
-remote_notif_get_pending_events (remote_target *remote, notif_client *nc)
+remote_notif_get_pending_events (remote_target *remote, const notif_client *nc)
 {
   remote->remote_notif_get_pending_events (nc);
 }
@@ -10059,7 +10059,7 @@ void
 remote_target::kill_new_fork_children (inferior *inf)
 {
   remote_state *rs = get_remote_state ();
-  struct notif_client *notif = &notif_client_stop;
+  const notif_client *notif = &notif_client_stop;
 
   /* Kill the fork child threads of any threads in inferior INF that are stopped
      at a fork event.  */
diff --git a/gdb/remote.h b/gdb/remote.h
index 638ffc2e337..a2d0a0266df 100644
--- a/gdb/remote.h
+++ b/gdb/remote.h
@@ -78,7 +78,7 @@ extern int remote_register_number_and_offset (struct gdbarch *gdbarch,
 					      int *poffset);
 
 extern void remote_notif_get_pending_events (remote_target *remote,
-					     struct notif_client *np);
+					     const notif_client *np);
 extern bool remote_target_is_non_stop_p (remote_target *t);
 
 /* An abstract class that represents the set of callbacks that are made
-- 
2.38.1


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

* Re: [PATCH] Constify notif_client
  2022-12-21 21:16 [PATCH] Constify notif_client Tom Tromey
@ 2023-01-20 17:50 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2023-01-20 17:50 UTC (permalink / raw)
  To: Tom Tromey via Gdb-patches; +Cc: Tom Tromey

>>>>> "Tom" == Tom Tromey via Gdb-patches <gdb-patches@sourceware.org> writes:

Tom> It seems to me that a notif_client is read-only, so this patch changes
Tom> the code to use "const" everywhere.

I'm checking this in.

Tom

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

end of thread, other threads:[~2023-01-20 17:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-21 21:16 [PATCH] Constify notif_client Tom Tromey
2023-01-20 17:50 ` Tom Tromey

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