Skip to content

Commit 8515fd7

Browse files
authored
gh-117845: Detect libedit hook function signature in configure (#117870)
Older libedit versions (like Apple's) use a different type signature for rl_startup_hook and rl_pre_input_hook. Add a configure check to determine which signature is accepted by introducing the Py_RL_STARTUP_HOOK_TAKES_ARGS macro in pyconfig.h.
1 parent f74e512 commit 8515fd7

File tree

5 files changed

+71
-2
lines changed

5 files changed

+71
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix building against recent libedit versions by detecting readline hook signatures in :program:`configure`.

Modules/readline.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ on_hook(PyObject *func)
10411041
}
10421042

10431043
static int
1044-
#if defined(_RL_FUNCTION_TYPEDEF)
1044+
#if defined(_RL_FUNCTION_TYPEDEF) || !defined(Py_RL_STARTUP_HOOK_TAKES_ARGS)
10451045
on_startup_hook(void)
10461046
#else
10471047
on_startup_hook(const char *Py_UNUSED(text), int Py_UNUSED(state))
@@ -1061,7 +1061,7 @@ on_startup_hook(const char *Py_UNUSED(text), int Py_UNUSED(state))
10611061

10621062
#ifdef HAVE_RL_PRE_INPUT_HOOK
10631063
static int
1064-
#if defined(_RL_FUNCTION_TYPEDEF)
1064+
#if defined(_RL_FUNCTION_TYPEDEF) || !defined(Py_RL_STARTUP_HOOK_TAKES_ARGS)
10651065
on_pre_input_hook(void)
10661066
#else
10671067
on_pre_input_hook(const char *Py_UNUSED(text), int Py_UNUSED(state))

configure

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6341,6 +6341,21 @@ AS_VAR_IF([with_readline], [no], [
63416341
# in readline as well as newer editline (April 2023)
63426342
AC_CHECK_TYPES([rl_compdisp_func_t], [], [], [readline_includes])
63436343
6344+
# Some editline versions declare rl_startup_hook as taking no args, others
6345+
# declare it as taking 2.
6346+
AC_CACHE_CHECK([if rl_startup_hook takes arguments], [ac_cv_readline_rl_startup_hook_takes_args], [
6347+
AC_COMPILE_IFELSE(
6348+
[AC_LANG_PROGRAM([readline_includes]
6349+
[extern int test_hook_func(const char *text, int state);],
6350+
[rl_startup_hook=test_hook_func;])],
6351+
[ac_cv_readline_rl_startup_hook_takes_args=yes],
6352+
[ac_cv_readline_rl_startup_hook_takes_args=no]
6353+
)
6354+
])
6355+
AS_VAR_IF([ac_cv_readline_rl_startup_hook_takes_args], [yes], [
6356+
AC_DEFINE([Py_RL_STARTUP_HOOK_TAKES_ARGS], [1], [Define if rl_startup_hook takes arguments])
6357+
])
6358+
63446359
m4_undefine([readline_includes])
63456360
])dnl WITH_SAVE_ENV()
63466361
])

pyconfig.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,9 @@
16591659
SipHash13: 3, externally defined: 0 */
16601660
#undef Py_HASH_ALGORITHM
16611661

1662+
/* Define if rl_startup_hook takes arguments */
1663+
#undef Py_RL_STARTUP_HOOK_TAKES_ARGS
1664+
16621665
/* Define if you want to enable internal statistics gathering. */
16631666
#undef Py_STATS
16641667

0 commit comments

Comments
 (0)