From patchwork Tue May 19 07:21:52 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 26778 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 8CA5BBDCBC for ; Tue, 19 May 2026 07:21:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 952DF63024; Tue, 19 May 2026 09:21:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="s9N2srcy"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8E3B762E6A for ; Tue, 19 May 2026 09:21:55 +0200 (CEST) Received: from pb-laptop.local (unknown [IPv6:2a01:cb1d:8f2:800:9eb6:570e:4fb2:add3]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B4A62BB for ; Tue, 19 May 2026 09:21:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1779175302; bh=vAkbxGLab49QdgbxDEu/qOzV+H6eAbqEuztwpB88SbM=; h=From:To:Subject:Date:From; b=s9N2srcymyR8DEnT0FZ1jooRj/L3RkTY7ONfSn0orKi9hAXnpy1E8e2acslpy/b8c 9u77huW6yT7q6Gchey0+m4SLoMHligBl0FAsnZiqqRMnQ2x2StL8HSpLhBzzFfaSuy sXEuD5JJ2gbwXe+6tIeh0SYSId0fr/oAxN+kpy5M= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [RFC PATCH v1] py: Use smart holder for `Camera` if available Date: Tue, 19 May 2026 09:21:52 +0200 Message-ID: <20260519072152.346204-1-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.54.0 MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The `Camera` class has a private destructor, so `std::shared_ptr<>` cannot be used as a holder type. In recent versions of pybind11, the custom holder type that was used no longer works: RuntimeError: Unable to convert std::shared_ptr to Python when the bound type does not use std::shared_ptr or py::smart_holder as its holder type This appears to be intentional and the fact that it worked is accidental. Fix that by using a "smart holder" since pybind11 3.x, and falling back to the custom one in previous versions. Link: https://github.com/pybind/pybind11/issues/6064 Closes: https://gitlab.freedesktop.org/camera/libcamera/-/work_items/334 --- src/py/libcamera/py_main.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp index d0ef6915b..3b101f996 100644 --- a/src/py/libcamera/py_main.cpp +++ b/src/py/libcamera/py_main.cpp @@ -34,6 +34,7 @@ LOG_DEFINE_CATEGORY(Python) } +#if PYBIND11_VERSION_MAJOR < 3 /* * This is a holder class used only for the Camera class, for the sole purpose * of avoiding the compilation issue with Camera's private destructor. @@ -79,6 +80,13 @@ private: PYBIND11_DECLARE_HOLDER_TYPE(T, PyCameraSmartPtr) +using PyCameraHolder = PyCameraSmartPtr; +using PyCameraArg = PyCameraSmartPtr; +#else +using PyCameraHolder = py::smart_holder; +using PyCameraArg = std::shared_ptr; +#endif + /* * Note: global C++ destructors can be ran on this before the py module is * destructed. @@ -103,7 +111,7 @@ PYBIND11_MODULE(_libcamera, m) */ auto pyCameraManager = py::class_>(m, "CameraManager"); - auto pyCamera = py::class_>(m, "Camera"); + auto pyCamera = py::class_(m, "Camera"); auto pySensorConfiguration = py::class_(m, "SensorConfiguration"); auto pyCameraConfiguration = py::class_(m, "CameraConfiguration"); auto pyCameraConfigurationStatus = py::enum_(pyCameraConfiguration, "Status"); @@ -347,7 +355,7 @@ PYBIND11_MODULE(_libcamera, m) .def("range", &StreamFormats::range); pyFrameBufferAllocator - .def(py::init>(), py::keep_alive<1, 2>()) + .def(py::init(), py::keep_alive<1, 2>()) .def("allocate", [](FrameBufferAllocator &self, Stream *stream) { int ret = self.allocate(stream); if (ret < 0)