Show a patch.

GET /api/patches/19954/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 19954,
    "url": "https://patchwork.libcamera.org/api/patches/19954/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/19954/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20240425160317.326458-1-pobrn@protonmail.com>",
    "date": "2024-04-25T16:03:19",
    "name": "[v2] treewide: Query list of cameras just once",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "234d30fe5f2b2ab48da376ecdbd19695000a0b15",
    "submitter": {
        "id": 133,
        "url": "https://patchwork.libcamera.org/api/people/133/?format=api",
        "name": "Pőcze Barnabás",
        "email": "pobrn@protonmail.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/19954/mbox/",
    "series": [
        {
            "id": 4274,
            "url": "https://patchwork.libcamera.org/api/series/4274/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4274",
            "date": "2024-04-25T16:03:19",
            "name": "[v2] treewide: Query list of cameras just once",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/4274/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/19954/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/19954/checks/",
    "tags": {},
    "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 7338CC3220\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 25 Apr 2024 16:03:27 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 905B461B43;\n\tThu, 25 Apr 2024 18:03:26 +0200 (CEST)",
            "from mail-40133.protonmail.ch (mail-40133.protonmail.ch\n\t[185.70.40.133])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 653A461A9B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 25 Apr 2024 18:03:24 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=protonmail.com header.i=@protonmail.com\n\theader.b=\"lc9xcQ1d\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;\n\ts=protonmail3; t=1714061003; x=1714320203;\n\tbh=cBci5P9lqCSMjhbRtuANGmsj65JaAPeVZqEZrY9vfUw=;\n\th=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date:\n\tSubject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector;\n\tb=lc9xcQ1dKvvCIZK3g+Mv+yK8o/KEAAZwpYgrfxH2GL2/5XdgXgUMWMYAjdFKthutX\n\tfohKnTNQR0kTxZZ6sU/pXCr7l7S6JTpjnqIjXJPRcZEvMwfLK+mMrMEn42IsbLfjCZ\n\te8d5ku24CzPwavMeVe08juaCm2A62rOo/ikK4aQ3i8ABC0Lvjh4wC7BPUSSTBdqzSD\n\tC6R7UVP8leWhL6Vfi7pzN84P+9zzUDUPbkbzcSYzEuns59h2OZmE8f0GAuepxWgP1b\n\tMH8JtIOPYZ8wTI/AIxFoMta51CWvsdnATunHTwZ8pM1m8KXNcxLcaP5jR1CX4Z9ZzB\n\tWjSycEE30edGA==",
        "Date": "Thu, 25 Apr 2024 16:03:19 +0000",
        "To": "libcamera-devel@lists.libcamera.org",
        "From": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>",
        "Subject": "[PATCH v2] treewide: Query list of cameras just once",
        "Message-ID": "<20240425160317.326458-1-pobrn@protonmail.com>",
        "Feedback-ID": "20568564:user:proton",
        "X-Pm-Message-ID": "b3e1c77aaad357cfc2b27f2b2cea1cfd45751893",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=utf-8",
        "Content-Transfer-Encoding": "quoted-printable",
        "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>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "This is more efficient since only a single vector will be constructed,\nand furthermore, it prevents the TOCTOU issue that might arise when\nthe list of cameras changes between the two queries.\n---\n Documentation/guides/application-developer.rst | 11 ++++++-----\n src/apps/cam/camera_session.cpp                |  6 ++++--\n src/gstreamer/gstlibcamerasrc.cpp              |  5 +++--\n 3 files changed, 13 insertions(+), 9 deletions(-)\n\n\nbase-commit: fb74bb7df66b96dbe28702155cddfc96a1b30f78",
    "diff": "diff --git a/Documentation/guides/application-developer.rst b/Documentation/guides/application-developer.rst\nindex 9a9905b1..e09ddfb1 100644\n--- a/Documentation/guides/application-developer.rst\n+++ b/Documentation/guides/application-developer.rst\n@@ -116,20 +116,21 @@ available.\n \n .. code:: cpp\n \n-   if (cm->cameras().empty()) {\n+   auto cameras = cm->cameras();\n+   if (cameras.empty()) {\n        std::cout << \"No cameras were identified on the system.\"\n                  << std::endl;\n        cm->stop();\n        return EXIT_FAILURE;\n    }\n \n-   std::string cameraId = cm->cameras()[0]->id();\n-   camera = cm->get(cameraId);\n+   std::string cameraId = cameras[0]->id();\n \n    /*\n-    * Note that is equivalent to:\n-    * camera = cm->cameras()[0];\n+    * Note that `camera` may be nullptr as the camera\n+    * might have disappeared in the meantime.\n     */\n+   auto camera = cm->get(cameraId);\n \n Once a camera has been selected an application needs to acquire an exclusive\n lock to it so no other application can use it.\ndiff --git a/src/apps/cam/camera_session.cpp b/src/apps/cam/camera_session.cpp\nindex 8447f932..5afd087f 100644\n--- a/src/apps/cam/camera_session.cpp\n+++ b/src/apps/cam/camera_session.cpp\n@@ -39,8 +39,10 @@ CameraSession::CameraSession(CameraManager *cm,\n {\n \tchar *endptr;\n \tunsigned long index = strtoul(cameraId.c_str(), &endptr, 10);\n-\tif (*endptr == '\\0' && index > 0 && index <= cm->cameras().size())\n-\t\tcamera_ = cm->cameras()[index - 1];\n+\tauto cameras = cm->cameras();\n+\n+\tif (*endptr == '\\0' && index > 0 && index <= cameras.size())\n+\t\tcamera_ = std::move(cameras[index - 1]);\n \telse\n \t\tcamera_ = cm->get(cameraId);\n \ndiff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\nindex f015c6d2..8613d66d 100644\n--- a/src/gstreamer/gstlibcamerasrc.cpp\n+++ b/src/gstreamer/gstlibcamerasrc.cpp\n@@ -385,13 +385,14 @@ gst_libcamera_src_open(GstLibcameraSrc *self)\n \t\t\treturn false;\n \t\t}\n \t} else {\n-\t\tif (cm->cameras().empty()) {\n+\t\tauto cameras = cm->cameras();\n+\t\tif (cameras.empty()) {\n \t\t\tGST_ELEMENT_ERROR(self, RESOURCE, NOT_FOUND,\n \t\t\t\t\t  (\"Could not find any supported camera on this system.\"),\n \t\t\t\t\t  (\"libcamera::CameraMananger::cameras() is empty\"));\n \t\t\treturn false;\n \t\t}\n-\t\tcam = cm->cameras()[0];\n+\t\tcam = std::move(cameras[0]);\n \t}\n \n \tGST_INFO_OBJECT(self, \"Using camera '%s'\", cam->id().c_str());\n",
    "prefixes": [
        "v2"
    ]
}