Skip to content

Commit e94715a

Browse files
committed
bindings: python: use PyImport_ImportModuleAttrString when available
Commit 035ad74 introduced Py_gpiod_GetModuleAttrString as a copy of an internal function used by CPython to get module attributes. CPython 3.14 added PyImport_ImportModuleAttrString to the public API which allows us to use the standard function when available. [0]: python/cpython#128912 Signed-off-by: Vincent Fazio <vfazio@gmail.com>
1 parent 456bb85 commit e94715a

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

bindings/python/gpiod/ext/common.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ PyObject *Py_gpiod_SetErrFromErrno(void)
6464
return PyErr_SetFromErrno(exc);
6565
}
6666

67+
#if PY_VERSION_HEX < 0x030E0000
6768
PyObject *Py_gpiod_GetModuleAttrString(const char *modname,
6869
const char *attrname)
6970
{
@@ -78,6 +79,7 @@ PyObject *Py_gpiod_GetModuleAttrString(const char *modname,
7879

7980
return attribute;
8081
}
82+
#endif
8183

8284
unsigned int Py_gpiod_PyLongAsUnsignedInt(PyObject *pylong)
8385
{

bindings/python/gpiod/ext/internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
#include <Python.h>
99

1010
PyObject *Py_gpiod_SetErrFromErrno(void);
11+
#if PY_VERSION_HEX < 0x030E0000
1112
PyObject *Py_gpiod_GetModuleAttrString(const char *modname,
1213
const char *attrname);
14+
#else
15+
#define Py_gpiod_GetModuleAttrString PyImport_ImportModuleAttrString
16+
#endif
1317
unsigned int Py_gpiod_PyLongAsUnsignedInt(PyObject *pylong);
1418
void Py_gpiod_dealloc(PyObject *self);
1519
PyObject *Py_gpiod_MakeRequestObject(struct gpiod_line_request *request,

0 commit comments

Comments
 (0)