From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8653 invoked by alias); 6 Apr 2017 22:23:22 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 8631 invoked by uid 89); 6 Apr 2017 22:23:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=lax, card X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 06 Apr 2017 22:23:20 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5D8AC8049B; Thu, 6 Apr 2017 22:23:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5D8AC8049B Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5D8AC8049B Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 612C617B8A; Thu, 6 Apr 2017 22:23:19 +0000 (UTC) Subject: Re: [PATCH v2] Class-ify ptid_t To: Simon Marchi , gdb-patches@sourceware.org References: <20170406190328.21103-1-simon.marchi@ericsson.com> From: Pedro Alves Message-ID: <78ec4cd7-8a6e-d757-cb1f-de7e3bb52aab@redhat.com> Date: Thu, 06 Apr 2017 22:23:00 -0000 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: <20170406190328.21103-1-simon.marchi@ericsson.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-04/txt/msg00150.txt.bz2 On 04/06/2017 08:03 PM, Simon Marchi wrote: > -struct ptid > +class ptid_t > { > +public: > + /* Must have a trivial defaulted default constructor so that the > + type remains POD. */ > + ptid_t () noexcept = default; > + > + /* Make a ptid given the necessary PID, LWP, and TID components. > + > + A ptid with only a PID (LWP and TID equal to zero) is usually used to > + represent a whole process, including all its lwps/threads. */ > + > + constexpr ptid_t (int pid, long lwp = 0, long tid = 0) > + : m_pid (pid), m_lwp (lwp), m_tid (tid) > + {} Hmm, I just realized that due to the default arguments, this results in an implicit ctor from int, which doesn't sound like a good idea to me. I.e., this bug would compile: void foo (ptid_t ptid); void bar (int lwpid) { foo (lwpid); // automatically constructs a (pid,0,0) ptid. } So I think we should make that ctor explicit, and add another assertion to the unit tests: static_assert (!std::is_convertible::value, ""); > + > + /* Returns true if the ptid matches FILTER. FILTER can be the wild > + card MINUS_ONE_PTID (all ptid match it); can be a ptid representing "all ptids" > + a process (ptid_is_pid returns true), in which case, all lwps and "ptid.is_pid ()" ? > + threads of that given process match, lwps and threads of other > + processes do not; or, it can represent a specific thread, in which > + case, only that thread will match true. The ptid must represent a > + specific LWP or THREAD, it can never be a wild card. */ > + > + constexpr bool matches (const ptid_t &filter) const > + { > + return (/* If filter represents any ptid, it's always a match. */ > + filter == make_minus_one () > + /* If filter is only a pid, any ptid with that pid > + matches. */ > + || (filter.is_pid () && m_pid == filter.pid ()) > + > + /* Otherwise, this ptid only matches if it's exactly equal > + to filter. */ > + || *this == filter); > + } > + > + /* Make a null ptid. */ > + > + static constexpr ptid_t > + make_null () > + { return {0, 0, 0}; } > + > + /* Make a minus one ptid. */ > + > + static constexpr ptid_t > + make_minus_one () > + { return {-1, 0, 0}; } I find it a bit odd to break the line after the return type in these two, when we don't break it in non-static members. > +#include "defs.h" > +#include "common/ptid.h" > +#include > + > +namespace selftests { > +namespace ptid { > + > +/* Check that the ptid_t class is POD. > + > + This isn't a strict requirement. If we have a good reason to change it to > + a non-POD type, we can remove this check. */ Hmm, I think this comment too lax. There _is_ a reason this type must remain POD for the time being. So I think that's what we should say here: /* Check that the ptid_t class is POD. This is a requirement for a long as we have ptids embedded in structures allocated with malloc. */ > + > +static_assert (std::is_pod::value, "ptid_t is POD"); > + Otherwise looks good to me. Please push. Thanks, Pedro Alves