ribrdb created this revision. ribrdb added a reviewer: tfiala. ribrdb added a subscriber: lldb-commits. ribrdb set the repository for this revision to rL LLVM.
This implements basic line editing for the interactive python interpreter on linux. No tab completion, but at least backspace works. Repository: rL LLVM http://reviews.llvm.org/D13268 Files: scripts/Python/modules/readline/CMakeLists.txt scripts/Python/modules/readline/readline.cpp Index: scripts/Python/modules/readline/readline.cpp =================================================================== --- scripts/Python/modules/readline/readline.cpp +++ scripts/Python/modules/readline/readline.cpp @@ -1,5 +1,6 @@ #include <stdio.h> #include "Python.h" +#include <editline/readline.h> // Python readline module intentionally built to not implement the // readline module interface. This is meant to work around llvm @@ -15,9 +16,34 @@ moduleDocumentation, "Stub module meant to effectively disable readline support."); +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, 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,5 +1,6 @@ #include <stdio.h> #include "Python.h" +#include <editline/readline.h> // Python readline module intentionally built to not implement the // readline module interface. This is meant to work around llvm @@ -15,9 +16,34 @@ moduleDocumentation, "Stub module meant to effectively disable readline support."); +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, 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
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits