From a719f655154acaa18b9fecbec7411454ebb29767 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Mon, 5 Aug 2024 10:07:54 +0200 Subject: [PATCH 1/3] Fix bug #51558: shared readline build fails The 'rl_pending_input' is a variable in Readline library and checking it with PHP_CHECK_LIBRARY wouldn't find it on some systems. This should fix the build on systems where this caused issues, such as AIX. Which works on most systems but not on AIX mentioned in the bug as it exports variables and functions differently whereas the linker couldn't resolve the variable as a function. The library check: ```c char rl_pending_input (); int main (void) { return rl_pending_input (); } ``` The declaration check: ```c int main (void) { (void) rl_pending_input; (void) rl_pending_input; ; return 0; } ``` Closes https://bugs.php.net/51558 --- NEWS | 3 +++ ext/readline/config.m4 | 12 +++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 9b2c40872b27e..16fc3b7b13a6d 100644 --- a/NEWS +++ b/NEWS @@ -23,6 +23,9 @@ PHP NEWS - Random: . lcg_value() is now deprecated. (timwolla) +- Readline: + . Fixed bug #51558 (Shared readline build fails). (Peter Kokot) + - Session: . INI settings session.sid_length and session.sid_bits_per_character are now deprecated. (timwolla) diff --git a/ext/readline/config.m4 b/ext/readline/config.m4 index 0ba5fd55656a2..24c4f7634b42c 100644 --- a/ext/readline/config.m4 +++ b/ext/readline/config.m4 @@ -46,11 +46,6 @@ if test "$PHP_READLINE" && test "$PHP_READLINE" != "no"; then [AC_MSG_FAILURE([The readline library not found.])], [-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS]) - PHP_CHECK_LIBRARY([readline], [rl_pending_input], - [], - [AC_MSG_FAILURE([Invalid readline installation detected. Try --with-libedit instead.])], - [-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS]) - PHP_CHECK_LIBRARY([readline], [rl_callback_read_char], [AC_DEFINE([HAVE_RL_CALLBACK_READ_CHAR], [1], [ ])], [], @@ -72,6 +67,13 @@ if test "$PHP_READLINE" && test "$PHP_READLINE" != "no"; then CFLAGS="$CFLAGS $INCLUDES" LDFLAGS="$LDFLAGS -L$READLINE_DIR/$PHP_LIBDIR" LIBS="$LIBS -lreadline" + + dnl Sanity check if readline library has variable rl_pending_input. + AC_CHECK_DECL([rl_pending_input],, [AC_MSG_FAILURE([ + Invalid readline installation detected. Try --with-libedit instead. + ])], + [#include ]) + AC_CHECK_DECL([rl_erase_empty_line], [AC_DEFINE([HAVE_ERASE_EMPTY_LINE], [1])],, [#include ]) From 8d4c9ddc1b26e64a41f1ae11a5bcfaf3d394e506 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Mon, 5 Aug 2024 11:31:21 +0200 Subject: [PATCH 2/3] Fix readline.h header inclusion The realine.h is not self-contained header and needs all sorts of adjustments including the included before. This fixes the issue on unpatched default readline installations, such as macOS. --- ext/readline/config.m4 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ext/readline/config.m4 b/ext/readline/config.m4 index 24c4f7634b42c..c38c372a90b27 100644 --- a/ext/readline/config.m4 +++ b/ext/readline/config.m4 @@ -71,12 +71,16 @@ if test "$PHP_READLINE" && test "$PHP_READLINE" != "no"; then dnl Sanity check if readline library has variable rl_pending_input. AC_CHECK_DECL([rl_pending_input],, [AC_MSG_FAILURE([ Invalid readline installation detected. Try --with-libedit instead. - ])], - [#include ]) + ])], [ + #include + #include + ]) AC_CHECK_DECL([rl_erase_empty_line], - [AC_DEFINE([HAVE_ERASE_EMPTY_LINE], [1])],, - [#include ]) + [AC_DEFINE([HAVE_ERASE_EMPTY_LINE], [1])],, [ + #include + #include + ]) CFLAGS=$CFLAGS_SAVE LDFLAGS=$LDFLAGS_SAVE LIBS=$LIBS_SAVE From 99bae7528be6be4df2b3cde348ec97b4973557a1 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Mon, 5 Aug 2024 15:45:26 +0200 Subject: [PATCH 3/3] [skip ci] Add quick note why this check is even needed --- ext/readline/config.m4 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/readline/config.m4 b/ext/readline/config.m4 index c38c372a90b27..82a3646eb848e 100644 --- a/ext/readline/config.m4 +++ b/ext/readline/config.m4 @@ -68,7 +68,8 @@ if test "$PHP_READLINE" && test "$PHP_READLINE" != "no"; then LDFLAGS="$LDFLAGS -L$READLINE_DIR/$PHP_LIBDIR" LIBS="$LIBS -lreadline" - dnl Sanity check if readline library has variable rl_pending_input. + dnl Sanity and minimum version check if readline library has variable + dnl rl_pending_input. AC_CHECK_DECL([rl_pending_input],, [AC_MSG_FAILURE([ Invalid readline installation detected. Try --with-libedit instead. ])], [