-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unix: upgrade libedit 20210910-3.1 -> 20240808-3.1 (#466)
We were soft blocked on upgrading due to musl compatibility issues. It looks like these got fixed upstream. So we refreshed the configure patch and libedit build _just worked_. However, Python 3.9 and 3.10 encountered compile errors with the newer version. On 3.10 we worked around this bug by backporting a patch from 3.11. On 3.9, the backport was non-trivial, so I just hacked up the existing 3.9 patch to manually change some C preprocessor checks to key off libedit. While diffing `Modules/readline.c` I found another patch related to fixing completer delims. While strictly not required, it was trivial to backport to 3.10 to fix some missing functionality. So I did. 3.13 initially didn't like the upgraded libedit because we were manually defining a preprocessor variable (introduced in 3.13 by upstream commit 8515fd79fef1ac16d7848cec5ec1797294cb5366). Removing the variable and letting configure deduce things with the newer libedit appears to _just work_. Perhaps upstream configure doesn't implement the feature detection properly on older libedit versions?
- Loading branch information
Showing
7 changed files
with
204 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
cpython-unix/patch-readline-libedit-completer-delims.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
diff --git a/Lib/test/test_readline.py b/Lib/test/test_readline.py | ||
index 835280f2281..6c2726d3209 100644 | ||
--- a/Lib/test/test_readline.py | ||
+++ b/Lib/test/test_readline.py | ||
@@ -5,6 +5,7 @@ | ||
import os | ||
import sys | ||
import tempfile | ||
+import textwrap | ||
import unittest | ||
from test.support import verbose | ||
from test.support.import_helper import import_module | ||
@@ -163,6 +164,25 @@ def test_auto_history_disabled(self): | ||
# end, so don't expect it in the output. | ||
self.assertIn(b"History length: 0", output) | ||
|
||
+ def test_set_complete_delims(self): | ||
+ script = textwrap.dedent(""" | ||
+ import readline | ||
+ def complete(text, state): | ||
+ if state == 0 and text == "$": | ||
+ return "$complete" | ||
+ return None | ||
+ if "libedit" in getattr(readline, "__doc__", ""): | ||
+ readline.parse_and_bind(r'bind "\\t" rl_complete') | ||
+ else: | ||
+ readline.parse_and_bind(r'"\\t": complete') | ||
+ readline.set_completer_delims(" \\t\\n") | ||
+ readline.set_completer(complete) | ||
+ print(input()) | ||
+ """) | ||
+ | ||
+ output = run_pty(script, input=b"$\t\n") | ||
+ self.assertIn(b"$complete", output) | ||
+ | ||
def test_nonascii(self): | ||
loc = locale.setlocale(locale.LC_CTYPE, None) | ||
if loc in ('C', 'POSIX'): | ||
diff --git a/Modules/readline.c b/Modules/readline.c | ||
index 8c7f526d418..1e13a0e6e06 100644 | ||
--- a/Modules/readline.c | ||
+++ b/Modules/readline.c | ||
@@ -572,6 +572,13 @@ readline_set_completer_delims(PyObject *module, PyObject *string) | ||
if (break_chars) { | ||
free(completer_word_break_characters); | ||
completer_word_break_characters = break_chars; | ||
+#ifdef WITH_EDITLINE | ||
+ rl_basic_word_break_characters = break_chars; | ||
+#else | ||
+ if (using_libedit_emulation) { | ||
+ rl_basic_word_break_characters = break_chars; | ||
+ } | ||
+#endif | ||
rl_completer_word_break_characters = break_chars; | ||
Py_RETURN_NONE; | ||
} | ||
@@ -1260,6 +1267,15 @@ setup_readline(readlinestate *mod_state) | ||
completer_word_break_characters = | ||
strdup(" \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?"); | ||
/* All nonalphanums except '.' */ | ||
+#ifdef WITH_EDITLINE | ||
+ // libedit uses rl_basic_word_break_characters instead of | ||
+ // rl_completer_word_break_characters as complete delimiter | ||
+ rl_basic_word_break_characters = completer_word_break_characters; | ||
+#else | ||
+ if (using_libedit_emulation) { | ||
+ rl_basic_word_break_characters = completer_word_break_characters; | ||
+ } | ||
+#endif | ||
rl_completer_word_break_characters = completer_word_break_characters; | ||
|
||
mod_state->begidx = PyLong_FromLong(0L); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
diff --git a/Modules/readline.c b/Modules/readline.c | ||
index 27b89de7279..8c7f526d418 100644 | ||
--- a/Modules/readline.c | ||
+++ b/Modules/readline.c | ||
@@ -440,7 +440,7 @@ readline_set_completion_display_matches_hook_impl(PyObject *module, | ||
default completion display. */ | ||
rl_completion_display_matches_hook = | ||
readlinestate_global->completion_display_matches_hook ? | ||
-#if defined(_RL_FUNCTION_TYPEDEF) | ||
+#if defined(HAVE_RL_COMPDISP_FUNC_T) | ||
(rl_compdisp_func_t *)on_completion_display_matches_hook : 0; | ||
#else | ||
(VFunction *)on_completion_display_matches_hook : 0; | ||
diff --git a/configure.ac b/configure.ac | ||
index e1cbb7c7fbe..629b7b76c3c 100644 | ||
--- a/configure.ac | ||
+++ b/configure.ac | ||
@@ -5918,6 +5918,20 @@ if test "$py_cv_lib_readline" = yes; then | ||
AC_CHECK_LIB($LIBREADLINE, append_history, | ||
AC_DEFINE(HAVE_RL_APPEND_HISTORY, 1, | ||
[Define if readline supports append_history]),,$READLINE_LIBS) | ||
+ | ||
+ # in readline as well as newer editline (April 2023) | ||
+ AC_CHECK_TYPE([rl_compdisp_func_t], | ||
+ [AC_DEFINE([HAVE_RL_COMPDISP_FUNC_T], [1], | ||
+ [Define if readline supports rl_compdisp_func_t])], | ||
+ [], | ||
+ [ | ||
+#include <stdio.h> /* Must be first for Gnu Readline */ | ||
+#ifdef WITH_EDITLINE | ||
+# include <editline/readline.h> | ||
+#else | ||
+# include <readline/readline.h> | ||
+#endif | ||
+ ]) | ||
fi | ||
|
||
# End of readline checks: restore LIBS | ||
diff --git a/pyconfig.h.in b/pyconfig.h.in | ||
index 0536047f573..94d02e14c44 100644 | ||
--- a/pyconfig.h.in | ||
+++ b/pyconfig.h.in | ||
@@ -968,6 +968,9 @@ | ||
/* Define if you can turn off readline's signal handling. */ | ||
#undef HAVE_RL_CATCH_SIGNAL | ||
|
||
+/* Define if readline supports rl_compdisp_func_t */ | ||
+#undef HAVE_RL_COMPDISP_FUNC_T | ||
+ | ||
/* Define if you have readline 2.2 */ | ||
#undef HAVE_RL_COMPLETION_APPEND_CHARACTER | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters