From: Vincent Fazio <vfazio@gmail.com>
To: linux-gpio@vger.kernel.org
Cc: Vincent Fazio <vfazio@gmail.com>
Subject: [libgpiod][PATCH 6/9] bindings: python: use PyImport_ImportModuleAttrString when available
Date: Tue, 21 Apr 2026 20:20:38 -0500 [thread overview]
Message-ID: <20260422012041.39933-7-vfazio@gmail.com> (raw)
In-Reply-To: <20260422012041.39933-1-vfazio@gmail.com>
Commit 035ad74fdd introduced Py_gpiod_GetModuleAttrString as a way to
get a module's attribute and was inspired by CPython's internal function
_PyImport_GetModuleAttrString.
CPython 3.14 added PyImport_ImportModuleAttrString to the public API [0]
which allows us to use the standard function when available.
[0]: https://github.com/python/cpython/pull/128912
Signed-off-by: Vincent Fazio <vfazio@gmail.com>
---
bindings/python/gpiod/ext/common.c | 3 +++
bindings/python/gpiod/ext/internal.h | 10 ++++++++--
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/bindings/python/gpiod/ext/common.c b/bindings/python/gpiod/ext/common.c
index 7d2dda7..fc28e96 100644
--- a/bindings/python/gpiod/ext/common.c
+++ b/bindings/python/gpiod/ext/common.c
@@ -64,6 +64,8 @@ PyObject *Py_gpiod_SetErrFromErrno(void)
return PyErr_SetFromErrno(exc);
}
+/* TODO: remove when 3.14 is the minimum version */
+#if PY_VERSION_HEX < 0x030E0000
PyObject *Py_gpiod_GetModuleAttrString(const char *modname,
const char *attrname)
{
@@ -78,6 +80,7 @@ PyObject *Py_gpiod_GetModuleAttrString(const char *modname,
return attribute;
}
+#endif
unsigned int Py_gpiod_PyLongAsUnsignedInt(PyObject *pylong)
{
diff --git a/bindings/python/gpiod/ext/internal.h b/bindings/python/gpiod/ext/internal.h
index 15aedfb..2996884 100644
--- a/bindings/python/gpiod/ext/internal.h
+++ b/bindings/python/gpiod/ext/internal.h
@@ -8,8 +8,6 @@
#include <Python.h>
PyObject *Py_gpiod_SetErrFromErrno(void);
-PyObject *Py_gpiod_GetModuleAttrString(const char *modname,
- const char *attrname);
unsigned int Py_gpiod_PyLongAsUnsignedInt(PyObject *pylong);
void Py_gpiod_dealloc(PyObject *self);
PyObject *Py_gpiod_MakeRequestObject(struct gpiod_line_request *request,
@@ -17,4 +15,12 @@ PyObject *Py_gpiod_MakeRequestObject(struct gpiod_line_request *request,
struct gpiod_line_config *Py_gpiod_LineConfigGetData(PyObject *obj);
struct gpiod_line_settings *Py_gpiod_LineSettingsGetData(PyObject *obj);
+#if PY_VERSION_HEX >= 0x030E0000
+/* Alias to standard function available in 3.14 */
+#define Py_gpiod_GetModuleAttrString PyImport_ImportModuleAttrString
+#else
+PyObject *Py_gpiod_GetModuleAttrString(const char *modname,
+ const char *attrname);
+#endif /* PY_VERSION_HEX >= 0x030E0000 */
+
#endif /* __LIBGPIOD_PYTHON_MODULE_H__ */
--
2.43.0
next prev parent reply other threads:[~2026-04-22 1:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-22 1:20 [libgpiod][PATCH 0/9] bindings: python: modernize C extensions Vincent Fazio
2026-04-22 1:20 ` [libgpiod][PATCH 1/9] bindings: python: use Py_RETURN_NONE in chip_get_line_name Vincent Fazio
2026-04-22 1:20 ` [libgpiod][PATCH 2/9] bindings: python: avoid PyObject_CallMethod during chip finalize Vincent Fazio
2026-04-22 1:20 ` [libgpiod][PATCH 3/9] bindings: python: avoid PyObject_CallMethod during request finalize Vincent Fazio
2026-04-22 1:20 ` [libgpiod][PATCH 4/9] bindings: python: simplify disallowing _ext.Request from being created Vincent Fazio
2026-04-22 1:20 ` [libgpiod][PATCH 5/9] bindings: python: use suggestions from upgrade_pythoncapi.py Vincent Fazio
2026-04-22 1:20 ` Vincent Fazio [this message]
2026-04-22 1:20 ` [libgpiod][PATCH 7/9] bindings: python: migrate the gpiod._ext module to multi-phase init Vincent Fazio
2026-04-22 1:20 ` [libgpiod][PATCH 8/9] bindings: python: tests: migrate the system " Vincent Fazio
2026-04-22 1:20 ` [libgpiod][PATCH 9/9] bindings: python: tests: migrate the gpiosim " Vincent Fazio
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=20260422012041.39933-7-vfazio@gmail.com \
--to=vfazio@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox