From e932a1a21ad30a1f539172999fe3b92e4a515a0b Mon Sep 17 00:00:00 2001 From: Joshua Root Date: Sun, 14 Apr 2024 23:49:13 +1000 Subject: [PATCH 1/6] gh-117845: Fix type mismatch for hook functions with libedit 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 one is accepted. --- Modules/readline.c | 4 ++-- configure | 51 ++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 15 ++++++++++++++ pyconfig.h.in | 3 +++ 4 files changed, 71 insertions(+), 2 deletions(-) diff --git a/Modules/readline.c b/Modules/readline.c index e29051c37f8827..c027f639f9cf77 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -1041,7 +1041,7 @@ on_hook(PyObject *func) } static int -#if defined(_RL_FUNCTION_TYPEDEF) +#if defined(_RL_FUNCTION_TYPEDEF) || !defined(RL_STARTUP_HOOK_TAKES_ARGS) on_startup_hook(void) #else 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)) #ifdef HAVE_RL_PRE_INPUT_HOOK static int -#if defined(_RL_FUNCTION_TYPEDEF) +#if defined(_RL_FUNCTION_TYPEDEF) || !defined(RL_STARTUP_HOOK_TAKES_ARGS) on_pre_input_hook(void) #else on_pre_input_hook(const char *Py_UNUSED(text), int Py_UNUSED(state)) diff --git a/configure b/configure index 80403255a814af..f338e099e2cb5e 100755 --- a/configure +++ b/configure @@ -25367,6 +25367,57 @@ printf "%s\n" "#define HAVE_RL_COMPDISP_FUNC_T 1" >>confdefs.h fi + # Some editline versions declare rl_startup_hook as taking no args, others + # declare it as taking 2. + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if rl_startup_hook takes arguments" >&5 +printf %s "checking if rl_startup_hook takes arguments... " >&6; } +if test ${ac_cv_readline_rl_startup_hook_takes_args+y} +then : + printf %s "(cached) " >&6 +else case e in #( + e) + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #include /* Must be first for Gnu Readline */ + #ifdef WITH_EDITLINE + # include + #else + # include + # include + #endif + + extern int test_hook_func(const char *text, int state); +int +main (void) +{ +rl_startup_hook=test_hook_func; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + ac_cv_readline_rl_startup_hook_takes_args=yes +else case e in #( + e) ac_cv_readline_rl_startup_hook_takes_args=no + ;; +esac +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + ;; +esac +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_readline_rl_startup_hook_takes_args" >&5 +printf "%s\n" "$ac_cv_readline_rl_startup_hook_takes_args" >&6; } + if test "x$ac_cv_readline_rl_startup_hook_takes_args" = xyes +then : + + +printf "%s\n" "#define RL_STARTUP_HOOK_TAKES_ARGS 1" >>confdefs.h + + +fi CFLAGS=$save_CFLAGS diff --git a/configure.ac b/configure.ac index ec925d4d4a0a5a..52f29443066e77 100644 --- a/configure.ac +++ b/configure.ac @@ -6340,6 +6340,21 @@ AS_VAR_IF([with_readline], [no], [ # in readline as well as newer editline (April 2023) AC_CHECK_TYPES([rl_compdisp_func_t], [], [], [readline_includes]) + # Some editline versions declare rl_startup_hook as taking no args, others + # declare it as taking 2. + AC_CACHE_CHECK([if rl_startup_hook takes arguments], [ac_cv_readline_rl_startup_hook_takes_args], [ + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([readline_includes] + [[extern int test_hook_func(const char *text, int state);]], + [[rl_startup_hook=test_hook_func;]])], + [ac_cv_readline_rl_startup_hook_takes_args=yes], + [ac_cv_readline_rl_startup_hook_takes_args=no] + ) + ]) + AS_VAR_IF([ac_cv_readline_rl_startup_hook_takes_args], [yes], [ + AC_DEFINE([RL_STARTUP_HOOK_TAKES_ARGS], [1], [Define if rl_startup_hook takes arguments]) + ]) + m4_undefine([readline_includes]) ])dnl WITH_SAVE_ENV() ]) diff --git a/pyconfig.h.in b/pyconfig.h.in index e28baef51d5737..84e85615967690 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1671,6 +1671,9 @@ /* assume C89 semantics that RETSIGTYPE is always void */ #undef RETSIGTYPE +/* Define if rl_startup_hook takes arguments */ +#undef RL_STARTUP_HOOK_TAKES_ARGS + /* Define if setpgrp() must be called as setpgrp(0, 0). */ #undef SETPGRP_HAVE_ARG From 1563484aca629a425ce8c6fc417527b9dcabe6a2 Mon Sep 17 00:00:00 2001 From: Joshua Root Date: Mon, 15 Apr 2024 18:18:23 +1000 Subject: [PATCH 2/6] Adopt review suggestions --- configure | 17 ++++++++--------- configure.ac | 6 +++--- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/configure b/configure index f338e099e2cb5e..01525b9bfc3d7f 100755 --- a/configure +++ b/configure @@ -25374,8 +25374,8 @@ printf %s "checking if rl_startup_hook takes arguments... " >&6; } if test ${ac_cv_readline_rl_startup_hook_takes_args+y} then : printf %s "(cached) " >&6 -else case e in #( - e) +else $as_nop + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -25399,14 +25399,12 @@ _ACEOF if ac_fn_c_try_compile "$LINENO" then : ac_cv_readline_rl_startup_hook_takes_args=yes -else case e in #( - e) ac_cv_readline_rl_startup_hook_takes_args=no - ;; -esac +else $as_nop + ac_cv_readline_rl_startup_hook_takes_args=no + fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext - ;; -esac + fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_readline_rl_startup_hook_takes_args" >&5 printf "%s\n" "$ac_cv_readline_rl_startup_hook_takes_args" >&6; } @@ -25414,12 +25412,13 @@ printf "%s\n" "$ac_cv_readline_rl_startup_hook_takes_args" >&6; } then : -printf "%s\n" "#define RL_STARTUP_HOOK_TAKES_ARGS 1" >>confdefs.h +printf "%s\n" "#define Py_RL_STARTUP_HOOK_TAKES_ARGS 1" >>confdefs.h fi + CFLAGS=$save_CFLAGS CPPFLAGS=$save_CPPFLAGS LDFLAGS=$save_LDFLAGS diff --git a/configure.ac b/configure.ac index 52f29443066e77..70fd1cd1356e7f 100644 --- a/configure.ac +++ b/configure.ac @@ -6345,14 +6345,14 @@ AS_VAR_IF([with_readline], [no], [ AC_CACHE_CHECK([if rl_startup_hook takes arguments], [ac_cv_readline_rl_startup_hook_takes_args], [ AC_COMPILE_IFELSE( [AC_LANG_PROGRAM([readline_includes] - [[extern int test_hook_func(const char *text, int state);]], - [[rl_startup_hook=test_hook_func;]])], + [extern int test_hook_func(const char *text, int state);], + [rl_startup_hook=test_hook_func;])], [ac_cv_readline_rl_startup_hook_takes_args=yes], [ac_cv_readline_rl_startup_hook_takes_args=no] ) ]) AS_VAR_IF([ac_cv_readline_rl_startup_hook_takes_args], [yes], [ - AC_DEFINE([RL_STARTUP_HOOK_TAKES_ARGS], [1], [Define if rl_startup_hook takes arguments]) + AC_DEFINE([Py_RL_STARTUP_HOOK_TAKES_ARGS], [1], [Define if rl_startup_hook takes arguments]) ]) m4_undefine([readline_includes]) From 45c1187ce8a3dc3ef909f489066f82a702b04062 Mon Sep 17 00:00:00 2001 From: Joshua Root Date: Mon, 15 Apr 2024 18:19:52 +1000 Subject: [PATCH 3/6] Update macro name --- Modules/readline.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/readline.c b/Modules/readline.c index c027f639f9cf77..c5c34535de0154 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -1041,7 +1041,7 @@ on_hook(PyObject *func) } static int -#if defined(_RL_FUNCTION_TYPEDEF) || !defined(RL_STARTUP_HOOK_TAKES_ARGS) +#if defined(_RL_FUNCTION_TYPEDEF) || !defined(Py_RL_STARTUP_HOOK_TAKES_ARGS) on_startup_hook(void) #else 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)) #ifdef HAVE_RL_PRE_INPUT_HOOK static int -#if defined(_RL_FUNCTION_TYPEDEF) || !defined(RL_STARTUP_HOOK_TAKES_ARGS) +#if defined(_RL_FUNCTION_TYPEDEF) || !defined(Py_RL_STARTUP_HOOK_TAKES_ARGS) on_pre_input_hook(void) #else on_pre_input_hook(const char *Py_UNUSED(text), int Py_UNUSED(state)) From 64c41d5a9d2d83b47faca86eaef0a911b0bac48b Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 15 Apr 2024 10:31:22 +0200 Subject: [PATCH 4/6] Regenerate configure --- pyconfig.h.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyconfig.h.in b/pyconfig.h.in index 84e85615967690..c279b147db3bdd 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1659,6 +1659,9 @@ SipHash13: 3, externally defined: 0 */ #undef Py_HASH_ALGORITHM +/* Define if rl_startup_hook takes arguments */ +#undef Py_RL_STARTUP_HOOK_TAKES_ARGS + /* Define if you want to enable internal statistics gathering. */ #undef Py_STATS @@ -1671,9 +1674,6 @@ /* assume C89 semantics that RETSIGTYPE is always void */ #undef RETSIGTYPE -/* Define if rl_startup_hook takes arguments */ -#undef RL_STARTUP_HOOK_TAKES_ARGS - /* Define if setpgrp() must be called as setpgrp(0, 0). */ #undef SETPGRP_HAVE_ARG From 9b2ab096db15dec29961f333052b81027b14e308 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 15 Apr 2024 08:35:08 +0000 Subject: [PATCH 5/6] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Build/2024-04-15-08-35-06.gh-issue-117845.IowzyW.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Build/2024-04-15-08-35-06.gh-issue-117845.IowzyW.rst diff --git a/Misc/NEWS.d/next/Build/2024-04-15-08-35-06.gh-issue-117845.IowzyW.rst b/Misc/NEWS.d/next/Build/2024-04-15-08-35-06.gh-issue-117845.IowzyW.rst new file mode 100644 index 00000000000000..715250911c6b67 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2024-04-15-08-35-06.gh-issue-117845.IowzyW.rst @@ -0,0 +1 @@ +Fixed function pointer type mismatch when building the readline module against recent libedit versions. From 9322a8455795cb2d7ea7afa271679dadd07db145 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 15 Apr 2024 11:05:22 +0200 Subject: [PATCH 6/6] Update Misc/NEWS.d/next/Build/2024-04-15-08-35-06.gh-issue-117845.IowzyW.rst --- .../next/Build/2024-04-15-08-35-06.gh-issue-117845.IowzyW.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Build/2024-04-15-08-35-06.gh-issue-117845.IowzyW.rst b/Misc/NEWS.d/next/Build/2024-04-15-08-35-06.gh-issue-117845.IowzyW.rst index 715250911c6b67..02d62da15b2546 100644 --- a/Misc/NEWS.d/next/Build/2024-04-15-08-35-06.gh-issue-117845.IowzyW.rst +++ b/Misc/NEWS.d/next/Build/2024-04-15-08-35-06.gh-issue-117845.IowzyW.rst @@ -1 +1 @@ -Fixed function pointer type mismatch when building the readline module against recent libedit versions. +Fix building against recent libedit versions by detecting readline hook signatures in :program:`configure`.