libcamera: camera: Simplify create() implementation

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@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Laurent Pinchart 2019-05-21 22:16:23 +03:00
parent 8d846ed8a7
commit 1f32abb995

View file

@ -358,24 +358,17 @@ std::shared_ptr<Camera> Camera::create(PipelineHandler *pipe,
const std::string &name, const std::string &name,
const std::set<Stream *> &streams) const std::set<Stream *> &streams)
{ {
struct Allocator : std::allocator<Camera> { struct Deleter : std::default_delete<Camera> {
void construct(void *p, PipelineHandler *pipe, void operator()(Camera *camera)
const std::string &name)
{ {
::new(p) Camera(pipe, name); delete camera;
}
void destroy(Camera *p)
{
p->~Camera();
} }
}; };
std::shared_ptr<Camera> camera = Camera *camera = new Camera(pipe, name);
std::allocate_shared<Camera>(Allocator(), pipe, name);
camera->streams_ = streams; camera->streams_ = streams;
return camera; return std::shared_ptr<Camera>(camera, Deleter());
} }
/** /**