Assertion failure in import-repeatedly test with Debian's python3.12-dbg or newer
To reproduce:
- Have a Debian or Ubuntu version where Python is 3.12 or later
- Install
python3-dbg
andpython3-dev
meson setup -Dpython=python3-dbg ${builddir}
meson compile -C ${builddir}
meson test -C ${builddir}
where test/import-repeatedly.py
has the same contents as it did in 1.3.2:
/* Regression test for https://bugs.freedesktop.org/show_bug.cgi?id=23831 */
/*
* Copyright 2010-2016 Collabora Ltd.
* SPDX-License-Identifier: MIT
*/
#include <stdio.h>
#include <Python.h>
int main(void)
{
int i;
puts("1..1");
for (i = 0; i < 100; ++i) {
Py_Initialize();
if (PyRun_SimpleString("import dbus\n") != 0) {
puts("not ok 1 - there was an exception");
return 1;
}
Py_Finalize();
}
puts("ok 1 - was able to import dbus 100 times");
return 0;
}
Expected result: tests pass, as they do for Python 3.11 or older, or for plain python3
rather than python3-dbg
.
Actual result: it crashes out with this assertion failure:
test-import-repeatedly: ../Objects/dictobject.c:1140: compare_unicode_unicode: Assertion `PyUnicode_CheckExact(ep_key)' failed.
Workarounds: any one of:
- Only initialize and finalize Python once (move
Py_Initialize()
andPy_Finalize()
outside the loop) - Use Python 3.11 or older
- Use the ordinary
python3
interpreter instead of thepython3-dbg
debug interpreter
It is not clear to me whether this is a Python regression, or whether dbus-python is doing something wrong,or what. Anyone who wants to embed dbus-python in a larger process, and be able to initialize and finalize the Python interpreter more than once, is invited to investigate this.