From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id CvyNIBQplGHPLgAAWB0awg (envelope-from ) for ; Tue, 16 Nov 2021 16:56:36 -0500 Received: by simark.ca (Postfix, from userid 112) id 722281F0C1; Tue, 16 Nov 2021 16:56:36 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,NICE_REPLY_A,URIBL_BLOCKED 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 AC1371E813 for ; Tue, 16 Nov 2021 16:56:35 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 08B90385AC0A for ; Tue, 16 Nov 2021 21:56:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 08B90385AC0A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1637099795; bh=+PRILB0w0GQQQZqsD1Lv6yaI30bVljobSgeYPhSVIa4=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=FjaUOH/eRCemZ2XStdQTF8J4obA3p2pVvlA74t+3apESACj8LhWvcB9eFtSflAH6X qiPNH2hL8h6jAHM+yidcgqDWxz6tDrIgifSNlV1cmAWCTYRh5IP2M4+oFFNynjUqki +lPJs69EB3g0kuMdRL3Q2MSxvyqNwpOWYZbBeJTE= Received: from mail.efficios.com (mail.efficios.com [167.114.26.124]) by sourceware.org (Postfix) with ESMTPS id 30D353858037 for ; Tue, 16 Nov 2021 21:56:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 30D353858037 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 95D393A236E; Tue, 16 Nov 2021 16:56:14 -0500 (EST) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 3EwqvhML0Wtc; Tue, 16 Nov 2021 16:56:14 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id F39193A23CE; Tue, 16 Nov 2021 16:56:13 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com F39193A23CE X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id L3mF5eM5ELYI; Tue, 16 Nov 2021 16:56:13 -0500 (EST) Received: from [172.16.0.95] (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by mail.efficios.com (Postfix) with ESMTPSA id CE7993A224A; Tue, 16 Nov 2021 16:56:13 -0500 (EST) Subject: Re: [PATCH 2/4] gdbsupport: add array_view copy function To: Tom Tromey , Simon Marchi via Gdb-patches References: <20211108210609.353208-1-simon.marchi@efficios.com> <20211108210609.353208-2-simon.marchi@efficios.com> <87h7cbesar.fsf@tromey.com> Message-ID: <90ddca61-ea64-b354-6fb4-99ab607a43d6@efficios.com> Date: Tue, 16 Nov 2021 16:56:13 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <87h7cbesar.fsf@tromey.com> Content-Type: text/plain; charset=utf-8 Content-Language: tl 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: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On 2021-11-16 3:53 p.m., Tom Tromey wrote: >>>>>> "Simon" == Simon Marchi via Gdb-patches writes: > > Simon> An assertion was recently added to array_view::operator[] to ensure we > Simon> don't do out of bounds accesses. However, when the array_view is copied > Simon> to or from using memcpy, it bypasses this safety. > > Simon> To address this, add a `copy` free function that copies data from an > Simon> array view to another. It ensures that the destination and source array > Simon> views have the same size and element size, which prevents any kind of > Simon> overflow in the source and in the destination. > > In C++20 I think we could use std::copy by having the array view > iterators implement the contiguous_iterator concept. So, maybe a > comment to this effect would be good. Do you mean we could use std::copy to implement this copy function, instead of using memcpy, and that would deal with the details of copying in the most efficient manner? If I read cppreference correctly [1], std::copy is available before C++20, it's just that in C++20 it has been made constexpr. So I could maybe give it a try, instead of using memcpy. [1] https://en.cppreference.com/w/cpp/algorithm/copy > Though maybe in C++20 we would want to switch from array_view to > std::span. Ack. Simon