[{"id":15107,"web_url":"https://patchwork.libcamera.org/comment/15107/","msgid":"<YCWgLr8anICm7XVF@pendragon.ideasonboard.com>","date":"2021-02-11T21:22:54","subject":"Re: [libcamera-devel] [PATCH v2 6/6] libcamera: MappedBuffer:\n\tDisable copy and assignment","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the patch.\n\nOn Thu, Feb 11, 2021 at 01:34:44PM +0000, Kieran Bingham wrote:\n> Prevent copying and assignment of MappedBuffer types, which could invoke\n> undesired unmapping of mapped memory.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nI think the commit message isn't 100% right. As explained in\nhttps://en.cppreference.com/w/cpp/language/copy_constructor, the\ncompiler will declare a copy constructor for the MappedBuffer class:\n\n\"If no user-defined copy constructors are provided for a class type\n(struct, class, or union), the compiler will always declare a copy\nconstructor as a non-explicit inline public member of its class.\"\n\nBut that constructor will be deleted:\n\n\"The implicitly-declared or defaulted copy constructor for class T is\ndefined as deleted if any of the following conditions are true:\n- ...\n- T has a user-defined move constructor or move assignment operator\n  (this condition only causes the implicitly-declared, not the\n  defaulted, copy constructor to be deleted).\"\n\nso MappedBuffer can't currently be copied if I'm not mistaken. Still,\nthis should be made explicit\n(https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rc-five)\nso the patch is right.\n\nWith or without the commit message updated,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  include/libcamera/internal/buffer.h | 4 ++++\n>  1 file changed, 4 insertions(+)\n> \n> diff --git a/include/libcamera/internal/buffer.h b/include/libcamera/internal/buffer.h\n> index b7b0173f93f5..b980deaf58d5 100644\n> --- a/include/libcamera/internal/buffer.h\n> +++ b/include/libcamera/internal/buffer.h\n> @@ -10,6 +10,7 @@\n>  #include <sys/mman.h>\n>  #include <vector>\n>  \n> +#include <libcamera/class.h>\n>  #include <libcamera/buffer.h>\n>  #include <libcamera/span.h>\n>  \n> @@ -34,6 +35,9 @@ protected:\n>  \n>  \tint error_;\n>  \tstd::vector<Plane> maps_;\n> +\n> +private:\n> +\tLIBCAMERA_DISABLE_COPY(MappedBuffer);\n>  };\n>  \n>  class MappedFrameBuffer : public MappedBuffer","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id B24DEBD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 11 Feb 2021 21:23:22 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 200EE63750;\n\tThu, 11 Feb 2021 22:23:22 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D6A68601B5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 11 Feb 2021 22:23:20 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 41C8B41;\n\tThu, 11 Feb 2021 22:23:20 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"ucn2SWmd\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1613078600;\n\tbh=l4CUu+YHC9M2n2IPbmc3FR2VApvx+TZteszPIVJ4NTI=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ucn2SWmddHDRg6CP9A6cWZ7tjjnObnCwSdww2ayWGwV1ioP5yfxrbDilKVCVKuoIo\n\tsm1NSNmGNKrjiOaHok4gFXMKshfIp+tEEvx/DprqZ/cY4EWU4haO/mULdnOqCpqw/3\n\tCz9SRzuMISUZE1iEfwHmXSMqvbLJbL53iW5ZDVbo=","Date":"Thu, 11 Feb 2021 23:22:54 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<YCWgLr8anICm7XVF@pendragon.ideasonboard.com>","References":"<20210211133444.764808-1-kieran.bingham@ideasonboard.com>\n\t<20210211133444.764808-7-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20210211133444.764808-7-kieran.bingham@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2 6/6] libcamera: MappedBuffer:\n\tDisable copy and assignment","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]