Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: Simon Marchi <simon.marchi@ericsson.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 2/2] Class-ify ptid_t
Date: Thu, 06 Apr 2017 11:06:00 -0000	[thread overview]
Message-ID: <30ba1984-b410-e162-a25c-116f57662e71@redhat.com> (raw)
In-Reply-To: <137a70edf29ba47b7d1d332e18ba3b94@polymtl.ca>

On 04/06/2017 04:09 AM, Simon Marchi wrote:

> constexpr ptid_t null_ptid = NULL_PTID;
> constexpr ptid_t minus_one_ptid = MINUS_ONE_PTID;
> 
> /* We don't want anybody using these macros, they are just temporary.
> #undef NULL_PTID
> #undef MINUS_ONE_PTID
> 
> What do you think?

I think we can avoid the macros.  :-)

Instead, add constexpr functions that make null/any instances, and
call those to initialize the null_ptid/minus_one_ptid globals.

See patchlet below.

> 
> Now, making null_ptid/minus_one_ptid constexpr brings its share of
> fallouts, such as:
> 
> /home/simark/src/binutils-gdb/gdb/linux-nat.c: In function ‘void
> linux_unstop_all_lwps()Â’:
> /home/simark/src/binutils-gdb/gdb/linux-nat.c:2387:37: error: invalid
> conversion from ‘const void*’ to ‘void*’ [-fpermissive]
>         resume_stopped_resumed_lwps, &minus_one_ptid);
>                                      ^~~~~~~~~~~~~~~
> /home/simark/src/binutils-gdb/gdb/linux-nat.c:980:1: note:  
> initializing argument 3 of ‘lwp_info* iterate_over_lwps(ptid_t, int
> (*)(lwp_info*, void*), void*)Â’
>  iterate_over_lwps (ptid_t filter,
>  ^~~~~~~~~~~~~~~~~
> 
> But it looks easy enough to fix by C++-ifying/modernizing
> iterate_over_lwps.

Guess making null_ptid/minus_one_ptid const (even if we avoid
constexpr) would make sense anyway.  Though it's not a huge deal
since the type has no mutating methods in any case.

In any case, I'd be totally fine with modernizing iterate_over_lwps.

From 36aba913c112e0790e7bb832e3010999372c465e Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Thu, 6 Apr 2017 11:50:50 +0100
Subject: [PATCH] make_null

---
 gdb/common/ptid.c |  8 ++++++--
 gdb/common/ptid.h | 10 ++++++++--
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/gdb/common/ptid.c b/gdb/common/ptid.c
index dff0071..d721605 100644
--- a/gdb/common/ptid.c
+++ b/gdb/common/ptid.c
@@ -22,9 +22,13 @@
 
 /* See ptid.h for these.  */
 
-ptid_t null_ptid = ptid_t (0, 0, 0);
-ptid_t minus_one_ptid = ptid_t (-1, 0, 0);
+ptid_t null_ptid = ptid_t::make_null ();
+ptid_t minus_one_ptid = ptid_t::make_any ();
 
+static_assert (ptid_t::make_null ().is_null (), "");
+static_assert (ptid_t::make_any ().is_any (), "");
+static_assert (!ptid_t::make_null ().is_any (), "");
+static_assert (!ptid_t::make_any ().is_null (), "");
 
 /* See ptid.h.  */
 
diff --git a/gdb/common/ptid.h b/gdb/common/ptid.h
index 12d43aa..67e8bad 100644
--- a/gdb/common/ptid.h
+++ b/gdb/common/ptid.h
@@ -65,12 +65,12 @@ public:
 
   constexpr bool is_null () const
   {
-    return *this == null_ptid;
+    return *this == make_null ();
   }
 
   constexpr bool is_any () const
   {
-    return *this == minus_one_ptid;
+    return *this == make_any ();
   }
 
   constexpr int pid () const
@@ -108,6 +108,12 @@ public:
 	    || *this == filter);
   }
 
+  static constexpr ptid_t make_null ()
+  { return {0, 0, 0}; }
+
+  static constexpr ptid_t make_any ()
+  { return {-1, 0, 0}; }
+
 private:
   /* Process id.  */
   int m_pid;
-- 
2.5.5



  reply	other threads:[~2017-04-06 11:06 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-04 18:32 [PATCH 1/2] ptid_{lwp,tid}_p: Remove unnecessary checks Simon Marchi
2017-04-04 18:33 ` [PATCH 2/2] Class-ify ptid_t Simon Marchi
2017-04-05 15:47   ` Pedro Alves
2017-04-05 19:44     ` Simon Marchi
2017-04-05 21:31       ` Pedro Alves
2017-04-06  2:15         ` Simon Marchi
2017-04-06 10:49           ` Pedro Alves
2017-04-06 11:12             ` Pedro Alves
2017-04-06 14:32               ` Simon Marchi
2017-04-06 14:38                 ` Pedro Alves
2017-04-06  3:09         ` Simon Marchi
2017-04-06 11:06           ` Pedro Alves [this message]
2017-04-05 15:15 ` [PATCH 1/2] ptid_{lwp,tid}_p: Remove unnecessary checks Pedro Alves
2017-04-05 19:21   ` Simon Marchi

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=30ba1984-b410-e162-a25c-116f57662e71@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@ericsson.com \
    --cc=simon.marchi@polymtl.ca \
    /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