[PATCH 2/2] Class-ify ptid_t
Pedro Alves
palves@redhat.com
Thu Apr 6 11:06:00 GMT 2017
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
More information about the Gdb-patches
mailing list