Patch Detail
Show a patch.
GET /api/1.1/patches/25636/?format=api
{ "id": 25636, "url": "https://patchwork.libcamera.org/api/1.1/patches/25636/?format=api", "web_url": "https://patchwork.libcamera.org/patch/25636/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/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": "<20260106165754.1759831-7-barnabas.pocze@ideasonboard.com>", "date": "2026-01-06T16:57:38", "name": "[v4,06/22] libcamera: base: Add alignment utility functions", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "09b2c5b3c5dee1a0095c5086b4605744d1aaf8ef", "submitter": { "id": 216, "url": "https://patchwork.libcamera.org/api/1.1/people/216/?format=api", "name": "Barnabás Pőcze", "email": "barnabas.pocze@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/25636/mbox/", "series": [ { "id": 5688, "url": "https://patchwork.libcamera.org/api/1.1/series/5688/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5688", "date": "2026-01-06T16:57:32", "name": "libcamera: Add `MetadataList`", "version": 4, "mbox": "https://patchwork.libcamera.org/series/5688/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/25636/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/25636/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 2974BBDCBF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 6 Jan 2026 16:58:14 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 58A0B61FC1;\n\tTue, 6 Jan 2026 17:58:05 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 77E3A61FC1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 6 Jan 2026 17:57:59 +0100 (CET)", "from pb-laptop.local (185.221.143.114.nat.pool.zt.hu\n\t[185.221.143.114])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 697A51733;\n\tTue, 6 Jan 2026 17:57:38 +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=\"KoNuWvF4\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1767718658;\n\tbh=7ADgsOd5Kh8W+29vzIwsn64OFI56wj3oNkbV31uALAA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=KoNuWvF4YeRFMqEpxIrsV5QuXWkEunvkaTXBXVf0vRvbMA7ONQtI+cfHbsizYitRo\n\tsBaya+YfCkV2/miXujvMCnJqVP9jo1Ifwc18kks/d1Zhe1NmpUYS7dRp/49TRPQHsC\n\t2kqHz9UrVLHXFuypzD2D8B/5dpqyXIjpetxYh4gA=", "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>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>", "Subject": "[PATCH v4 06/22] libcamera: base: Add alignment utility functions", "Date": "Tue, 6 Jan 2026 17:57:38 +0100", "Message-ID": "<20260106165754.1759831-7-barnabas.pocze@ideasonboard.com>", "X-Mailer": "git-send-email 2.52.0", "In-Reply-To": "<20260106165754.1759831-1-barnabas.pocze@ideasonboard.com>", "References": "<20260106165754.1759831-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>\nReviewed-by: Kieran Bingham <kieran.bingham@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 000000000..d8ee4e369\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 bb4ed556b..305dfa0dd 100644\n--- a/include/libcamera/base/meson.build\n+++ b/include/libcamera/base/meson.build\n@@ -34,6 +34,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": [ "v4", "06/22" ] }