From patchwork Thu Apr 6 11:06:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 19879 Received: (qmail 68670 invoked by alias); 6 Apr 2017 11:06:37 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 68647 invoked by uid 89); 6 Apr 2017 11:06:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.2 spammy=Though, 6512 X-HELO: mail-wr0-f177.google.com Received: from mail-wr0-f177.google.com (HELO mail-wr0-f177.google.com) (209.85.128.177) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 06 Apr 2017 11:06:35 +0000 Received: by mail-wr0-f177.google.com with SMTP id w11so52529888wrc.3 for ; Thu, 06 Apr 2017 04:06:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=OF/FDATITmju2xgmd2KEVPZpKSgvrVI+gPRg16kZxkc=; b=tmxbJ6RalJo/Jd73JoJNGKJQemujKOuDxpJXc27mJOEF6nzm5e8dS4YtczKPXvTEUJ hxgM8yUHPkwFNKO4JGCxLfXQItprlGGug40CBzPZtI5W6Sk7tLnU/m1ONIOBGHAKC9fS xoSeJWwIMajNELK6vUDzZnJvHioz1fY+IE72zwD4zQabAe1Gk3p9sOhLHyK1pKLAVsYk +oeWux7rHPsQnA6s6hZwRo7Hbc2jDkVpmugHtiB2RmLxsdO2ywnoVeMvYgarSXFYLByM 2VbirQ945nNy2K6hTrb/Bi4yYqs4QtzUcwv+B6jubqDXxbvuUoAhW581wo7ocQwP5qSN qisQ== X-Gm-Message-State: AFeK/H3EDrGmoHK5pth7ZGRXxfwqa3MGY6wIfbVEatqp6jkouAkqWTcKFYF7uE4St+bu1xJ8 X-Received: by 10.223.179.195 with SMTP id x3mr25114911wrd.80.1491476793405; Thu, 06 Apr 2017 04:06:33 -0700 (PDT) Received: from [192.168.0.101] ([37.189.166.198]) by smtp.gmail.com with ESMTPSA id x127sm26078231wmf.31.2017.04.06.04.06.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Apr 2017 04:06:32 -0700 (PDT) Subject: Re: [PATCH 2/2] Class-ify ptid_t To: Simon Marchi References: <20170404183235.10589-1-simon.marchi@ericsson.com> <20170404183235.10589-2-simon.marchi@ericsson.com> <580e9a8a-d59b-095c-cf56-ee2f50fe46df@redhat.com> <84b33a5c655af3f344494c9e9ee473d6@polymtl.ca> <137a70edf29ba47b7d1d332e18ba3b94@polymtl.ca> Cc: Simon Marchi , gdb-patches@sourceware.org From: Pedro Alves Message-ID: <30ba1984-b410-e162-a25c-116f57662e71@redhat.com> Date: Thu, 6 Apr 2017 12:06:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 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 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;