From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id OwGAEaBDKGW7EiwAWB0awg (envelope-from ) for ; Thu, 12 Oct 2023 15:06:08 -0400 Received: by simark.ca (Postfix, from userid 112) id 3AB141E0C1; Thu, 12 Oct 2023 15:06:08 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 2B31C1E091 for ; Thu, 12 Oct 2023 15:06:06 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 747303857716 for ; Thu, 12 Oct 2023 19:06:05 +0000 (GMT) Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by sourceware.org (Postfix) with ESMTPS id 84A6E3858C5E for ; Thu, 12 Oct 2023 19:05:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 84A6E3858C5E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4066692ad35so13939015e9.1 for ; Thu, 12 Oct 2023 12:05:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697137547; x=1697742347; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7gKrt0mVbAcMKducs/pLK1PPAPRRgeqvpiUO9vRGJSw=; b=kgIu3yqUeXIY0iP0FIOXRoR5Xdhwy4eYWsb26OuNH7Z9tjN/57dsk7qpwrTOgLIvmf TTqL43XJ/dR5c0VSr7tSEXJZOfsID263Q4UFBzm7YwZ5f5lyX97aBvmtMcymHfzXNo6I WRGSXaYOa/54FMy6X9luYjonSj5k4wbHJBS+ZSiakc8ufhc8GSWZ9FV02afpAnPglqt3 Iu6t9Sn0Uz2Ce5sBSV+qVxc7gU7YnmV/hVFgZyj+fwgq0LGSmUpyheokM5UKv9JWd6M0 pYtruV7PD4Umh0p96zGqE0QHboTico023Ca+zLtZKf4OMum3Qx3pQRXMBOj3iJpqmwyQ vClQ== X-Gm-Message-State: AOJu0Yytbp2dwlp51GabaCdYYLtmxqONGShUQEIcQmJKw1pJLdJ8eTZ8 fdN3FOIOCORSC7hCVmISph5wILS32gKsKw== X-Google-Smtp-Source: AGHT+IEzbowUtFm1L0M93Bz5/V4EMlbqCL/MmqNSYLCCjXm8kXMSYsNkEbciPYKnbm+ARIYVvPENXw== X-Received: by 2002:a05:600c:2146:b0:402:ea96:c09a with SMTP id v6-20020a05600c214600b00402ea96c09amr22779534wml.16.1697137547095; Thu, 12 Oct 2023 12:05:47 -0700 (PDT) Received: from ?IPV6:2001:8a0:f939:d200:dedd:c263:b7d3:9ba1? ([2001:8a0:f939:d200:dedd:c263:b7d3:9ba1]) by smtp.gmail.com with ESMTPSA id v7-20020adfedc7000000b003197efd1e7bsm18905283wro.114.2023.10.12.12.05.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Oct 2023 12:05:46 -0700 (PDT) Message-ID: <1f70b3f3-3291-4115-99e1-948707d9c7a2@palves.net> Date: Thu, 12 Oct 2023 20:05:43 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 06/24] gdbsupport: make intrusive_list's disposer accept a reference Content-Language: en-US To: Simon Marchi , gdb-patches@sourceware.org References: <20231010204213.111285-1-simon.marchi@efficios.com> <20231010204213.111285-7-simon.marchi@efficios.com> From: Pedro Alves In-Reply-To: <20231010204213.111285-7-simon.marchi@efficios.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org On 2023-10-10 21:40, Simon Marchi wrote: > All the API of intrusive_list works with references to item, I'm not > sure why the disposer used in intrusive_list::clear_and_dispose is > different and receives a pointer. Change it to accept a reference > instead. This helps simplify a bit a subsequent patch, and I don't see > any downside to it. The whole intrusive_list API was copied from Boost intrusive_list (not the implementation), so that's where that came from. I assume that the Disposer interface takes a pointer so that it has the same interface as a unique_ptr Deleter, for instance. From a pure disposer/deleter angle, it seems a bit odd to me to have a "delete" operator wrapper take a reference instead of a pointer, leading to code like "delete &ref", FWIW. If this doesn't result in a great tangible improvement, I'd prefer keeping the interface in sync with Boost's. Pedro Alves > > Change-Id: I380886cd4ddaf136fe532eb2744f9e69beb41283 > --- > gdb/inferior.c | 10 +++++----- > gdb/unittests/intrusive_list-selftests.c | 4 ++-- > gdbsupport/intrusive_list.h | 2 +- > 3 files changed, 8 insertions(+), 8 deletions(-) > > diff --git a/gdb/inferior.c b/gdb/inferior.c > index efe57cceae3e..4a55970ccba1 100644 > --- a/gdb/inferior.c > +++ b/gdb/inferior.c > @@ -262,13 +262,13 @@ inferior::find_thread (ptid_t ptid) > void > inferior::clear_thread_list () > { > - thread_list.clear_and_dispose ([=] (thread_info *thr) > + thread_list.clear_and_dispose ([=] (thread_info &thr) > { > threads_debug_printf ("deleting thread %s", > - thr->ptid.to_string ().c_str ()); > - set_thread_exited (thr, {}, true /* silent */); > - if (thr->deletable ()) > - delete thr; > + thr.ptid.to_string ().c_str ()); > + set_thread_exited (&thr, {}, true /* silent */); > + if (thr.deletable ()) > + delete &thr; > }); > ptid_thread_map.clear (); > } > diff --git a/gdb/unittests/intrusive_list-selftests.c b/gdb/unittests/intrusive_list-selftests.c > index 1f85b3266830..d990c0878b35 100644 > --- a/gdb/unittests/intrusive_list-selftests.c > +++ b/gdb/unittests/intrusive_list-selftests.c > @@ -692,9 +692,9 @@ struct intrusive_list_test > list.push_back (b); > list.push_back (c); > > - auto disposer = [&] (const item_type *item) > + auto disposer = [&] (const item_type &item) > { > - disposer_seen.insert (item); > + disposer_seen.insert (&item); > disposer_calls++; > }; > list.clear_and_dispose (disposer); > diff --git a/gdbsupport/intrusive_list.h b/gdbsupport/intrusive_list.h > index 5e9243867d27..aea1922cabee 100644 > --- a/gdbsupport/intrusive_list.h > +++ b/gdbsupport/intrusive_list.h > @@ -513,7 +513,7 @@ class intrusive_list > { > while (!this->empty ()) > { > - pointer p = &front (); > + reference p = front (); > pop_front (); > disposer (p); > }