Show a patch.

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

{
    "id": 24909,
    "url": "https://patchwork.libcamera.org/api/patches/24909/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/24909/",
    "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": "<20251030165816.1095180-7-barnabas.pocze@ideasonboard.com>",
    "date": "2025-10-30T16:58:00",
    "name": "[RFC,v3,06/22] libcamera: base: Add alignment utility functions",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "09b2c5b3c5dee1a0095c5086b4605744d1aaf8ef",
    "submitter": {
        "id": 216,
        "url": "https://patchwork.libcamera.org/api/people/216/?format=api",
        "name": "Barnabás Pőcze",
        "email": "barnabas.pocze@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/24909/mbox/",
    "series": [
        {
            "id": 5545,
            "url": "https://patchwork.libcamera.org/api/series/5545/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5545",
            "date": "2025-10-30T16:57:54",
            "name": "libcamera: Add `MetadataList`",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/5545/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/24909/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/24909/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 5D928C32CE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 30 Oct 2025 16:58:36 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 913F0609B8;\n\tThu, 30 Oct 2025 17:58:30 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7699F608FE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Oct 2025 17:58:22 +0100 (CET)",
            "from pb-laptop.local (185.221.140.239.nat.pool.zt.hu\n\t[185.221.140.239])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 35B4915D2;\n\tThu, 30 Oct 2025 17:56:32 +0100 (CET)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"WhF7h9H1\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1761843392;\n\tbh=uzkL5Fxz7WOvjGEDWesm1VWIovsBhcpyyMDr+NwGhJQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=WhF7h9H1P1x3bc2OLsqixb+ko5ZAZZP4ntVvkacQS+Kn+DjSCz/ZUmmtITL9VbFY9\n\tgMyrMn6ZJnEpv3Uya3MUVT4kud9KdFUmaZsOKAInAQh0ZG5t3RZtetvf8fUZgLOvpF\n\tQVv4eCQ6jabbbEZgCgt+ngPPK8nMh1rhiqy5AM00=",
        "From": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Paul Elder <paul.elder@ideasonboard.com>",
        "Subject": "[RFC PATCH v3 06/22] libcamera: base: Add alignment utility\n\tfunctions",
        "Date": "Thu, 30 Oct 2025 17:58:00 +0100",
        "Message-ID": "<20251030165816.1095180-7-barnabas.pocze@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.51.1",
        "In-Reply-To": "<20251030165816.1095180-1-barnabas.pocze@ideasonboard.com>",
        "References": "<20251030165816.1095180-1-barnabas.pocze@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "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": "Add a couple internal functions to check alignment, and to\nalign integers, pointers up to a given alignment.\n\nSigned-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n---\nchanges in v3:\n  * documentation\n---\n include/libcamera/base/internal/align.h | 135 ++++++++++++++++++++++++\n include/libcamera/base/meson.build      |   1 +\n 2 files changed, 136 insertions(+)\n create mode 100644 include/libcamera/base/internal/align.h",
    "diff": "diff --git a/include/libcamera/base/internal/align.h b/include/libcamera/base/internal/align.h\nnew file mode 100644\nindex 0000000000..d8ee4e3695\n--- /dev/null\n+++ b/include/libcamera/base/internal/align.h\n@@ -0,0 +1,135 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2025, Ideas on Board Oy\n+ *\n+ * Alignment utilities\n+ */\n+\n+#pragma once\n+\n+#include <cassert>\n+#include <cstddef>\n+#include <cstdint>\n+\n+#include <libcamera/base/internal/cxx20.h>\n+\n+/**\n+ * \\internal\n+ * \\file align.h\n+ * \\brief Utilities for handling alignment\n+ */\n+\n+namespace libcamera::internal::align {\n+\n+/**\n+ * \\internal\n+ * \\brief Check if pointer is aligned\n+ * \\param[in] p pointer to check\n+ * \\param[in] alignment desired alignment\n+ * \\return true if \\a p is at least \\a alignment aligned, false otherwise\n+ */\n+inline bool is(const void *p, std::uintptr_t alignment)\n+{\n+\tassert(alignment > 0);\n+\n+\treturn reinterpret_cast<std::uintptr_t>(p) % alignment == 0;\n+}\n+\n+/**\n+ * \\internal\n+ * \\brief Align number up\n+ * \\param[in] x number to check\n+ * \\param[in] alignment desired alignment\n+ * \\return true if \\a p is at least \\a alignment aligned, false otherwise\n+ */\n+template<typename T>\n+constexpr T up(T x, cxx20::type_identity_t<T> alignment)\n+{\n+\tstatic_assert(std::is_unsigned_v<T>);\n+\tassert(alignment > 0);\n+\n+\tconst auto padding = (alignment - (x % alignment)) % alignment;\n+\tassert(x + padding >= x);\n+\n+\treturn x + padding;\n+}\n+\n+/**\n+ * \\internal\n+ * \\brief Align pointer up\n+ * \\param[in] p pointer to align\n+ * \\param[in] alignment desired alignment\n+ * \\return \\a p up-aligned to \\a alignment\n+ */\n+template<typename T>\n+auto *up(T *p, std::uintptr_t alignment)\n+{\n+\tusing U = std::conditional_t<\n+\t\tstd::is_const_v<T>,\n+\t\tconst std::byte,\n+\t\tstd::byte\n+\t>;\n+\n+\treturn reinterpret_cast<U *>(up(reinterpret_cast<std::uintptr_t>(p), alignment));\n+}\n+\n+/**\n+ * \\internal\n+ * \\brief Align pointer up\n+ * \\param[in] size required number of bytes\n+ * \\param[in] alignment required alignment\n+ * \\param[in] ptr base pointer\n+ * \\param[in] avail number of available bytes\n+ *\n+ * This function checks if the storage starting at \\a ptr and continuing for \\a avail\n+ * bytes (if \\a avail is nullptr, then no size checking is done) can accommodate \\a size\n+ * bytes of data aligned to \\a alignment. If so, then a pointer to the start is the returned\n+ * and \\a ptr is adjusted to point right after the section of \\a size bytes. If present,\n+ * \\a avail is also adjusted.\n+ *\n+ * Similar to std::align().\n+ *\n+ * \\return the appropriately aligned pointer, or nullptr if there is not enough space\n+ */\n+template<typename T>\n+T *up(std::size_t size, std::size_t alignment, T *&ptr, std::size_t *avail = nullptr)\n+{\n+\tassert(alignment > 0);\n+\n+\tauto p = reinterpret_cast<std::uintptr_t>(ptr);\n+\tconst auto padding = (alignment - (p % alignment)) % alignment;\n+\n+\tif (avail) {\n+\t\tif (size > *avail || padding > *avail - size)\n+\t\t\treturn nullptr;\n+\n+\t\t*avail -= size + padding;\n+\t}\n+\n+\tp += padding;\n+\tptr = reinterpret_cast<T *>(p + size);\n+\n+\treturn reinterpret_cast<T *>(p);\n+}\n+\n+/**\n+ * \\internal\n+ * \\brief Align pointer up\n+ * \\tparam U desired type\n+ * \\param[in] ptr base pointer\n+ * \\param[in] avail number of available bytes\n+ *\n+ * A convenience wrapper around libcamera::internal::align::up(std::size_t, std::size_t, T *&, std::size_t *)\n+ * that takes the size and alignment information from the type \\a U.\n+ *\n+ * \\sa libcamera::internal::align::up(std::size_t, std::size_t, T *&, std::size_t *)\n+ */\n+template<typename U, typename T>\n+U *up(T *&ptr, std::size_t *avail = nullptr)\n+{\n+\treturn reinterpret_cast<std::conditional_t<std::is_const_v<T>, const U, U> *>(\n+\t\tup(sizeof(U), alignof(U), ptr, avail)\n+\t);\n+}\n+\n+} /* namespace libcamera::internal::align */\ndiff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build\nindex ee42c9910f..723f42b362 100644\n--- a/include/libcamera/base/meson.build\n+++ b/include/libcamera/base/meson.build\n@@ -33,6 +33,7 @@ libcamera_base_private_headers = files([\n \n libcamera_base_internal_headers = files([\n     'internal/cxx20.h',\n+    'internal/align.h',\n ])\n \n libcamera_base_headers = [\n",
    "prefixes": [
        "RFC",
        "v3",
        "06/22"
    ]
}