Show a patch.

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

{
    "id": 2997,
    "url": "https://patchwork.libcamera.org/api/patches/2997/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/2997/",
    "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": "<20200306160002.30549-26-laurent.pinchart@ideasonboard.com>",
    "date": "2020-03-06T15:59:55",
    "name": "[libcamera-devel,v2,25/32] libcamera: byte_stream_buffer: Add zero-copy read() variant",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "d6f46a4cccbee5d0cd13a349e10eb408e7df4d13",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/2997/mbox/",
    "series": [
        {
            "id": 703,
            "url": "https://patchwork.libcamera.org/api/series/703/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=703",
            "date": "2020-03-06T15:59:30",
            "name": "libcamera: Add support for array controls",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/703/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/2997/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/2997/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<laurent.pinchart@ideasonboard.com>",
        "Received": [
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1F9CF628B7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Mar 2020 17:00:26 +0100 (CET)",
            "from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B08A824B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Mar 2020 17:00:25 +0100 (CET)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1583510425;\n\tbh=IB2SdpK9t3+O0qL+nuKVMs4Yb2mP1wIBYwMpFTN+us8=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=YEbbRE5aG1gkR9YKCgGp2Xspz1rCcktGU2WcsTv6UTifs+q9ItauegMR+SOmKXRRk\n\tzvExdlaiQ0BDWCutQ94xMa+NQhcyh3F9IdoD7e5Ejedl/VtLC7n2kMpGv+EmFD2bPQ\n\tx/eokJv8XRDVsKvMUVKPs+7LzVjScJ764l3HgkBQ=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri,  6 Mar 2020 17:59:55 +0200",
        "Message-Id": "<20200306160002.30549-26-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.24.1",
        "In-Reply-To": "<20200306160002.30549-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20200306160002.30549-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 25/32] libcamera: byte_stream_buffer:\n\tAdd zero-copy read() variant",
        "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>",
        "X-List-Received-Date": "Fri, 06 Mar 2020 16:00:27 -0000"
    },
    "content": "Add a read() function to ByteStreamBuffer that returns a pointer to the\ndata instead of copying it. Overflow check is still handled by the\nclass, but the caller must check the returned pointer explicitly.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/libcamera/byte_stream_buffer.cpp       | 39 ++++++++++++++++++++++\n src/libcamera/include/byte_stream_buffer.h |  9 +++++\n 2 files changed, 48 insertions(+)",
    "diff": "diff --git a/src/libcamera/byte_stream_buffer.cpp b/src/libcamera/byte_stream_buffer.cpp\nindex 17e710c4887e..20d6a6552c5f 100644\n--- a/src/libcamera/byte_stream_buffer.cpp\n+++ b/src/libcamera/byte_stream_buffer.cpp\n@@ -241,6 +241,19 @@ int ByteStreamBuffer::skip(size_t size)\n  * \\retval -ENOSPC no more space is available in the managed memory buffer\n  */\n \n+/**\n+ * \\fn template<typename T> const T *ByteStreamBuffer::read(size_t count)\n+ * \\brief Read data from the managed memory buffer without performing a copy\n+ * \\param[in] count Number of data items to read\n+ *\n+ * This function reads \\a count elements of type \\a T from the buffer. Unlike\n+ * the other read variants, it doesn't copy the data but returns a pointer to\n+ * the first element. If data can't be read for any reason (usually due to\n+ * reading more data than available), the function returns nullptr.\n+ *\n+ * \\return A pointer to the data on success, or nullptr otherwise\n+ */\n+\n /**\n  * \\fn template<typename T> int ByteStreamBuffer::write(const T *t)\n  * \\brief Write \\a t to the managed memory buffer\n@@ -259,6 +272,32 @@ int ByteStreamBuffer::skip(size_t size)\n  * \\retval -ENOSPC no more space is available in the managed memory buffer\n  */\n \n+const uint8_t *ByteStreamBuffer::read(size_t size, size_t count)\n+{\n+\tif (!read_)\n+\t\treturn nullptr;\n+\n+\tif (overflow_)\n+\t\treturn nullptr;\n+\n+\tsize_t bytes;\n+\tif (__builtin_mul_overflow(size, count, &bytes)) {\n+\t\tsetOverflow();\n+\t\treturn nullptr;\n+\t}\n+\n+\tif (read_ + bytes > base_ + size_) {\n+\t\tLOG(Serialization, Error)\n+\t\t\t<< \"Unable to read \" << bytes << \" bytes: out of bounds\";\n+\t\tsetOverflow();\n+\t\treturn nullptr;\n+\t}\n+\n+\tconst uint8_t *data = read_;\n+\tread_ += bytes;\n+\treturn data;\n+}\n+\n int ByteStreamBuffer::read(uint8_t *data, size_t size)\n {\n \tif (!read_)\ndiff --git a/src/libcamera/include/byte_stream_buffer.h b/src/libcamera/include/byte_stream_buffer.h\nindex 17cb0146061e..b3aaa8b9fb28 100644\n--- a/src/libcamera/include/byte_stream_buffer.h\n+++ b/src/libcamera/include/byte_stream_buffer.h\n@@ -9,6 +9,7 @@\n \n #include <stddef.h>\n #include <stdint.h>\n+#include <type_traits>\n \n #include <libcamera/span.h>\n \n@@ -43,6 +44,13 @@ public:\n \t\t\t    data.size_bytes());\n \t}\n \n+\ttemplate<typename T>\n+\tconst std::remove_reference_t<T> *read(size_t count = 1)\n+\t{\n+\t\tusing return_type = const std::remove_reference_t<T> *;\n+\t\treturn reinterpret_cast<return_type>(read(sizeof(T), count));\n+\t}\n+\n \ttemplate<typename T>\n \tint write(const T *t)\n \t{\n@@ -63,6 +71,7 @@ private:\n \tvoid setOverflow();\n \n \tint read(uint8_t *data, size_t size);\n+\tconst uint8_t *read(size_t size, size_t count);\n \tint write(const uint8_t *data, size_t size);\n \n \tByteStreamBuffer *parent_;\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "25/32"
    ]
}