From: Vincent Fazio <vfazio@gmail.com>
To: linux-gpio@vger.kernel.org
Cc: brgl@kernel.org, Vincent Fazio <vfazio@gmail.com>
Subject: [libgpiod][PATCH v2 11/14] bindings: python: include Python.h before other headers
Date: Sat, 24 Oct 2026 15:00:45 -0500 [thread overview]
Message-ID: <20261024200048.25987-3-vfazio@gmail.com> (raw)
In-Reply-To: <20261024200048.25987-1-vfazio@gmail.com>
Per the Python C API reference manual [0], Python.h should be included
before other headers since it specifies some pre-processor definitions
that may differ from system defaults.
This was noticed when testing on CPython 3.15 [1] which emitted warnings
due to redefinitions of _XOPEN_SOURCE and _POSIX_C_SOURCE during builds
of the Python bindings.
Note: despite the manual stating that `PY_SSIZE_T_CLEAN` should also be
defined, it is intentionally not included. The Python bindings do not
use the `#` format specifier when parsing any arguments so defining it
provides no value [2] and it is deprecated in future versions.
[0]: https://docs.python.org/3/c-api/intro.html#include-files
[1]: https://github.com/python/cpython/commit/927eb448aad6436d794ec9f55780013e25609600
[2]: https://docs.python.org/3/c-api/arg.html#strings-and-buffers
Signed-off-by: Vincent Fazio <vfazio@gmail.com>
---
Changes in v2:
- Add an blank line between Python.h and other includes (Bartosz)
---
bindings/python/gpiod/ext/internal.h | 3 ++-
bindings/python/gpiod/ext/module.c | 3 ++-
bindings/python/tests/gpiosim/ext.c | 3 ++-
bindings/python/tests/system/ext.c | 1 +
4 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/bindings/python/gpiod/ext/internal.h b/bindings/python/gpiod/ext/internal.h
index 2996884..b600071 100644
--- a/bindings/python/gpiod/ext/internal.h
+++ b/bindings/python/gpiod/ext/internal.h
@@ -4,9 +4,10 @@
#ifndef __LIBGPIOD_PYTHON_MODULE_H__
#define __LIBGPIOD_PYTHON_MODULE_H__
-#include <gpiod.h>
#include <Python.h>
+#include <gpiod.h>
+
PyObject *Py_gpiod_SetErrFromErrno(void);
unsigned int Py_gpiod_PyLongAsUnsignedInt(PyObject *pylong);
void Py_gpiod_dealloc(PyObject *self);
diff --git a/bindings/python/gpiod/ext/module.c b/bindings/python/gpiod/ext/module.c
index 21ea519..f13b86e 100644
--- a/bindings/python/gpiod/ext/module.c
+++ b/bindings/python/gpiod/ext/module.c
@@ -1,9 +1,10 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
-#include <gpiod.h>
#include <Python.h>
+#include <gpiod.h>
+
struct module_const {
const char *name;
long val;
diff --git a/bindings/python/tests/gpiosim/ext.c b/bindings/python/tests/gpiosim/ext.c
index cc7bd37..e3cb2ef 100644
--- a/bindings/python/tests/gpiosim/ext.c
+++ b/bindings/python/tests/gpiosim/ext.c
@@ -1,9 +1,10 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
-#include <gpiosim.h>
#include <Python.h>
+#include <gpiosim.h>
+
struct module_const {
const char *name;
long val;
diff --git a/bindings/python/tests/system/ext.c b/bindings/python/tests/system/ext.c
index 8b307f6..7d8304d 100644
--- a/bindings/python/tests/system/ext.c
+++ b/bindings/python/tests/system/ext.c
@@ -3,6 +3,7 @@
// SPDX-FileCopyrightText: 2024 Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
#include <Python.h>
+
#include <linux/version.h>
#include <sys/prctl.h>
#include <sys/utsname.h>
--
2.43.0
next prev parent reply other threads:[~2026-10-24 20:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-24 20:00 [libgpiod][PATCH v2 09/14] bindings: python: chip: use literals for dict/list and declare types Vincent Fazio
2026-10-24 20:00 ` [libgpiod][PATCH v2 10/14] bindings: python: bump ruff linter dependency Vincent Fazio
2026-10-24 20:00 ` Vincent Fazio [this message]
2026-10-24 20:00 ` [libgpiod][PATCH v2 12/14] bindings: python: advertise Python 3.15 support Vincent Fazio
2026-10-24 20:00 ` [libgpiod][PATCH v2 13/14] bindings: python: fix directory validation in artifact script Vincent Fazio
2026-10-24 20:00 ` [libgpiod][PATCH v2 14/14] bindings: python: bump dependencies " Vincent Fazio
2026-10-28 9:19 ` [libgpiod][PATCH v2 09/14] bindings: python: chip: use literals for dict/list and declare types Bartosz Golaszewski
-- strict thread matches above, loose matches on Subject: below --
2026-10-20 21:12 [libgpiod][PATCH v2 11/14] bindings: python: include Python.h before other headers Vincent Fazio
2026-10-21 7:56 ` Bartosz Golaszewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261024200048.25987-3-vfazio@gmail.com \
--to=vfazio@gmail.com \
--cc=brgl@kernel.org \
--cc=linux-gpio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.