Closed
Description
While trying to update lldb to work with Python >= 3.12, I found the following issue:
Starting with Python 3.12, there is code now preventing the usage of PyImport_AppendInittab
after Py_Initialize()
.
However, according to this source code comment:
We cannot control what external code may have done before getting to this point in LLDB,
including potentially having already initialized Python...
This is causing the following failures:
Failed Tests (19):
lldb-unit :: ScriptInterpreter/Python/./ScriptInterpreterPythonTests/0/20
lldb-unit :: ScriptInterpreter/Python/./ScriptInterpreterPythonTests/1/20
lldb-unit :: ScriptInterpreter/Python/./ScriptInterpreterPythonTests/10/20
lldb-unit :: ScriptInterpreter/Python/./ScriptInterpreterPythonTests/11/20
lldb-unit :: ScriptInterpreter/Python/./ScriptInterpreterPythonTests/12/20
lldb-unit :: ScriptInterpreter/Python/./ScriptInterpreterPythonTests/13/20
lldb-unit :: ScriptInterpreter/Python/./ScriptInterpreterPythonTests/14/20
lldb-unit :: ScriptInterpreter/Python/./ScriptInterpreterPythonTests/15/20
lldb-unit :: ScriptInterpreter/Python/./ScriptInterpreterPythonTests/16/20
lldb-unit :: ScriptInterpreter/Python/./ScriptInterpreterPythonTests/17/20
lldb-unit :: ScriptInterpreter/Python/./ScriptInterpreterPythonTests/18/20
lldb-unit :: ScriptInterpreter/Python/./ScriptInterpreterPythonTests/2/20
lldb-unit :: ScriptInterpreter/Python/./ScriptInterpreterPythonTests/3/20
lldb-unit :: ScriptInterpreter/Python/./ScriptInterpreterPythonTests/4/20
lldb-unit :: ScriptInterpreter/Python/./ScriptInterpreterPythonTests/5/20
lldb-unit :: ScriptInterpreter/Python/./ScriptInterpreterPythonTests/6/20
lldb-unit :: ScriptInterpreter/Python/./ScriptInterpreterPythonTests/7/20
lldb-unit :: ScriptInterpreter/Python/./ScriptInterpreterPythonTests/8/20
lldb-unit :: ScriptInterpreter/Python/./ScriptInterpreterPythonTests/9/20
With the following output:
Fatal Python error: PyImport_AppendInittab: PyImport_AppendInittab() may not be called after Py_Initialize()
Python runtime state: initialized
Current thread 0x00007f60b876c300 (most recent call first):
<no Python frame>
#0 0x00007f60b059bceb llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/build/llvm-build.f39/lib/libLLVM-
18git.so+0x79bceb)
#1 0x00007f60b05992ab SignalHandler(int) Signals.cpp:0:0
#2 0x00007f60afa089a0 __restore_rt (/lib64/libc.so.6+0x3e9a0)
#3 0x00007f60afa5a834 __pthread_kill_implementation (/lib64/libc.so.6+0x90834)
#4 0x00007f60afa088ee gsignal (/lib64/libc.so.6+0x3e8ee)
#5 0x00007f60af9f08ff abort (/lib64/libc.so.6+0x268ff)
#6 0x00007f60b435acaa /usr/src/debug/python3.12-3.12.0-1.fc39.x86_64/Python/pylifecycle.c:2712:0
#7 0x00007f60b435acaa /usr/src/debug/python3.12-3.12.0-1.fc39.x86_64/Python/pylifecycle.c:2820:0
#8 0x00007f60b435b020 /usr/src/debug/python3.12-3.12.0-1.fc39.x86_64/Modules/faulthandler.c:1035:0
#9 0x00007f60b42b2a6c /usr/include/bits/string_fortified.h:59:10
#10 0x00007f60b42b2a6c PyImport_AppendInittab /usr/src/debug/python3.12-3.12.0-1.fc39.x86_64/Python/import.c:1
502:5
#11 0x0000000000480faf lldb_private::ScriptInterpreterPythonImpl::Initialize() (/build/llvm-build.f39/tools/ll
db/unittests/ScriptInterpreter/Python/./ScriptInterpreterPythonTests+0x480faf)
#12 0x000000000044cded PythonTestSuite::SetUp() (/build/llvm-build.f39/tools/lldb/unittests/ScriptInterpreter/
Python/./ScriptInterpreterPythonTests+0x44cded)
#13 0x0000000000441789 PythonDataObjectsTest::SetUp() NameMatches.cpp:0:0
#14 0x0000000000465687 testing::Test::Run() (.part.0) gtest-all.cc:0:0
#15 0x000000000046a58a testing::TestInfo::Run() (/build/llvm-build.f39/tools/lldb/unittests/ScriptInterpreter/
Python/./ScriptInterpreterPythonTests+0x46a58a)
#16 0x000000000046abcc testing::TestSuite::Run() (.part.0) gtest-all.cc:0:0
#17 0x0000000000471d10 testing::internal::UnitTestImpl::RunAllTests() (/build/llvm-build.f39/tools/lldb/unitte
sts/ScriptInterpreter/Python/./ScriptInterpreterPythonTests+0x471d10)
#18 0x000000000046503e testing::UnitTest::Run() (/build/llvm-build.f39/tools/lldb/unittests/ScriptInterpreter/
Python/./ScriptInterpreterPythonTests+0x46503e)
#19 0x000000000042ab26 main (/build/llvm-build.f39/tools/lldb/unittests/ScriptInterpreter/Python/./ScriptInter
preterPythonTests+0x42ab26)
#20 0x00007f60af9f214a __libc_start_call_main (/lib64/libc.so.6+0x2814a)
#21 0x00007f60af9f220b __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x2820b)
#22 0x000000000042b1a5 _start (/build/llvm-build.f39/tools/lldb/unittests/ScriptInterpreter/Python/./ScriptInt
erpreterPythonTests+0x42b1a5)
One can reduce the list of failures to 2 by guaranteeing the critical code in InitializePythonRAII()
is executed only once.
But it still doesn't solve all the cases.