]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-117845: Detect libedit hook function signature in configure (#117870)
authorJoshua Root <jmr@macports.org>
Wed, 17 Apr 2024 09:26:10 +0000 (19:26 +1000)
committerGitHub <noreply@github.com>
Wed, 17 Apr 2024 09:26:10 +0000 (11:26 +0200)
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.

Misc/NEWS.d/next/Build/2024-04-15-08-35-06.gh-issue-117845.IowzyW.rst [new file with mode: 0644]
Modules/readline.c
configure
configure.ac
pyconfig.h.in

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 (file)
index 0000000..02d62da
--- /dev/null
@@ -0,0 +1 @@
+Fix building against recent libedit versions by detecting readline hook signatures in :program:`configure`.
index e29051c37f882717de41eb420e34e30c225290b8..c5c34535de015469ce26a564aa3eb29a4638d739 100644 (file)
@@ -1041,7 +1041,7 @@ on_hook(PyObject *func)
 }
 
 static int
-#if defined(_RL_FUNCTION_TYPEDEF)
+#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)
+#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))
index 6782d470aadfff52b6ae299eafe4ba154ad06ec4..29a7d5b2b86c29321d8091f417e3190957415cbf 100755 (executable)
--- a/configure
+++ b/configure
@@ -25367,6 +25367,56 @@ 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 $as_nop
+
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+      #include <stdio.h> /* Must be first for Gnu Readline */
+      #ifdef WITH_EDITLINE
+      # include <editline/readline.h>
+      #else
+      # include <readline/readline.h>
+      # include <readline/history.h>
+      #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 $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
+
+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 Py_RL_STARTUP_HOOK_TAKES_ARGS 1" >>confdefs.h
+
+
+fi
+
 
 
 CFLAGS=$save_CFLAGS
index 51a0d35dbc328e95bc571be86498c73c5794bbcf..7723c805b93daeea1c017b264012c3c40e2c6e93 100644 (file)
@@ -6341,6 +6341,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([Py_RL_STARTUP_HOOK_TAKES_ARGS], [1], [Define if rl_startup_hook takes arguments])
+    ])
+
     m4_undefine([readline_includes])
   ])dnl WITH_SAVE_ENV()
 ])
index e28baef51d57373ad224337d50e84cd035e2673e..c279b147db3bdd24c4e435b772ef1b2dc4b13881 100644 (file)
    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