From patchwork Wed May 22 22:12:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1265 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 30F9F60103 for ; Thu, 23 May 2019 00:13:02 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C60E5443 for ; Thu, 23 May 2019 00:13:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1558563181; bh=NROoCzaA1cMJqcqtDCrTF/cxmXByA7s9KvtBKmh4kk4=; h=From:To:Subject:Date:From; b=cYz0NxF2fHWMW9EhwUg0OToeywmQfTdwHcBE3zOapLvOsVqRUBuSrNBbBnb2VyKbP IKqvgiVcb6pKnv5ikv9B25muhGmCO+LZmsZ4JD0BIIDiIE3tPEcWp8unNQeoAOBDhn 0oAnFBhUMNlhinatTrlO8DiCVvZW3v4uhzkDVfig= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 23 May 2019 01:12:37 +0300 Message-Id: <20190522221237.19400-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: camera: Simplify create() implementation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 May 2019 22:13:02 -0000 Now that the Camera class inherits from std::enable_shared_from_this, we don't need to use std::allocate_shared anymore and can simplify the Camera::create() implementation. This fixes compilation with recent versions of libc++ whose std::allocate_shared implementation isn't compatible with classes that are not publicly constructible. The custom allocator is removed, but a custom deleter is needed as the Camera destructor is private. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- src/libcamera/camera.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 0f45ab7e4358..617ea99cdf71 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -358,24 +358,17 @@ std::shared_ptr Camera::create(PipelineHandler *pipe, const std::string &name, const std::set &streams) { - struct Allocator : std::allocator { - void construct(void *p, PipelineHandler *pipe, - const std::string &name) + struct Deleter : std::default_delete { + void operator()(Camera *camera) { - ::new(p) Camera(pipe, name); - } - void destroy(Camera *p) - { - p->~Camera(); + delete camera; } }; - std::shared_ptr camera = - std::allocate_shared(Allocator(), pipe, name); - + Camera *camera = new Camera(pipe, name); camera->streams_ = streams; - return camera; + return std::shared_ptr(camera, Deleter()); } /**