-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreadline_libedit.patch
973 lines (898 loc) · 31.5 KB
/
readline_libedit.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
diff -ur Python-3.9.0.orig/Modules/readline.c Python-3.9.0/Modules/readline.c
--- Python-3.9.0.orig/Modules/readline.c 2020-10-23 10:35:53.619118422 +0300
+++ Python-3.9.0/Modules/readline.c 2020-10-23 10:45:12.300876632 +0300
@@ -26,23 +26,20 @@
# define RESTORE_LOCALE(sl)
#endif
+#ifdef WITH_EDITLINE
+# include <editline/readline.h>
+#else
/* GNU readline definitions */
-#undef HAVE_CONFIG_H /* Else readline/chardefs.h includes strings.h */
-#include <readline/readline.h>
-#include <readline/history.h>
+# undef HAVE_CONFIG_H /* Else readline/chardefs.h includes strings.h */
+# include <readline/readline.h>
+# include <readline/history.h>
+#endif
+/* Readline 4.2 deprecated completion_matches() in favour of
++rl_completion_matches() */
#ifdef HAVE_RL_COMPLETION_MATCHES
#define completion_matches(x, y) \
rl_completion_matches((x), ((rl_compentry_func_t *)(y)))
-#else
-#if defined(_RL_FUNCTION_TYPEDEF)
-extern char **completion_matches(char *, rl_compentry_func_t *);
-#else
-
-#if !defined(__APPLE__)
-extern char **completion_matches(char *, CPFunction *);
-#endif
-#endif
#endif
/*
@@ -50,20 +47,26 @@
* emulation library of editline/libedit.
*
* This emulation library is not 100% API compatible with the "real" readline
- * and cannot be detected at compile-time,
+ * and if WITH_EDITLINE was not specified, cannot be detected at compile-time,
* hence we use a runtime check to detect if the Python readlinke module is
* linked to libedit.
- *
- * Currently there is one known API incompatibility:
+ */
+#if !defined(WITH_EDITLINE)
+# define DETECT_EDITLINE
+static int using_libedit_emulation = 0;
+static const char libedit_version_tag[] = "EditLine wrapper";
+#endif
+
+#if defined(WITH_EDITLINE)
+# define SUPPORT_EDITLINE
+/* One incompatibility of Editline:
* - 'get_history' has a 1-based index with GNU readline, and a 0-based
* index with older versions of libedit's emulation.
* - Note that replace_history and remove_history use a 0-based index
* with both implementations.
*/
-static int using_libedit_emulation = 0;
-static const char libedit_version_tag[] = "EditLine wrapper";
-
static int libedit_history_start = 0;
+#endif
#ifdef HAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK
static void
@@ -668,25 +671,6 @@
\n\
Returns current completer function.");
-/* Private function to get current length of history. XXX It may be
- * possible to replace this with a direct use of history_length instead,
- * but it's not clear whether BSD's libedit keeps history_length up to date.
- * See issue #8065.*/
-
-static int
-_py_get_history_length(void)
-{
- HISTORY_STATE *hist_st = history_get_history_state();
- int length = hist_st->length;
- /* the history docs don't say so, but the address of hist_st changes each
- time history_get_history_state is called which makes me think it's
- freshly malloc'd memory... on the other hand, the address of the last
- line stays the same as long as history isn't extended, so it appears to
- be malloc'd but managed by the history package... */
- free(hist_st);
- return length;
-}
-
/* Exported function to get any element of history */
static PyObject *
@@ -697,25 +681,24 @@
if (!PyArg_ParseTuple(args, "i:get_history_item", &idx))
return NULL;
- if (using_libedit_emulation) {
- /* Older versions of libedit's readline emulation
- * use 0-based indexes, while readline and newer
- * versions of libedit use 1-based indexes.
- */
- int length = _py_get_history_length();
-
- idx = idx - 1 + libedit_history_start;
-
- /*
- * Apple's readline emulation crashes when
- * the index is out of range, therefore
- * test for that and fail gracefully.
- */
- if (idx < (0 + libedit_history_start)
- || idx >= (length + libedit_history_start)) {
- Py_RETURN_NONE;
- }
+#ifdef SUPPORT_EDITLINE
+ idx = idx - 1 + libedit_history_start;
+
+ /*
+ * Apple's readline emulation crashes when
+ * the index is out of range, therefore
+ * test for that and fail gracefully.
+ */
+ /* KELLIN NOTE:
+ * The initial patch removed the 0 for some unknown to me reason
+ *
+ * if (idx < (0 + libedit_history_start)
+ */
+ if (idx < libedit_history_start
+ || idx >= (history_length + libedit_history_start)) {
+ Py_RETURN_NONE;
}
+#endif /* SUPPORT_EDITLINE */
if ((hist_ent = history_get(idx)))
return decode(hist_ent->line);
else {
@@ -733,7 +716,7 @@
static PyObject *
get_current_history_length(PyObject *self, PyObject *noarg)
{
- return PyLong_FromLong((long)_py_get_history_length());
+ return PyLong_FromLong(history_length);
}
PyDoc_STRVAR(doc_get_current_history_length,
@@ -1083,13 +1066,15 @@
/* The name must be defined before initialization */
rl_readline_name = "python";
+#ifdef SUPPORT_EDITLINE
/* the libedit readline emulation resets key bindings etc
- * when calling rl_initialize. So call it upfront
+ * when calling rl_initialize. So call it before making those settings.
*/
+# ifdef DETECT_EDITLINE
if (using_libedit_emulation)
+# endif
rl_initialize();
-
- /* Detect if libedit's readline emulation uses 0-based
+ /* Detect if the backend library uses 0-based
* indexing or 1-based indexing.
*/
add_history("1");
@@ -1099,6 +1084,7 @@
libedit_history_start = 1;
}
clear_history();
+#endif /* SUPPORT_EDITLINE */
using_history();
@@ -1127,7 +1113,9 @@
mod_state->begidx = PyLong_FromLong(0L);
mod_state->endidx = PyLong_FromLong(0L);
+#ifdef DETECT_EDITLINE
if (!using_libedit_emulation)
+#endif
{
if (!isatty(STDOUT_FILENO)) {
/* Issue #19884: stdout is not a terminal. Disable meta modifier
@@ -1146,11 +1134,20 @@
*
* XXX: A bug in the readline-2.2 library causes a memory leak
* inside this function. Nothing we can do about it.
+ *
+ * For Editline, just invoke the user configuration; initialization was
+ * already done above.
*/
+#ifdef DETECT_EDITLINE
if (using_libedit_emulation)
rl_read_init_file(NULL);
else
rl_initialize();
+#elif defined(WITH_EDITLINE)
+ rl_read_init_file(NULL);
+#else
+ rl_initialize();
+#endif
RESTORE_LOCALE(saved_locale)
return 0;
@@ -1276,14 +1273,13 @@
n = strlen(p);
if (should_auto_add_history && n > 0) {
const char *line;
- int length = _py_get_history_length();
- if (length > 0) {
+ if (history_length > 0) {
HIST_ENTRY *hist_ent;
- if (using_libedit_emulation) {
- /* handle older 0-based or newer 1-based indexing */
- hist_ent = history_get(length + libedit_history_start - 1);
- } else
- hist_ent = history_get(length);
+#ifdef SUPPORT_EDITLINE
+ hist_ent = history_get(history_length + libedit_history_start - 1);
+#else
+ hist_ent = history_get(history_length);
+#endif
line = hist_ent ? hist_ent->line : "";
} else
line = "";
@@ -1308,10 +1304,15 @@
/* Initialize the module */
PyDoc_STRVAR(doc_module,
+#ifndef WITH_EDITLINE
"Importing this module enables command line editing using GNU readline.");
-
+#endif
+#ifdef DETECT_EDITLINE
PyDoc_STRVAR(doc_module_le,
+#endif
+#ifdef SUPPORT_EDITLINE
"Importing this module enables command line editing using libedit readline.");
+#endif
static struct PyModuleDef readlinemodule = {
PyModuleDef_HEAD_INIT,
@@ -1332,13 +1333,14 @@
PyObject *m;
readlinestate *mod_state;
+#ifdef DETECT_EDITLINE
if (strncmp(rl_library_version, libedit_version_tag, strlen(libedit_version_tag)) == 0) {
using_libedit_emulation = 1;
}
if (using_libedit_emulation)
readlinemodule.m_doc = doc_module_le;
-
+#endif /* DETECT_EDITLINE */
m = PyModule_Create(&readlinemodule);
diff -ur Python-3.9.0.orig/configure Python-3.9.0/configure
--- Python-3.9.0.orig/configure 2020-10-23 10:35:53.452460203 +0300
+++ Python-3.9.0/configure 2020-10-23 10:55:42.742362204 +0300
@@ -846,6 +846,7 @@
with_libc
enable_big_digits
with_platlibdir
+with_readline
with_computed_gotos
with_ensurepip
with_openssl
@@ -1572,6 +1573,8 @@
system-dependent)
--with-platlibdir=DIRNAME
Python library directory name (default is "lib")
+ --with(out)-readline[=editline]
+ use Editline for backend or disable readline module
--with-computed-gotos enable computed gotos in evaluation loop (enabled by
default on supported compilers)
--with-ensurepip[=install|upgrade|no]
@@ -15471,24 +15474,49 @@
fi
+
+# Check whether --with-readline was given.
+if test "${with_readline+set}" = set; then :
+ withval=$with_readline;
+else
+ with_readline=yes
+fi
+
+
# check where readline lives
+py_cv_lib_readline=no
# save the value of LIBS so we don't actually link Python with readline
LIBS_no_readline=$LIBS
-# On some systems we need to link readline to a termcap compatible
-# library. NOTE: Keep the precedence of listed libraries synchronised
-# with setup.py.
-py_cv_lib_readline=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link readline libs" >&5
+if test "$with_readline" != no; then
+ case "$with_readline" in
+ editline|edit)
+ LIBREADLINE=edit
+
+$as_echo "#define WITH_EDITLINE 1" >>confdefs.h
+
+ ;;
+ yes|readline)
+ LIBREADLINE=readline
+ ;;
+ *)
+ as_fn_error $? "proper usage is --with(out)-readline[=editline]" "$LINENO" 5
+ ;;
+ esac
+
+ # On some systems we need to link readline to a termcap compatible
+ # library. NOTE: Keep the precedence of listed libraries synchronised
+ # with setup.py.
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link readline libs" >&5
$as_echo_n "checking how to link readline libs... " >&6; }
-for py_libtermcap in "" tinfo ncursesw ncurses curses termcap; do
- if test -z "$py_libtermcap"; then
- READLINE_LIBS="-lreadline"
- else
- READLINE_LIBS="-lreadline -l$py_libtermcap"
- fi
- LIBS="$READLINE_LIBS $LIBS_no_readline"
- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ for py_libtermcap in "" tinfo ncursesw ncurses curses termcap; do
+ if test -z "$py_libtermcap"; then
+ READLINE_LIBS="-l$LIBREADLINE"
+ else
+ READLINE_LIBS="-l$LIBREADLINE -l$py_libtermcap"
+ fi
+ LIBS="$READLINE_LIBS $LIBS_no_readline"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
@@ -15511,73 +15539,67 @@
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
- if test $py_cv_lib_readline = yes; then
- break
- fi
-done
-# Uncomment this line if you want to use READINE_LIBS in Makefile or scripts
-#AC_SUBST([READLINE_LIBS])
-if test $py_cv_lib_readline = no; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5
+ if test $py_cv_lib_readline = yes; then
+ break
+ fi
+ done
+
+ # Uncomment this line if you want to use READLINE_LIBS in Makefile or scripts
+ #AC_SUBST([READLINE_LIBS])
+ if test $py_cv_lib_readline = no; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5
$as_echo "none" >&6; }
-else
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $READLINE_LIBS" >&5
+ else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $READLINE_LIBS" >&5
$as_echo "$READLINE_LIBS" >&6; }
$as_echo "#define HAVE_LIBREADLINE 1" >>confdefs.h
+ fi
fi
-# check for readline 2.2
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-#include <readline/readline.h>
-_ACEOF
-if ac_fn_c_try_cpp "$LINENO"; then :
- have_readline=yes
-else
- have_readline=no
-
-fi
-rm -f conftest.err conftest.i conftest.$ac_ext
-if test $have_readline = yes
-then
- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-#include <readline/readline.h>
+if test "$py_cv_lib_readline" = yes; then
+ # check for readline 2.2
+ ac_fn_c_check_decl "$LINENO" "rl_completion_append_character" "ac_cv_have_decl_rl_completion_append_character" "
+#include <stdio.h> /* Must be first for Gnu Readline */
+#ifdef WITH_EDITLINE
+# include <editline/readline.h>
+#else
+# include <readline/readline.h>
+#endif
-_ACEOF
-if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
- $EGREP "extern int rl_completion_append_character;" >/dev/null 2>&1; then :
+"
+if test "x$ac_cv_have_decl_rl_completion_append_character" = xyes; then :
-$as_echo "#define HAVE_RL_COMPLETION_APPEND_CHARACTER 1" >>confdefs.h
+ $as_echo "#define HAVE_RL_COMPLETION_APPEND_CHARACTER 1" >>confdefs.h
fi
-rm -f conftest*
- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-#include <readline/readline.h>
+ ac_fn_c_check_decl "$LINENO" "rl_completion_suppress_append" "ac_cv_have_decl_rl_completion_suppress_append" "
+#include <stdio.h> /* Must be first for Gnu Readline */
+#ifdef WITH_EDITLINE
+# include <editline/readline.h>
+#else
+# include <readline/readline.h>
+#endif
-_ACEOF
-if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
- $EGREP "extern int rl_completion_suppress_append;" >/dev/null 2>&1; then :
+"
+if test "x$ac_cv_have_decl_rl_completion_suppress_append" = xyes; then :
$as_echo "#define HAVE_RL_COMPLETION_SUPPRESS_APPEND 1" >>confdefs.h
fi
-rm -f conftest*
-fi
-# check for readline 4.0
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_pre_input_hook in -lreadline" >&5
-$as_echo_n "checking for rl_pre_input_hook in -lreadline... " >&6; }
-if ${ac_cv_lib_readline_rl_pre_input_hook+:} false; then :
+ # check for readline 4.0
+ as_ac_Lib=`$as_echo "ac_cv_lib_$LIBREADLINE''_rl_pre_input_hook" | $as_tr_sh`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_pre_input_hook in -l$LIBREADLINE" >&5
+$as_echo_n "checking for rl_pre_input_hook in -l$LIBREADLINE... " >&6; }
+if eval \${$as_ac_Lib+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
-LIBS="-lreadline $READLINE_LIBS $LIBS"
+LIBS="-l$LIBREADLINE $READLINE_LIBS $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
@@ -15597,31 +15619,34 @@
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
- ac_cv_lib_readline_rl_pre_input_hook=yes
+ eval "$as_ac_Lib=yes"
else
- ac_cv_lib_readline_rl_pre_input_hook=no
+ eval "$as_ac_Lib=no"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_readline_rl_pre_input_hook" >&5
-$as_echo "$ac_cv_lib_readline_rl_pre_input_hook" >&6; }
-if test "x$ac_cv_lib_readline_rl_pre_input_hook" = xyes; then :
+eval ac_res=\$$as_ac_Lib
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+
+if eval test \"x\$"$as_ac_Lib"\" = x"yes"; then :
$as_echo "#define HAVE_RL_PRE_INPUT_HOOK 1" >>confdefs.h
fi
-# also in 4.0
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_completion_display_matches_hook in -lreadline" >&5
-$as_echo_n "checking for rl_completion_display_matches_hook in -lreadline... " >&6; }
-if ${ac_cv_lib_readline_rl_completion_display_matches_hook+:} false; then :
+ # also in 4.0
+ as_ac_Lib=`$as_echo "ac_cv_lib_$LIBREADLINE''_rl_completion_display_matches_hook" | $as_tr_sh`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_completion_display_matches_hook in -l$LIBREADLINE" >&5
+$as_echo_n "checking for rl_completion_display_matches_hook in -l$LIBREADLINE... " >&6; }
+if eval \${$as_ac_Lib+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
-LIBS="-lreadline $READLINE_LIBS $LIBS"
+LIBS="-l$LIBREADLINE $READLINE_LIBS $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
@@ -15641,31 +15666,34 @@
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
- ac_cv_lib_readline_rl_completion_display_matches_hook=yes
+ eval "$as_ac_Lib=yes"
else
- ac_cv_lib_readline_rl_completion_display_matches_hook=no
+ eval "$as_ac_Lib=no"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_readline_rl_completion_display_matches_hook" >&5
-$as_echo "$ac_cv_lib_readline_rl_completion_display_matches_hook" >&6; }
-if test "x$ac_cv_lib_readline_rl_completion_display_matches_hook" = xyes; then :
+eval ac_res=\$$as_ac_Lib
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+
+if eval test \"x\$"$as_ac_Lib"\" = x"yes"; then :
$as_echo "#define HAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK 1" >>confdefs.h
fi
-# also in 4.0, but not in editline
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_resize_terminal in -lreadline" >&5
-$as_echo_n "checking for rl_resize_terminal in -lreadline... " >&6; }
-if ${ac_cv_lib_readline_rl_resize_terminal+:} false; then :
+ # also in 4.0, but not in editline
+ as_ac_Lib=`$as_echo "ac_cv_lib_$LIBREADLINE''_rl_resize_terminal" | $as_tr_sh`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_resize_terminal in -l$LIBREADLINE" >&5
+$as_echo_n "checking for rl_resize_terminal in -l$LIBREADLINE... " >&6; }
+if eval \${$as_ac_Lib+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
-LIBS="-lreadline $READLINE_LIBS $LIBS"
+LIBS="-l$LIBREADLINE $READLINE_LIBS $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
@@ -15685,31 +15713,33 @@
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
- ac_cv_lib_readline_rl_resize_terminal=yes
+ eval "$as_ac_Lib=yes"
else
- ac_cv_lib_readline_rl_resize_terminal=no
+ eval "$as_ac_Lib=no"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_readline_rl_resize_terminal" >&5
-$as_echo "$ac_cv_lib_readline_rl_resize_terminal" >&6; }
-if test "x$ac_cv_lib_readline_rl_resize_terminal" = xyes; then :
+eval ac_res=\$$as_ac_Lib
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+if eval test \"x\$"$as_ac_Lib"\" = x"yes"; then :
$as_echo "#define HAVE_RL_RESIZE_TERMINAL 1" >>confdefs.h
fi
-# check for readline 4.2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_completion_matches in -lreadline" >&5
-$as_echo_n "checking for rl_completion_matches in -lreadline... " >&6; }
-if ${ac_cv_lib_readline_rl_completion_matches+:} false; then :
+ # check for readline 4.2
+ as_ac_Lib=`$as_echo "ac_cv_lib_$LIBREADLINE''_rl_completion_matches" | $as_tr_sh`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_completion_matches in -l$LIBREADLINE" >&5
+$as_echo_n "checking for rl_completion_matches in -l$LIBREADLINE... " >&6; }
+if eval \${$as_ac_Lib+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
-LIBS="-lreadline $READLINE_LIBS $LIBS"
+LIBS="-l$LIBREADLINE $READLINE_LIBS $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
@@ -15729,59 +15759,49 @@
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
- ac_cv_lib_readline_rl_completion_matches=yes
+ eval "$as_ac_Lib=yes"
else
- ac_cv_lib_readline_rl_completion_matches=no
+ eval "$as_ac_Lib=no"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_readline_rl_completion_matches" >&5
-$as_echo "$ac_cv_lib_readline_rl_completion_matches" >&6; }
-if test "x$ac_cv_lib_readline_rl_completion_matches" = xyes; then :
+eval ac_res=\$$as_ac_Lib
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+
+if eval test \"x\$"$as_ac_Lib"\" = x"yes"; then :
$as_echo "#define HAVE_RL_COMPLETION_MATCHES 1" >>confdefs.h
fi
-# also in readline 4.2
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-#include <readline/readline.h>
-_ACEOF
-if ac_fn_c_try_cpp "$LINENO"; then :
- have_readline=yes
-else
- have_readline=no
-
-fi
-rm -f conftest.err conftest.i conftest.$ac_ext
-if test $have_readline = yes
-then
- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-#include <readline/readline.h>
+ # also in readline 4.2
+ ac_fn_c_check_decl "$LINENO" "rl_catch_signals" "ac_cv_have_decl_rl_catch_signals" "
+#include <stdio.h> /* Must be first for Gnu Readline */
+#ifdef WITH_EDITLINE
+# include <editline/readline.h>
+#else
+# include <readline/readline.h>
+#endif
-_ACEOF
-if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
- $EGREP "extern int rl_catch_signals;" >/dev/null 2>&1; then :
+"
+if test "x$ac_cv_have_decl_rl_catch_signals" = xyes; then :
$as_echo "#define HAVE_RL_CATCH_SIGNAL 1" >>confdefs.h
fi
-rm -f conftest*
-
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for append_history in -lreadline" >&5
-$as_echo_n "checking for append_history in -lreadline... " >&6; }
-if ${ac_cv_lib_readline_append_history+:} false; then :
+ as_ac_Lib=`$as_echo "ac_cv_lib_$LIBREADLINE''_append_history" | $as_tr_sh`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for append_history in -l$LIBREADLINE" >&5
+$as_echo_n "checking for append_history in -l$LIBREADLINE... " >&6; }
+if eval \${$as_ac_Lib+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
-LIBS="-lreadline $READLINE_LIBS $LIBS"
+LIBS="-l$LIBREADLINE $READLINE_LIBS $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
@@ -15801,22 +15821,24 @@
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
- ac_cv_lib_readline_append_history=yes
+ eval "$as_ac_Lib=yes"
else
- ac_cv_lib_readline_append_history=no
+ eval "$as_ac_Lib=no"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_readline_append_history" >&5
-$as_echo "$ac_cv_lib_readline_append_history" >&6; }
-if test "x$ac_cv_lib_readline_append_history" = xyes; then :
+eval ac_res=\$$as_ac_Lib
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+if eval test \"x\$"$as_ac_Lib"\" = x"yes"; then :
$as_echo "#define HAVE_RL_APPEND_HISTORY 1" >>confdefs.h
fi
+fi
# End of readline checks: restore LIBS
LIBS=$LIBS_no_readline
diff -ur Python-3.9.0.orig/configure.ac Python-3.9.0/configure.ac
--- Python-3.9.0.orig/configure.ac 2020-10-23 10:35:53.392463243 +0300
+++ Python-3.9.0/configure.ac 2020-10-23 11:01:15.675567214 +0300
@@ -4856,93 +4856,125 @@
[Define this if you have flockfile(), getc_unlocked(), and funlockfile()])
fi
+AC_ARG_WITH([readline],
+ [AS_HELP_STRING([--with(out)-readline@<:@=editline@:>@],
+ [use Editline for backend or disable readline module])],
+ [],
+ [with_readline=yes])
+
# check where readline lives
+py_cv_lib_readline=no
# save the value of LIBS so we don't actually link Python with readline
LIBS_no_readline=$LIBS
-# On some systems we need to link readline to a termcap compatible
-# library. NOTE: Keep the precedence of listed libraries synchronised
-# with setup.py.
-py_cv_lib_readline=no
-AC_MSG_CHECKING([how to link readline libs])
-for py_libtermcap in "" tinfo ncursesw ncurses curses termcap; do
- if test -z "$py_libtermcap"; then
- READLINE_LIBS="-lreadline"
+if test "$with_readline" != no; then
+ case "$with_readline" in
+ editline|edit)
+ LIBREADLINE=edit
+ AC_DEFINE(WITH_EDITLINE, 1,
+ [Define to build the readline module against Editline.])
+ ;;
+ yes|readline)
+ LIBREADLINE=readline
+ ;;
+ *)
+ AC_MSG_ERROR([proper usage is --with(out)-readline@<:@=editline@:>@])
+ ;;
+ esac
+
+ # On some systems we need to link readline to a termcap compatible
+ # library. NOTE: Keep the precedence of listed libraries synchronised
+ # with setup.py.
+ AC_MSG_CHECKING([how to link readline libs])
+ for py_libtermcap in "" tinfo ncursesw ncurses curses termcap; do
+ if test -z "$py_libtermcap"; then
+ READLINE_LIBS="-l$LIBREADLINE"
+ else
+ READLINE_LIBS="-l$LIBREADLINE -l$py_libtermcap"
+ fi
+ LIBS="$READLINE_LIBS $LIBS_no_readline"
+ AC_LINK_IFELSE(
+ [AC_LANG_CALL([],[readline])],
+ [py_cv_lib_readline=yes])
+ if test $py_cv_lib_readline = yes; then
+ break
+ fi
+ done
+
+ # Uncomment this line if you want to use READLINE_LIBS in Makefile or scripts
+ #AC_SUBST([READLINE_LIBS])
+ if test $py_cv_lib_readline = no; then
+ AC_MSG_RESULT([none])
else
- READLINE_LIBS="-lreadline -l$py_libtermcap"
- fi
- LIBS="$READLINE_LIBS $LIBS_no_readline"
- AC_LINK_IFELSE(
- [AC_LANG_CALL([],[readline])],
- [py_cv_lib_readline=yes])
- if test $py_cv_lib_readline = yes; then
- break
+ AC_MSG_RESULT([$READLINE_LIBS])
+ AC_DEFINE(HAVE_LIBREADLINE, 1,
+ [Define to build the readline module.])
fi
-done
-# Uncomment this line if you want to use READINE_LIBS in Makefile or scripts
-#AC_SUBST([READLINE_LIBS])
-if test $py_cv_lib_readline = no; then
- AC_MSG_RESULT([none])
-else
- AC_MSG_RESULT([$READLINE_LIBS])
- AC_DEFINE(HAVE_LIBREADLINE, 1,
- [Define if you have the readline library (-lreadline).])
fi
-# check for readline 2.2
-AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <readline/readline.h>]])],
- [have_readline=yes],
- [have_readline=no]
-)
-if test $have_readline = yes
-then
- AC_EGREP_HEADER([extern int rl_completion_append_character;],
- [readline/readline.h],
- AC_DEFINE(HAVE_RL_COMPLETION_APPEND_CHARACTER, 1,
- [Define if you have readline 2.2]), )
- AC_EGREP_HEADER([extern int rl_completion_suppress_append;],
- [readline/readline.h],
- AC_DEFINE(HAVE_RL_COMPLETION_SUPPRESS_APPEND, 1,
- [Define if you have rl_completion_suppress_append]), )
+if test "$py_cv_lib_readline" = yes; then
+ # check for readline 2.2
+ AC_CHECK_DECL(rl_completion_append_character,
+ AC_DEFINE(HAVE_RL_COMPLETION_APPEND_CHARACTER, 1,
+ [Define if you have readline 2.2]),,
+ [
+#include <stdio.h> /* Must be first for Gnu Readline */
+#ifdef WITH_EDITLINE
+# include <editline/readline.h>
+#else
+# include <readline/readline.h>
+#endif
+ ])
+ AC_CHECK_DECL(rl_completion_suppress_append,
+ AC_DEFINE(HAVE_RL_COMPLETION_SUPPRESS_APPEND, 1,
+ [Define if you have rl_completion_suppress_append]),,
+ [
+#include <stdio.h> /* Must be first for Gnu Readline */
+#ifdef WITH_EDITLINE
+# include <editline/readline.h>
+#else
+# include <readline/readline.h>
+#endif
+ ])
+
+ # check for readline 4.0
+ AC_CHECK_LIB($LIBREADLINE, rl_pre_input_hook,
+ AC_DEFINE(HAVE_RL_PRE_INPUT_HOOK, 1,
+ [Define if you have readline 4.0]),,$READLINE_LIBS)
+
+ # also in 4.0
+ AC_CHECK_LIB($LIBREADLINE, rl_completion_display_matches_hook,
+ AC_DEFINE(HAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK, 1,
+ [Define if you have readline 4.0]),,$READLINE_LIBS)
+
+ # also in 4.0, but not in editline
+ AC_CHECK_LIB($LIBREADLINE, rl_resize_terminal,
+ AC_DEFINE(HAVE_RL_RESIZE_TERMINAL, 1,
+ [Define if you have readline 4.0]),,$READLINE_LIBS)
+
+ # check for readline 4.2
+ AC_CHECK_LIB($LIBREADLINE, rl_completion_matches,
+ AC_DEFINE(HAVE_RL_COMPLETION_MATCHES, 1,
+ [Define if you have readline 4.2]),,$READLINE_LIBS)
+
+ # also in readline 4.2
+ AC_CHECK_DECL(rl_catch_signals,
+ AC_DEFINE(HAVE_RL_CATCH_SIGNAL, 1,
+ [Define if you can turn off readline's signal handling.]),,
+ [
+#include <stdio.h> /* Must be first for Gnu Readline */
+#ifdef WITH_EDITLINE
+# include <editline/readline.h>
+#else
+# include <readline/readline.h>
+#endif
+ ])
+
+ AC_CHECK_LIB($LIBREADLINE, append_history,
+ AC_DEFINE(HAVE_RL_APPEND_HISTORY, 1,
+ [Define if readline supports append_history]),,$READLINE_LIBS)
fi
-# check for readline 4.0
-AC_CHECK_LIB(readline, rl_pre_input_hook,
- AC_DEFINE(HAVE_RL_PRE_INPUT_HOOK, 1,
- [Define if you have readline 4.0]), ,$READLINE_LIBS)
-
-# also in 4.0
-AC_CHECK_LIB(readline, rl_completion_display_matches_hook,
- AC_DEFINE(HAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK, 1,
- [Define if you have readline 4.0]), ,$READLINE_LIBS)
-
-# also in 4.0, but not in editline
-AC_CHECK_LIB(readline, rl_resize_terminal,
- AC_DEFINE(HAVE_RL_RESIZE_TERMINAL, 1,
- [Define if you have readline 4.0]), ,$READLINE_LIBS)
-
-# check for readline 4.2
-AC_CHECK_LIB(readline, rl_completion_matches,
- AC_DEFINE(HAVE_RL_COMPLETION_MATCHES, 1,
- [Define if you have readline 4.2]), ,$READLINE_LIBS)
-
-# also in readline 4.2
-AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <readline/readline.h>]])],
- [have_readline=yes],
- [have_readline=no]
-)
-if test $have_readline = yes
-then
- AC_EGREP_HEADER([extern int rl_catch_signals;],
- [readline/readline.h],
- AC_DEFINE(HAVE_RL_CATCH_SIGNAL, 1,
- [Define if you can turn off readline's signal handling.]), )
-fi
-
-AC_CHECK_LIB(readline, append_history,
- AC_DEFINE(HAVE_RL_APPEND_HISTORY, 1,
- [Define if readline supports append_history]), ,$READLINE_LIBS)
-
# End of readline checks: restore LIBS
LIBS=$LIBS_no_readline
diff -ur Python-3.9.0.orig/pyconfig.h.in Python-3.9.0/pyconfig.h.in
--- Python-3.9.0.orig/pyconfig.h.in 2020-10-23 10:35:53.645783737 +0300
+++ Python-3.9.0/pyconfig.h.in 2020-10-23 10:36:41.496691638 +0300
@@ -598,7 +598,7 @@
/* Define to 1 if you have the <libintl.h> header file. */
#undef HAVE_LIBINTL_H
-/* Define if you have the readline library (-lreadline). */
+/* Define to build the readline module. */
#undef HAVE_LIBREADLINE
/* Define to 1 if you have the `resolv' library (-lresolv). */
@@ -1536,6 +1536,9 @@
Dyld is necessary to support frameworks. */
#undef WITH_DYLD
+/* Define to build the readline module against Editline. */
+#undef WITH_EDITLINE
+
/* Define to 1 if libintl is needed for locale functions. */
#undef WITH_LIBINTL
diff -ur Python-3.9.0.orig/setup.py Python-3.9.0/setup.py
--- Python-3.9.0.orig/setup.py 2020-10-23 10:35:53.392463243 +0300
+++ Python-3.9.0/setup.py 2020-10-23 11:01:58.906729487 +0300
@@ -978,7 +978,6 @@
def detect_readline_curses(self):
# readline
- do_readline = self.compiler.find_library_file(self.lib_dirs, 'readline')
readline_termcap_library = ""
curses_library = ""
# Cannot use os.popen here in py3k.
@@ -986,7 +985,13 @@
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
# Determine if readline is already linked against curses or tinfo.
- if do_readline:
+ if sysconfig.get_config_var('HAVE_LIBREADLINE'):
+ if sysconfig.get_config_var('WITH_EDITLINE'):
+ readline_lib = 'edit'
+ else:
+ readline_lib = 'readline'
+ do_readline = self.compiler.find_library_file(self.lib_dirs,
+ readline_lib)
if CROSS_COMPILING:
ret = run_command("%s -d %s | grep '(NEEDED)' > %s"
% (sysconfig.get_config_var('READELF'),
@@ -1009,6 +1014,8 @@
break
if os.path.exists(tmpfile):
os.unlink(tmpfile)
+ else:
+ do_readline = False
# Issue 7384: If readline is already linked against curses,
# use the same library for the readline and curses modules.
if 'curses' in readline_termcap_library:
@@ -1048,7 +1055,7 @@
else:
readline_extra_link_args = ()
- readline_libs = ['readline']
+ readline_libs = [readline_lib]
if readline_termcap_library:
pass # Issue 7384: Already linked against curses or tinfo.
elif curses_library: