From: Wouter Deconinck Date: Wed, 24 Dec 2025 21:49:34 +0000 (-0600) Subject: fix: use Py_REFCNT macro to work with free-threaded python X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a51ad9408317d0896bcf839714822412f9aacef4;p=thirdparty%2Futil-linux.git fix: use Py_REFCNT macro to work with free-threaded python --- diff --git a/configure.ac b/configure.ac index 9fafeed04..6de222e84 100644 --- a/configure.ac +++ b/configure.ac @@ -2850,6 +2850,9 @@ AC_ARG_WITH([python], [], [with_python=check withval=check] ) +# Minimum required Python version defined by use of Py_REFCNT +m4_define([MIN_PYTHON_VER], [2.6]) + have_python=no have_libpython=no AS_IF([test "x$with_python" != xno], [ @@ -2870,6 +2873,9 @@ AS_IF([test "x$with_python" != xno], [ [*:yes], # check for python development stuff [ + AX_COMPARE_VERSION([$PYTHON_VERSION], [lt], [MIN_PYTHON_VER], + [AC_MSG_ERROR([python version $PYTHON_VERSION is too old])]) + PKG_CHECK_MODULES([PYTHON], [python-$PYTHON_VERSION], [have_libpython=yes], [have_libpython=no]) # https://github.com/util-linux/util-linux/issues/2366 diff --git a/libmount/python/fs.c b/libmount/python/fs.c index cb48c43a1..0ec52aeed 100644 --- a/libmount/python/fs.c +++ b/libmount/python/fs.c @@ -640,7 +640,7 @@ static PyMethodDef Fs_methods[] = { static void Fs_destructor(FsObject *self) { DBG(FS, pymnt_debug_h(self->fs, "destructor py-obj: %p, py-refcnt=%d", - self, (int) ((PyObject *) self)->ob_refcnt)); + self, (int) Py_REFCNT((PyObject *) self))); mnt_unref_fs(self->fs); PyFree(self); } @@ -774,7 +774,7 @@ PyObject *PyObjectResultFs(struct libmnt_fs *fs) if (result) { Py_INCREF(result); DBG(FS, pymnt_debug_h(fs, "result py-obj %p: already exists, py-refcnt=%d", - result, (int) ((PyObject *) result)->ob_refcnt)); + result, (int) Py_REFCNT((PyObject *) result))); return (PyObject *) result; } @@ -792,7 +792,7 @@ PyObject *PyObjectResultFs(struct libmnt_fs *fs) mnt_ref_fs(fs); DBG(FS, pymnt_debug_h(fs, "result py-obj %p new, py-refcnt=%d", - result, (int) ((PyObject *) result)->ob_refcnt)); + result, (int) Py_REFCNT((PyObject *) result))); result->fs = fs; mnt_fs_set_userdata(fs, result); return (PyObject *) result; diff --git a/libmount/python/tab.c b/libmount/python/tab.c index 14a39da85..8b7e75e6a 100644 --- a/libmount/python/tab.c +++ b/libmount/python/tab.c @@ -548,7 +548,7 @@ void Table_unref(struct libmnt_table *tab) static void Table_destructor(TableObject *self) { DBG(TAB, pymnt_debug_h(self->tab, "destructor py-obj: %p, py-refcnt=%d", - self, (int) ((PyObject *) self)->ob_refcnt)); + self, (int) Py_REFCNT((PyObject *) self))); Table_unref(self->tab); self->tab = NULL; @@ -683,7 +683,7 @@ PyObject *PyObjectResultTab(struct libmnt_table *tab) if (result) { Py_INCREF(result); DBG(TAB, pymnt_debug_h(tab, "result py-obj %p: already exists, py-refcnt=%d", - result, (int) ((PyObject *) result)->ob_refcnt)); + result, (int) Py_REFCNT((PyObject *) result))); return (PyObject *) result; } @@ -701,7 +701,7 @@ PyObject *PyObjectResultTab(struct libmnt_table *tab) mnt_ref_table(tab); DBG(TAB, pymnt_debug_h(tab, "result py-obj %p new, py-refcnt=%d", - result, (int) ((PyObject *) result)->ob_refcnt)); + result, (int) Py_REFCNT((PyObject *) result))); result->tab = tab; result->iter = mnt_new_iter(MNT_ITER_FORWARD); mnt_table_set_userdata(result->tab, result);