1 #include "PythonReadline.h"
3 #ifdef LLDB_USE_LIBEDIT_READLINE_COMPAT_MODULE
7 #include <editline/readline.h>
9 // Simple implementation of the Python readline module using libedit.
10 // In the event that libedit is excluded from the build, this turns
11 // back into a null implementation that blocks the module from pulling
12 // in the GNU readline shared lib, which causes linkage confusion when
13 // both readline and libedit's readline compatibility symbols collide.
15 // Currently it only installs a PyOS_ReadlineFunctionPointer, without
16 // implementing any of the readline module methods. This is meant to
17 // work around LLVM pr18841 to avoid seg faults in the stock Python
18 // readline.so linked against GNU readline.
20 // Bug on the cpython side: https://bugs.python.org/issue38634
22 PyDoc_STRVAR(moduleDocumentation
,
23 "Simple readline module implementation based on libedit.");
25 static struct PyModuleDef readline_module
= {
26 PyModuleDef_HEAD_INIT
, // m_base
27 "lldb_editline", // m_name
28 moduleDocumentation
, // m_doc
32 nullptr, // m_traverse
37 static char *simple_readline(FILE *stdin
, FILE *stdout
, const char *prompt
) {
39 rl_outstream
= stdout
;
40 char *line
= readline(prompt
);
42 char *ret
= (char *)PyMem_RawMalloc(1);
50 char *ret
= (char *)PyMem_RawMalloc(n
+ 2);
60 PyMODINIT_FUNC
initlldb_readline(void) {
61 PyOS_ReadlineFunctionPointer
= simple_readline
;
63 return PyModule_Create(&readline_module
);