[lldb] Use (only) PyImport_AppendInittab to patch readline (#153329)

The current implementation tries to (1) patch the existing readline
module definition if it's already present in the inittab and (2) append
our patched readline module to the inittab. The former (1) uses the
non-stable Python API and I can't find a situation where this is
necessary. 

We do this work before initialization, so for the readline
module to exist, it either needs to be added by Python itself (which
doesn't seem to be the case), or someone would have had to have added it
without initializing.
This commit is contained in:
Jonas Devlieghere authored and GitHub committed 2025-08-14 13:47:48 -05:00
1 parent 20a829937c
commit b62b65a95f
1 file changed
+1 -11
@@ -98,17 +98,7 @@ public:
#ifdef LLDB_USE_LIBEDIT_READLINE_COMPAT_MODULE
// Python's readline is incompatible with libedit being linked into lldb.
// Provide a patched version local to the embedded interpreter.
bool ReadlinePatched = false;
for (auto *p = PyImport_Inittab; p->name != nullptr; p++) {
if (strcmp(p->name, "readline") == 0) {
p->initfunc = initlldb_readline;
break;
}
}
if (!ReadlinePatched) {
PyImport_AppendInittab("readline", initlldb_readline);
ReadlinePatched = true;
}
PyImport_AppendInittab("readline", initlldb_readline);
#endif
// Register _lldb as a built-in module.