Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d1e22ba

Browse files
committed
only support append_history if readline has it
1 parent 810aa6d commit d1e22ba

5 files changed

Lines changed: 56 additions & 0 deletions

File tree

Lib/test/test_readline.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def testHistoryUpdates(self):
4343

4444
self.assertEqual(readline.get_current_history_length(), 1)
4545

46+
@unittest.skipUnless(hasattr(readline, "append_history"),
47+
"append_history not available")
4648
def test_write_read_append(self):
4749
hfile = tempfile.NamedTemporaryFile(delete=False)
4850
hfile.close()

Modules/readline.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ Save a readline history file.\n\
237237
The default filename is ~/.history.");
238238

239239

240+
#ifdef HAVE_RL_APPEND_HISTORY
240241
/* Exported function to save part of a readline history file */
241242

242243
static PyObject *
@@ -270,6 +271,7 @@ PyDoc_STRVAR(doc_append_history_file,
270271
"append_history_file(nelements[, filename]) -> None\n\
271272
Append the last nelements of the history list to file.\n\
272273
The default filename is ~/.history.");
274+
#endif
273275

274276

275277
/* Set history length */
@@ -782,7 +784,9 @@ static struct PyMethodDef readline_methods[] =
782784
METH_VARARGS, doc_read_history_file},
783785
{"write_history_file", write_history_file,
784786
METH_VARARGS, doc_write_history_file},
787+
#ifdef HAVE_RL_APPEND_HISTORY
785788
{"append_history_file", append_history_file,
789+
#endif
786790
METH_VARARGS, doc_append_history_file},
787791
{"get_history_item", get_history_item,
788792
METH_VARARGS, doc_get_history_item},

configure

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14529,6 +14529,49 @@ rm -f conftest*
1452914529

1453014530
fi
1453114531

14532+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for append_history in -lreadline" >&5
14533+
$as_echo_n "checking for append_history in -lreadline... " >&6; }
14534+
if ${ac_cv_lib_readline_append_history+:} false; then :
14535+
$as_echo_n "(cached) " >&6
14536+
else
14537+
ac_check_lib_save_LIBS=$LIBS
14538+
LIBS="-lreadline $READLINE_LIBS $LIBS"
14539+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
14540+
/* end confdefs.h. */
14541+
14542+
/* Override any GCC internal prototype to avoid an error.
14543+
Use char because int might match the return type of a GCC
14544+
builtin and then its argument prototype would still apply. */
14545+
#ifdef __cplusplus
14546+
extern "C"
14547+
#endif
14548+
char append_history ();
14549+
int
14550+
main ()
14551+
{
14552+
return append_history ();
14553+
;
14554+
return 0;
14555+
}
14556+
_ACEOF
14557+
if ac_fn_c_try_link "$LINENO"; then :
14558+
ac_cv_lib_readline_append_history=yes
14559+
else
14560+
ac_cv_lib_readline_append_history=no
14561+
fi
14562+
rm -f core conftest.err conftest.$ac_objext \
14563+
conftest$ac_exeext conftest.$ac_ext
14564+
LIBS=$ac_check_lib_save_LIBS
14565+
fi
14566+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_readline_append_history" >&5
14567+
$as_echo "$ac_cv_lib_readline_append_history" >&6; }
14568+
if test "x$ac_cv_lib_readline_append_history" = xyes; then :
14569+
14570+
$as_echo "#define HAVE_RL_APPEND_HISTORY 1" >>confdefs.h
14571+
14572+
fi
14573+
14574+
1453214575
# End of readline checks: restore LIBS
1453314576
LIBS=$LIBS_no_readline
1453414577

configure.ac

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4308,6 +4308,10 @@ then
43084308
[Define if you can turn off readline's signal handling.]), )
43094309
fi
43104310

4311+
AC_CHECK_LIB(readline, append_history,
4312+
AC_DEFINE(HAVE_RL_APPEND_HISTORY, 1,
4313+
[Define if readline supports append_history]), ,$READLINE_LIBS)
4314+
43114315
# End of readline checks: restore LIBS
43124316
LIBS=$LIBS_no_readline
43134317

pyconfig.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,9 @@
690690
/* Define to 1 if you have the `renameat' function. */
691691
#undef HAVE_RENAMEAT
692692

693+
/* Define if readline supports append_history */
694+
#undef HAVE_RL_APPEND_HISTORY
695+
693696
/* Define if you have readline 2.1 */
694697
#undef HAVE_RL_CALLBACK
695698

0 commit comments

Comments
 (0)