[all-commits] [llvm/llvm-project] fbce24: [lldb] Call Import_AppendInittab before Py_Initial...
Jonas Devlieghere via All-commits
all-commits at lists.llvm.org
Sat Feb 17 15:10:21 PST 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: fbce244299524fc3d736cce9d25b4262303b45d5
https://github.com/llvm/llvm-project/commit/fbce244299524fc3d736cce9d25b4262303b45d5
Author: Jonas Devlieghere <jonas at devlieghere.com>
Date: 2024-02-17 (Sat, 17 Feb 2024)
Changed paths:
M lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
Log Message:
-----------
[lldb] Call Import_AppendInittab before Py_Initialize (#82095)
The Python documentation [1] says that `PyImport_AppendInittab` should
be called before `Py_Initialize()`. Starting with Python 3.12, this is
enforced with a fatal error:
Fatal Python error: PyImport_AppendInittab: PyImport_AppendInittab()
may not be called after Py_Initialize()
This commit ensures we only modify the table of built-in modules if
Python hasn't been initialized. For Python embedded in LLDB, that means
this happen exactly once, before the first call to `Py_Initialize`,
which becomes a NO-OP after. However, when lldb is imported in an
existing Python interpreter, Python will have already been initialized,
but by definition, the lldb module will already have been loaded, so
it's safe to skip adding it (again).
This fixes #70453.
[1] https://docs.python.org/3.12/c-api/import.html#c.PyImport_AppendInittab
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list