From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by sourceware.org (Postfix) with ESMTPS id D43C23831384 for ; Tue, 22 Aug 2023 14:43:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D43C23831384 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-wr1-f51.google.com with SMTP id ffacd0b85a97d-319559fd67dso4234887f8f.3 for ; Tue, 22 Aug 2023 07:43:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692715408; x=1693320208; 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=/3aA8CD6Rxs9J9smc1yYkrghmuXWcAvlUyrVQOh28C0=; b=e2kSHckT39/MRTDHWbK4gWyID37uTAeOb9ysW3RvcLWfw1HyrQZH0/9pG671O++/mR +wEoSteAJ41msCEadRpSjru8sOfyMWDtLTEKbAbXEx+aDXoRGLWHP3FqyuFfQ8bCr90V v4+tHw+SCZr6dOOLLQORBdulusO5+Vmr146e+0tQaHAmEANuutuK07xpooMJ9sdk2+2V 5euDRuY7u0x9SZ29GucDZBO0/xy0h/AhNTzPetdFqHP7l8oG+XOKn7JBieS+217ImG6l QATieGnXLZDR9Luexo9pYLkM9tk0T9za+syv3ocq3ImVUWR8ZSQm1guEZq5oxyRW/lEO q4gA== X-Gm-Message-State: AOJu0YxI+zqwhCdyp5lIgrE4KXYp9Lo3USEoDDmArx9YrO4nYHg53OdT TSFDsJFWWi1EYqWhJZnK1Pb25Uej1+ISdFij X-Google-Smtp-Source: AGHT+IGgul4bF+j9+vltU3RvlY9mNkDs5tjvwl5cW74Ot4zmf+KFdvP/PYnbx2aWqoK9lEvNparNfg== X-Received: by 2002:a5d:65c5:0:b0:319:76a2:36e9 with SMTP id e5-20020a5d65c5000000b0031976a236e9mr7540367wrw.56.1692715407434; Tue, 22 Aug 2023 07:43:27 -0700 (PDT) Received: from ?IPV6:2001:8a0:f90f:8600:1210:1829:770d:f735? ([2001:8a0:f90f:8600:1210:1829:770d:f735]) by smtp.gmail.com with ESMTPSA id c3-20020adfe703000000b0031433443265sm16036848wrm.53.2023.08.22.07.43.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Aug 2023 07:43:26 -0700 (PDT) Message-ID: <4917ef2f-f50a-efc0-59a8-30e86d5ac53b@palves.net> Date: Tue, 22 Aug 2023 15:43:19 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH 2/2] [gdb/build] Return const reference in thread_info_to_thread_handle Content-Language: en-US To: Tom de Vries , gdb-patches@sourceware.org References: <20230821105356.869-1-tdevries@suse.de> <20230821105356.869-2-tdevries@suse.de> From: Pedro Alves In-Reply-To: <20230821105356.869-2-tdevries@suse.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,NICE_REPLY_A,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 List-Id: On 2023-08-21 11:53, Tom de Vries via Gdb-patches wrote: > In remote_target::thread_info_to_thread_handle we return a copy: > ... > gdb::byte_vector > remote_target::thread_info_to_thread_handle (struct thread_info *tp) > { > remote_thread_info *priv = get_remote_thread_info (tp); > return priv->thread_handle; > } > ... > > Fix this by returning a const reference instead: > ... > const gdb::optional & > remote_target::thread_info_to_thread_handle (struct thread_info *tp) > ... > > Returning a gdb::optional allows us to return a nullptr, or std::nullopt in > std::optional terms, something that is required by > thread_db_target::thread_info_to_thread_handle. > > In gdb we use gdb::optional instead std::optional, because std::optional is > availabe starting c++17 and we support c++11 and c++14, but gdb::nullopt is > currently not available, though a submission is available [1]. > > So we use a kludge gdb_optional_byte_vector_nullopt. > IMHO making the function return gdb::array_view would be even better. Then the byte_vector is completely an implementation detail, and, you wouldn't need to wrap with optional, as you could just return an empty array_view, like currently we return an empty byte_vector.