cpython: 1e03fd72e116 (original) (raw)
Mercurial > cpython
changeset 86265:1e03fd72e116 2.7
Issue #18458: Prevent crashes with newer versions of libedit. Its readline emulation has changed from 0-based indexing to 1-based like gnu readline. Original patch by Ronald Oussoren. [#18458]
Ned Deily nad@acm.org | |
---|---|
date | Sat, 12 Oct 2013 15:45:25 -0700 |
parents | ced6d02097e6 |
children | 3e2525d640d5 |
files | Misc/NEWS Modules/readline.c |
diffstat | 2 files changed, 29 insertions(+), 15 deletions(-)[+] [-] Misc/NEWS 4 Modules/readline.c 40 |
line wrap: on
line diff
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -32,6 +32,10 @@ Core and Builtins Library ------- +- Issue #18458: Prevent crashes with newer versions of libedit. Its readline
- emulation has changed from 0-based indexing to 1-based like gnu readline.
- Original patch by Ronald Oussoren. +
- Issue #18919: If the close() method of a writer in the sunau or wave module failed, second invocation of close() and destructor no more raise an exception. Second invocation of close() on sunau writer now has no effects.
--- a/Modules/readline.c +++ b/Modules/readline.c @@ -54,14 +54,16 @@ extern char **completion_matches(char *,
- with the "real" readline and cannot be detected at compile-time,
- hence we use a runtime check to detect if we're using libedit *
#endif /* APPLE */ static void @@ -555,21 +557,21 @@ get_history_item(PyObject *self, PyObjec return NULL; #ifdef APPLE if (using_libedit_emulation) {
/* Libedit emulation uses 0-based indexes,[](#l2.27)
* the real one uses 1-based indexes,[](#l2.28)
* adjust the index to ensure that Python[](#l2.29)
* code doesn't have to worry about the[](#l2.30)
* difference.[](#l2.31)
/* Older versions of libedit's readline emulation[](#l2.32)
* use 0-based indexes, while readline and newer[](#l2.33)
* versions of libedit use 1-based indexes.[](#l2.34) */[](#l2.35) int length = _py_get_history_length();[](#l2.36)
idx --;[](#l2.37)
idx = idx - 1 + libedit_history_start;[](#l2.39)
/* * Apple's readline emulation crashes when * the index is out of range, therefore * test for that and fail gracefully. */
if (idx < 0 || idx >= length) {[](#l2.46)
if (idx < (0 + libedit_history_start)[](#l2.47)
} @@ -883,6 +885,17 @@ setup_readline(void) */ if (using_libedit_emulation) rl_initialize();|| idx >= (length + libedit_history_start)) {[](#l2.48) Py_RETURN_NONE;[](#l2.49) }[](#l2.50)
- /* Detect if libedit's readline emulation uses 0-based
* indexing or 1-based indexing.[](#l2.58)
*/[](#l2.59)
- add_history("1");
- if (history_get(1) == NULL) {
libedit_history_start = 0;[](#l2.62)
- } else {
libedit_history_start = 1;[](#l2.64)
- }
- clear_history();
#endif /* APPLE */ using_history(); @@ -1090,11 +1103,8 @@ call_readline(FILE *sys_stdin, FILE *sys if (length > 0) #ifdef APPLE if (using_libedit_emulation) {
/*[](#l2.74)
* Libedit's emulation uses 0-based indexes,[](#l2.75)
* the real readline uses 1-based indexes.[](#l2.76)
*/[](#l2.77)
line = history_get(length - 1)->line;[](#l2.78)
/* handle older 0-based or newer 1-based indexing */[](#l2.79)
line = history_get(length + libedit_history_start - 1)->line;[](#l2.80) } else[](#l2.81)