[libcamera-devel] [PATCH] libcamera: camera: Simplify create() implementation

Laurent Pinchart laurent.pinchart at ideasonboard.com
Thu May 23 00:12:37 CEST 2019


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 <laurent.pinchart at ideasonboard.com>
---
 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> Camera::create(PipelineHandler *pipe,
 				       const std::string &name,
 				       const std::set<Stream *> &streams)
 {
-	struct Allocator : std::allocator<Camera> {
-		void construct(void *p, PipelineHandler *pipe,
-			       const std::string &name)
+	struct Deleter : std::default_delete<Camera> {
+		void operator()(Camera *camera)
 		{
-			::new(p) Camera(pipe, name);
-		}
-		void destroy(Camera *p)
-		{
-			p->~Camera();
+			delete camera;
 		}
 	};
 
-	std::shared_ptr<Camera> camera =
-		std::allocate_shared<Camera>(Allocator(), pipe, name);
-
+	Camera *camera = new Camera(pipe, name);
 	camera->streams_ = streams;
 
-	return camera;
+	return std::shared_ptr<Camera>(camera, Deleter());
 }
 
 /**
-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list