From patchwork Fri Feb 20 14:40:08 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 26215 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 24A80C0DA4 for ; Fri, 20 Feb 2026 14:40:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6DBDF62262; Fri, 20 Feb 2026 15:40:13 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="kH0Moa+z"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0C09F61FBF for ; Fri, 20 Feb 2026 15:40:12 +0100 (CET) Received: from pb-laptop.local (185.221.141.206.nat.pool.zt.hu [185.221.141.206]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1B9EC502 for ; Fri, 20 Feb 2026 15:39:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1771598358; bh=bbAgYSczHSVLM2HyTvIprtU+YJgXyaaROcsoYsjv34M=; h=From:To:Subject:Date:From; b=kH0Moa+zUuXJa+aAbkmaWlIx8FHdnGTkkmIrV/1pIKENygqSdDI0gtNky4pWOBlZ7 N6RPfHbf/FctMAkjRcYfaTCELWcDPhrKFl5cp7vLItbZqOf0Q31RmwpR82ezLkD47m Wf7RoKLQ0WwI3I+y3JZie1pzIjAvBYSeZgDRsAmM= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [PATCH v2] py: Fix include order Date: Fri, 20 Feb 2026 15:40:08 +0100 Message-ID: <20260220144008.211492-1-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.53.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" Python.h hence the pybind header must be included first since pyconfig.h unconditionally overrides certain feature test macros[0]. This was mostly hidden by the fact that macro redefinitions with the same value do not trigger compiler warnings. However, glibc 43 has changed certain defaults[1], causing mismatches, leading to compiler warnings. So change the include order so that `` headers are included first and then the local `"py_..."` headers, and then everything else. Adjust `.clang-format` and the documentation as well. [0]: https://docs.python.org/3/c-api/intro.html#include-files [1]: https://sourceware.org/git/?p=glibc.git;a=commit;h=a5cc3018f31a125f019685b239c6e5a0bf1a272b Link: https://github.com/python/cpython/issues/61322 Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart --- changes in v2: * edit documentation v1: https://patchwork.libcamera.org/patch/26184/ --- .clang-format | 6 ++++++ Documentation/coding-style.rst | 6 ++++++ src/py/libcamera/py_camera_manager.h | 4 ++-- src/py/libcamera/py_color_space.cpp | 6 +++--- src/py/libcamera/py_controls_generated.cpp.in | 4 ++-- src/py/libcamera/py_enums.cpp | 4 ++-- src/py/libcamera/py_formats_generated.cpp.in | 4 ++-- src/py/libcamera/py_geometry.cpp | 10 +++++----- src/py/libcamera/py_helpers.cpp | 8 ++++---- src/py/libcamera/py_helpers.h | 4 ++-- src/py/libcamera/py_main.cpp | 15 +++++++-------- src/py/libcamera/py_main.h | 4 ++-- src/py/libcamera/py_transform.cpp | 6 +++--- 13 files changed, 46 insertions(+), 35 deletions(-) -- 2.53.0 diff --git a/.clang-format b/.clang-format index 7fc30f614..7dbeea784 100644 --- a/.clang-format +++ b/.clang-format @@ -77,6 +77,12 @@ IncludeCategories: - Regex: '' CaseSensitive: true Priority: 9 + # Python.h hence pybind11 headers must be included first + # https://docs.python.org/3/c-api/intro.html#include-files + - Regex: '' + Priority: -9 + - Regex: '"py_.*"' + Priority: -8 # Headers in <> with an extension. (+system libraries) - Regex: '<([A-Za-z0-9\-_])+\.h>' Priority: 2 diff --git a/Documentation/coding-style.rst b/Documentation/coding-style.rst index 3352b75c7..e0864b78d 100644 --- a/Documentation/coding-style.rst +++ b/Documentation/coding-style.rst @@ -95,6 +95,12 @@ System and library headers shall be included with angle brackets. Project headers shall be included with angle brackets for the libcamera public API headers, and with double quotes for internal libcamera headers. +.. note:: + As an exception pybind11 headers and local ``py_*`` headers must be included first + in the Python bindings due to the requirements outlined in the `Python documentation`_. + +.. _Python documentation: https://docs.python.org/3/c-api/intro.html#include-files + C++ Specific Rules ------------------ diff --git a/src/py/libcamera/py_camera_manager.h b/src/py/libcamera/py_camera_manager.h index af69b915e..7da65172e 100644 --- a/src/py/libcamera/py_camera_manager.h +++ b/src/py/libcamera/py_camera_manager.h @@ -5,12 +5,12 @@ #pragma once +#include + #include #include -#include - using namespace libcamera; class PyCameraManager diff --git a/src/py/libcamera/py_color_space.cpp b/src/py/libcamera/py_color_space.cpp index fd5a5dabe..2f4d2d891 100644 --- a/src/py/libcamera/py_color_space.cpp +++ b/src/py/libcamera/py_color_space.cpp @@ -5,15 +5,15 @@ * Python bindings - Color Space classes */ -#include -#include - #include #include #include #include "py_main.h" +#include +#include + namespace py = pybind11; using namespace libcamera; diff --git a/src/py/libcamera/py_controls_generated.cpp.in b/src/py/libcamera/py_controls_generated.cpp.in index 22a132d19..c42a477bb 100644 --- a/src/py/libcamera/py_controls_generated.cpp.in +++ b/src/py/libcamera/py_controls_generated.cpp.in @@ -7,12 +7,12 @@ * This file is auto-generated. Do not edit. */ -#include - #include #include "py_main.h" +#include + namespace py = pybind11; class Py{{mode|capitalize}} diff --git a/src/py/libcamera/py_enums.cpp b/src/py/libcamera/py_enums.cpp index 9e75ec1a9..715b63880 100644 --- a/src/py/libcamera/py_enums.cpp +++ b/src/py/libcamera/py_enums.cpp @@ -5,12 +5,12 @@ * Python bindings - Enumerations */ -#include - #include #include "py_main.h" +#include + namespace py = pybind11; using namespace libcamera; diff --git a/src/py/libcamera/py_formats_generated.cpp.in b/src/py/libcamera/py_formats_generated.cpp.in index c5fb90639..bd0ccdc3e 100644 --- a/src/py/libcamera/py_formats_generated.cpp.in +++ b/src/py/libcamera/py_formats_generated.cpp.in @@ -7,10 +7,10 @@ * This file is auto-generated. Do not edit. */ -#include - #include +#include + #include "py_main.h" namespace py = pybind11; diff --git a/src/py/libcamera/py_geometry.cpp b/src/py/libcamera/py_geometry.cpp index c7e303609..d96015f03 100644 --- a/src/py/libcamera/py_geometry.cpp +++ b/src/py/libcamera/py_geometry.cpp @@ -5,17 +5,17 @@ * Python bindings - Geometry classes */ -#include - -#include -#include - #include #include #include #include "py_main.h" +#include + +#include +#include + namespace py = pybind11; using namespace libcamera; diff --git a/src/py/libcamera/py_helpers.cpp b/src/py/libcamera/py_helpers.cpp index 8c55ef845..b9142225c 100644 --- a/src/py/libcamera/py_helpers.cpp +++ b/src/py/libcamera/py_helpers.cpp @@ -3,14 +3,14 @@ * Copyright (C) 2022, Tomi Valkeinen */ -#include "py_helpers.h" - -#include - #include #include #include +#include "py_helpers.h" + +#include + namespace py = pybind11; using namespace libcamera; diff --git a/src/py/libcamera/py_helpers.h b/src/py/libcamera/py_helpers.h index 983969dff..989fae77b 100644 --- a/src/py/libcamera/py_helpers.h +++ b/src/py/libcamera/py_helpers.h @@ -5,9 +5,9 @@ #pragma once -#include - #include +#include + pybind11::object controlValueToPy(const libcamera::ControlValue &cv); libcamera::ControlValue pyToControlValue(const pybind11::object &ob, libcamera::ControlType type); diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp index a983ea75c..d0ef6915b 100644 --- a/src/py/libcamera/py_main.cpp +++ b/src/py/libcamera/py_main.cpp @@ -5,6 +5,13 @@ * Python bindings */ +#include +#include +#include +#include + +#include "py_camera_manager.h" +#include "py_helpers.h" #include "py_main.h" #include @@ -17,14 +24,6 @@ #include -#include -#include -#include -#include - -#include "py_camera_manager.h" -#include "py_helpers.h" - namespace py = pybind11; using namespace libcamera; diff --git a/src/py/libcamera/py_main.h b/src/py/libcamera/py_main.h index 4d594326e..dd31c6d9a 100644 --- a/src/py/libcamera/py_main.h +++ b/src/py/libcamera/py_main.h @@ -5,10 +5,10 @@ #pragma once -#include - #include +#include + namespace libcamera { LOG_DECLARE_CATEGORY(Python) diff --git a/src/py/libcamera/py_transform.cpp b/src/py/libcamera/py_transform.cpp index 768260ffc..8719b5ff5 100644 --- a/src/py/libcamera/py_transform.cpp +++ b/src/py/libcamera/py_transform.cpp @@ -5,15 +5,15 @@ * Python bindings - Transform class */ -#include -#include - #include #include #include #include "py_main.h" +#include +#include + namespace py = pybind11; using namespace libcamera;