| Message ID | 20260217085309.61350-1-barnabas.pocze@ideasonboard.com |
|---|---|
| State | Superseded |
| Headers | show |
| Series |
|
| Related | show |
Quoting Barnabás Pőcze (2026-02-17 08:53:09) > Python.h hence the pybind headers 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 `<pybind11/...>` headers are included > first and then the local `"py_..."` headers, and then everything else. > > Also adjust `.clang-format` as well. Awesome, thanks. Could you also add a note to Documentation/coding-style.rst where the include orders are mentioned please? > > [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 <barnabas.pocze@ideasonboard.com> > --- > .clang-format | 6 ++++++ > src/py/libcamera/py_camera_manager.cpp | 3 +-- > 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, 41 insertions(+), 37 deletions(-) > > diff --git a/.clang-format b/.clang-format > index 7fc30f614..7dbeea784 100644 > --- a/.clang-format > +++ b/.clang-format > @@ -77,6 +77,12 @@ IncludeCategories: > - Regex: '<Q([A-Za-z0-9\-_])+>' > 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: '<pybind11/.*>' > + Priority: -9 > + - Regex: '"py_.*"' > + Priority: -8 > # Headers in <> with an extension. (+system libraries) > - Regex: '<([A-Za-z0-9\-_])+\.h>' > Priority: 2 > diff --git a/src/py/libcamera/py_camera_manager.cpp b/src/py/libcamera/py_camera_manager.cpp > index 9ccb7aada..3159bce5b 100644 > --- a/src/py/libcamera/py_camera_manager.cpp > +++ b/src/py/libcamera/py_camera_manager.cpp > @@ -4,6 +4,7 @@ > */ > > #include "py_camera_manager.h" > +#include "py_main.h" > > #include <errno.h> > #include <memory> > @@ -12,8 +13,6 @@ > #include <unistd.h> > #include <vector> > > -#include "py_main.h" > - > namespace py = pybind11; > > using namespace libcamera; > 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 <pybind11/pybind11.h> > + > #include <libcamera/base/mutex.h> > > #include <libcamera/libcamera.h> > > -#include <pybind11/pybind11.h> > - > 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 <libcamera/color_space.h> > -#include <libcamera/libcamera.h> > - > #include <pybind11/operators.h> > #include <pybind11/pybind11.h> > #include <pybind11/stl.h> > > #include "py_main.h" > > +#include <libcamera/color_space.h> > +#include <libcamera/libcamera.h> > + > 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 <libcamera/{{header}}> > - > #include <pybind11/pybind11.h> > > #include "py_main.h" > > +#include <libcamera/{{header}}> > + > 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 <libcamera/libcamera.h> > - > #include <pybind11/pybind11.h> > > #include "py_main.h" > > +#include <libcamera/libcamera.h> > + > 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..9da3a3c79 100644 > --- a/src/py/libcamera/py_formats_generated.cpp.in > +++ b/src/py/libcamera/py_formats_generated.cpp.in > @@ -7,12 +7,12 @@ > * This file is auto-generated. Do not edit. > */ > > -#include <libcamera/formats.h> > - > #include <pybind11/pybind11.h> > > #include "py_main.h" > > +#include <libcamera/formats.h> > + > namespace py = pybind11; > > class PyFormats > 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 <array> > - > -#include <libcamera/geometry.h> > -#include <libcamera/libcamera.h> > - > #include <pybind11/operators.h> > #include <pybind11/pybind11.h> > #include <pybind11/stl.h> > > #include "py_main.h" > > +#include <array> > + > +#include <libcamera/geometry.h> > +#include <libcamera/libcamera.h> > + > 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 <tomi.valkeinen@ideasonboard.com> > */ > > -#include "py_helpers.h" > - > -#include <libcamera/libcamera.h> > - > #include <pybind11/functional.h> > #include <pybind11/stl.h> > #include <pybind11/stl_bind.h> > > +#include "py_helpers.h" > + > +#include <libcamera/libcamera.h> > + > 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 <libcamera/libcamera.h> > - > #include <pybind11/pybind11.h> > > +#include <libcamera/libcamera.h> > + > 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 <pybind11/functional.h> > +#include <pybind11/pybind11.h> > +#include <pybind11/stl.h> > +#include <pybind11/stl_bind.h> > + > +#include "py_camera_manager.h" > +#include "py_helpers.h" > #include "py_main.h" > > #include <limits> > @@ -17,14 +24,6 @@ > > #include <libcamera/libcamera.h> > > -#include <pybind11/functional.h> > -#include <pybind11/pybind11.h> > -#include <pybind11/stl.h> > -#include <pybind11/stl_bind.h> > - > -#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 <libcamera/base/log.h> > - > #include <pybind11/pybind11.h> > > +#include <libcamera/base/log.h> > + > 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 <libcamera/transform.h> > -#include <libcamera/libcamera.h> > - > #include <pybind11/operators.h> > #include <pybind11/pybind11.h> > #include <pybind11/stl.h> > > #include "py_main.h" > > +#include <libcamera/transform.h> > +#include <libcamera/libcamera.h> > + > namespace py = pybind11; > > using namespace libcamera; > -- > 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: '<Q([A-Za-z0-9\-_])+>' 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: '<pybind11/.*>' + Priority: -9 + - Regex: '"py_.*"' + Priority: -8 # Headers in <> with an extension. (+system libraries) - Regex: '<([A-Za-z0-9\-_])+\.h>' Priority: 2 diff --git a/src/py/libcamera/py_camera_manager.cpp b/src/py/libcamera/py_camera_manager.cpp index 9ccb7aada..3159bce5b 100644 --- a/src/py/libcamera/py_camera_manager.cpp +++ b/src/py/libcamera/py_camera_manager.cpp @@ -4,6 +4,7 @@ */ #include "py_camera_manager.h" +#include "py_main.h" #include <errno.h> #include <memory> @@ -12,8 +13,6 @@ #include <unistd.h> #include <vector> -#include "py_main.h" - namespace py = pybind11; using namespace libcamera; 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 <pybind11/pybind11.h> + #include <libcamera/base/mutex.h> #include <libcamera/libcamera.h> -#include <pybind11/pybind11.h> - 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 <libcamera/color_space.h> -#include <libcamera/libcamera.h> - #include <pybind11/operators.h> #include <pybind11/pybind11.h> #include <pybind11/stl.h> #include "py_main.h" +#include <libcamera/color_space.h> +#include <libcamera/libcamera.h> + 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 <libcamera/{{header}}> - #include <pybind11/pybind11.h> #include "py_main.h" +#include <libcamera/{{header}}> + 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 <libcamera/libcamera.h> - #include <pybind11/pybind11.h> #include "py_main.h" +#include <libcamera/libcamera.h> + 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..9da3a3c79 100644 --- a/src/py/libcamera/py_formats_generated.cpp.in +++ b/src/py/libcamera/py_formats_generated.cpp.in @@ -7,12 +7,12 @@ * This file is auto-generated. Do not edit. */ -#include <libcamera/formats.h> - #include <pybind11/pybind11.h> #include "py_main.h" +#include <libcamera/formats.h> + namespace py = pybind11; class PyFormats 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 <array> - -#include <libcamera/geometry.h> -#include <libcamera/libcamera.h> - #include <pybind11/operators.h> #include <pybind11/pybind11.h> #include <pybind11/stl.h> #include "py_main.h" +#include <array> + +#include <libcamera/geometry.h> +#include <libcamera/libcamera.h> + 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 <tomi.valkeinen@ideasonboard.com> */ -#include "py_helpers.h" - -#include <libcamera/libcamera.h> - #include <pybind11/functional.h> #include <pybind11/stl.h> #include <pybind11/stl_bind.h> +#include "py_helpers.h" + +#include <libcamera/libcamera.h> + 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 <libcamera/libcamera.h> - #include <pybind11/pybind11.h> +#include <libcamera/libcamera.h> + 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 <pybind11/functional.h> +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> +#include <pybind11/stl_bind.h> + +#include "py_camera_manager.h" +#include "py_helpers.h" #include "py_main.h" #include <limits> @@ -17,14 +24,6 @@ #include <libcamera/libcamera.h> -#include <pybind11/functional.h> -#include <pybind11/pybind11.h> -#include <pybind11/stl.h> -#include <pybind11/stl_bind.h> - -#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 <libcamera/base/log.h> - #include <pybind11/pybind11.h> +#include <libcamera/base/log.h> + 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 <libcamera/transform.h> -#include <libcamera/libcamera.h> - #include <pybind11/operators.h> #include <pybind11/pybind11.h> #include <pybind11/stl.h> #include "py_main.h" +#include <libcamera/transform.h> +#include <libcamera/libcamera.h> + namespace py = pybind11; using namespace libcamera;
Python.h hence the pybind headers 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 `<pybind11/...>` headers are included first and then the local `"py_..."` headers, and then everything else. Also adjust `.clang-format` 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 <barnabas.pocze@ideasonboard.com> --- .clang-format | 6 ++++++ src/py/libcamera/py_camera_manager.cpp | 3 +-- 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, 41 insertions(+), 37 deletions(-)