Index: scripts/Python/modules/readline/CMakeLists.txt =================================================================== --- scripts/Python/modules/readline/CMakeLists.txt +++ scripts/Python/modules/readline/CMakeLists.txt @@ -7,7 +7,7 @@ include_directories(${PYTHON_INCLUDE_DIR}) add_library(readline SHARED readline.cpp) -target_link_libraries(readline ${PYTHON_LIBRARY}) +target_link_libraries(readline ${PYTHON_LIBRARY} edit) # FIXME: the LIBRARY_OUTPUT_PATH seems to be ignored - this is not a # functional issue for the build dir, though, since the shared lib dir Index: scripts/Python/modules/readline/readline.cpp =================================================================== --- scripts/Python/modules/readline/readline.cpp +++ scripts/Python/modules/readline/readline.cpp @@ -1,10 +1,12 @@ #include #include "Python.h" +#include -// Python readline module intentionally built to not implement the -// readline module interface. This is meant to work around llvm -// pr18841 to avoid seg faults in the stock Python readline.so linked -// against GNU readline. +// Simple implementation of the Python readline module using libedit. +// Currently it only installs a PyOS_ReadlineFunctionPointer, without +// implementing any of the readline module methods. This is meant to +// work around LLVM pr18841 to avoid seg faults in the stock Python +// readline.so linked against GNU readline. static struct PyMethodDef moduleMethods[] = { @@ -13,11 +15,36 @@ PyDoc_STRVAR( moduleDocumentation, - "Stub module meant to effectively disable readline support."); + "Stub module meant to avoid linking GNU readline."); + +static char* +simple_readline(FILE *stdin, FILE *stdout, char *prompt) +{ + rl_instream = stdin; + rl_outstream = stdout; + char* line = readline(prompt); + if (!line) + { + char* ret = (char*)PyMem_Malloc(1); + if (ret != NULL) + *ret = '\0'; + return ret; + } + if (*line) + add_history(line); + int n = strlen(line); + char* ret = (char*)PyMem_Malloc(n + 2); + strncpy(ret, line, n); + free(line); + ret[n] = '\n'; + ret[n+1] = '\0'; + return ret; +} PyMODINIT_FUNC initreadline(void) { + PyOS_ReadlineFunctionPointer = simple_readline; Py_InitModule4( "readline", moduleMethods,