Skip to content

Commit db5f134

Browse files
committed
python: add combat shim for older distros
Newer SWIG started generating Py_NewRef() calls in its own runtime boilerplate, but Py_NewRef wasn't added until Python 3.10. The mismatch hits any distro with SWIG ≥ 4.1 but Python < 3.10. Suggested-by: Martin Belanger <[email protected]> Signed-off-by: Daniel Wagner <[email protected]>
1 parent f018b37 commit db5f134

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

libnvme/libnvme/meson.build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
# Authors: Martin Belanger <[email protected]>
77
#
88
if want_python
9+
if not cc.has_header_symbol('Python.h', 'Py_NewRef', dependencies: py3_dep)
10+
warning('Python < 3.10 detected: providing Py_NewRef compatibility shim')
11+
endif
12+
913
r = run_command(swig, ['-version'], check: true) # Returns: "\nSWIG Version 4.1.1\n\nCompiled with ..."
1014
swig_version = r.stdout().split('\n')[1].split()[2].strip()
1115
if swig_version.version_compare('<4.1.0')

libnvme/libnvme/nvme.i

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@
1010
clashes with the same macro defined in Python.h.
1111
*/
1212
#undef fallthrough
13+
14+
#include <Python.h>
15+
16+
/*
17+
* Py_NewRef was added in Python 3.10; provide a compat shim for
18+
* older versions
19+
*/
20+
#if PY_VERSION_HEX < 0x030a0000
21+
static inline PyObject *Py_NewRef(PyObject *obj)
22+
{
23+
Py_INCREF(obj);
24+
return obj;
25+
}
26+
#endif
1327
%}
1428

1529
%module(docstring="Python bindings for libnvme") nvme

0 commit comments

Comments
 (0)