@@ -51,14 +51,53 @@ diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py
51
51
if _os.name == "nt":
52
52
EOF
53
53
54
+ # libedit on non-macOS requires various hacks because readline.c assumes
55
+ # libedit is only used on macOS and its readline/libedit detection code
56
+ # makes various assumptions about the macOS environment.
57
+ #
58
+ # USE_LIBEDIT comes from our static-modules file.
59
+ #
60
+ # TODO make upstream patches to readline.c to properly support libedit
61
+ # on other platforms.
54
62
cp Modules/readline.c Modules/readline-libedit.c
55
63
56
- # Python supports using libedit instead of readline. But Modules/readline.c
57
- # has all of this behind ``#ifdef __APPLE__`` instead of a more specific
58
- # feature flag. All occurrences of __APPLE__ in that file are related to
59
- # libedit. So we just replace the content. USE_LIBEDIT comes from our
60
- # static-modules file.
61
- # TODO make changes upstream to allow libedit to more easily be used
64
+ # readline.c assumes that a modern readline API version has a free_history_entry().
65
+ # but libedit does not. Change the #ifdef accordingly.
66
+ #
67
+ # Similarly, we invoke configure using readline, which sets
68
+ # HAVE_RL_COMPLETION_SUPPRESS_APPEND improperly. So hack that. This is a bug
69
+ # in our build system, as we should probably be invoking configure again when
70
+ # using libedit.
71
+ patch -p1 << EOF
72
+ diff --git a/Modules/readline-libedit.c b/Modules/readline-libedit.c
73
+ index 57335fe911..f3e83ff932 100644
74
+ --- a/Modules/readline-libedit.c
75
+ +++ b/Modules/readline-libedit.c
76
+ @@ -486,7 +486,7 @@ set the word delimiters for completion");
77
+
78
+ /* _py_free_history_entry: Utility function to free a history entry. */
79
+
80
+ -#if defined(RL_READLINE_VERSION) && RL_READLINE_VERSION >= 0x0500
81
+ +#ifndef USE_LIBEDIT
82
+
83
+ /* Readline version >= 5.0 introduced a timestamp field into the history entry
84
+ structure; this needs to be freed to avoid a memory leak. This version of
85
+ @@ -1032,7 +1032,7 @@ flex_complete(const char *text, int start, int end)
86
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
87
+ rl_completion_append_character ='\0';
88
+ #endif
89
+ -#ifdef HAVE_RL_COMPLETION_SUPPRESS_APPEND
90
+ +#ifndef USE_LIBEDIT
91
+ rl_completion_suppress_append = 0;
92
+ #endif
93
+
94
+
95
+ EOF
96
+
97
+ # Modules/readline.c has various libedit conditions behind an
98
+ # ``#ifdef __APPLE__`` instead of a more specific feature flag. All
99
+ # occurrences of __APPLE__ in that file are related to libedit. So we
100
+ # just replace the content.
62
101
sed -i s/__APPLE__/USE_LIBEDIT/g Modules/readline-libedit.c
63
102
64
103
# Most bits look at CFLAGS. But setup.py only looks at CPPFLAGS.
0 commit comments