From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id PfHnGafgs1+XBgAAWB0awg (envelope-from ) for ; Tue, 17 Nov 2020 09:39:35 -0500 Received: by simark.ca (Postfix, from userid 112) id 558201F08B; Tue, 17 Nov 2020 09:39:35 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI autolearn=ham autolearn_force=no version=3.4.2 Received: from 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 606671E58D for ; Tue, 17 Nov 2020 09:39:34 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B818239730BE; Tue, 17 Nov 2020 14:39:33 +0000 (GMT) Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id B1667385801E for ; Tue, 17 Nov 2020 14:39:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B1667385801E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.11] (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 09D431E58D; Tue, 17 Nov 2020 09:32:19 -0500 (EST) Subject: Re: [RFA 2/6] gmp-utils: Convert the read/write methods to using gdb::array_view To: Pedro Alves , Joel Brobecker , gdb-patches@sourceware.org References: <1604817017-25807-1-git-send-email-brobecker@adacore.com> <1605430184-81335-1-git-send-email-brobecker@adacore.com> <1605430184-81335-3-git-send-email-brobecker@adacore.com> <9fcbb9da-97d9-c0b2-a5b5-39f114fbe819@simark.ca> <14f04e1f-ab01-8675-533f-24aaaa466966@palves.net> From: Simon Marchi Message-ID: <9e1487f4-1b24-ff7c-0001-a7774896ada1@simark.ca> Date: Tue, 17 Nov 2020 09:32:18 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <14f04e1f-ab01-8675-533f-24aaaa466966@palves.net> Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 2020-11-16 6:05 p.m., Pedro Alves wrote: > On 11/16/20 12:52 AM, Simon Marchi wrote: >> On 2020-11-15 3:49 a.m., Joel Brobecker wrote: >>> This commit changes the interfaces of some of the methods declared >>> in gmp-utils to take a gdb::array_view of gdb_byte instead of a >>> (gdb_byte *, size) couple. >>> >>> This makes these methods' API probably more C++-idiomatic. >>> With the way things are structured, this change introduces a minor >>> extra complication at the point of call of these methods, since >>> the data available there is not in the form of an array_view, >>> and thus the array_view needs to be constructed on the spot. >> >> I'd suggest using gdb::make_array_view (ptr, len) instead of the >> array_view constructor. This way, you don't need to specify the >> template type, it's automatically deduced, so it's a bit less verbose. >> Otherwise, LGTM. > > Note gdb::make_array_view is only necessary if the type of len > is not size_t. If it is size_t, then the shorter "{ptr, len}" works. > > As an illustration: > > --- i/gdb/unittests/gmp-utils-selftests.c > +++ w/gdb/unittests/gmp-utils-selftests.c > @@ -95,7 +95,7 @@ gdb_mpz_as_integer () > > template > void > -store_and_read_back (T val, int buf_len, enum bfd_endian byte_order, > +store_and_read_back (T val, size_t buf_len, enum bfd_endian byte_order, > gdb_mpz &expected, gdb_mpz &actual) > { > gdb_byte *buf; > @@ -109,8 +109,7 @@ store_and_read_back (T val, int buf_len, enum bfd_endian byte_order, > mpz_set (actual.val, expected.val); > mpz_sub_ui (actual.val, actual.val, 500); > > - actual.read (gdb::array_view (buf, buf_len), > - byte_order, !std::is_signed::value); > + actual.read ({buf, buf_len}, byte_order, !std::is_signed::value); > } > Well, +1 for using that. Simon