Skip to content

Commit cd69ca3

Browse files
petknielsdos
authored andcommitted
Fix bug #51558: shared readline build fails (php#15242)
The 'rl_pending_input' is a variable in Readline library and checking it with PHP_CHECK_LIBRARY wouldn't find it on some systems. Library check works on most systems but not on the mentioned AIX in the bug as it exports variables and functions differently whereas the linker couldn't resolve the variable as a function. This should fix the build on systems where this caused issues, such as AIX. The <readline/readline.h> is not self-contained header and needs to also have <stdio.h> included before to have FILE type available. This fixes the issue on unpatched default readline installations, such as macOS. Checking this variable ensures that the found library is the correct library and also that it is of minimum version needed by current PHP code (https://bugs.php.net/48608). The library check: ```c | char rl_pending_input (); | int main (void) { | return rl_pending_input (); | } ``` The declaration check: ```c | #include <stdio.h> | #include <readline/readline.h> | int main (void) { | #ifndef rl_pending_input | #ifdef __cplusplus | (void) rl_pending_input; | #else | (void) rl_pending_input; | #endif | #endif | ; | return 0; | } ``` Closes https://bugs.php.net/51558
1 parent f94c11f commit cd69ca3

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ PHP NEWS
2727
return value check). (nielsdos, botovq)
2828
. Fix error return check of EVP_CIPHER_CTX_ctrl(). (nielsdos)
2929

30+
- Readline:
31+
. Fixed bug GH-19250 and bug #51360 (Invalid conftest for rl_pending_input).
32+
(petk, nielsdos)
33+
3034
- SOAP:
3135
. Fixed bug GH-18640 (heap-use-after-free ext/soap/php_encoding.c:299:32
3236
in soap_check_zval_ref). (nielsdos)

ext/readline/config.m4

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,6 @@ if test "$PHP_READLINE" && test "$PHP_READLINE" != "no"; then
4747
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
4848
])
4949

50-
PHP_CHECK_LIBRARY(readline, rl_pending_input,
51-
[], [
52-
AC_MSG_ERROR([invalid readline installation detected. Try --with-libedit instead.])
53-
], [
54-
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
55-
])
56-
5750
PHP_CHECK_LIBRARY(readline, rl_callback_read_char,
5851
[
5952
AC_DEFINE(HAVE_RL_CALLBACK_READ_CHAR, 1, [ ])
@@ -75,6 +68,26 @@ if test "$PHP_READLINE" && test "$PHP_READLINE" != "no"; then
7568
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
7669
])
7770

71+
CFLAGS_SAVE=$CFLAGS
72+
LDFLAGS_SAVE=$LDFLAGS
73+
LIBS_SAVE=$LIBS
74+
CFLAGS="$CFLAGS $INCLUDES"
75+
LDFLAGS="$LDFLAGS -L$READLINE_DIR/$PHP_LIBDIR"
76+
LIBS="$LIBS -lreadline"
77+
78+
dnl Sanity and minimum version check if readline library has variable
79+
dnl rl_pending_input.
80+
AC_CHECK_DECL([rl_pending_input],, [AC_MSG_FAILURE([
81+
Invalid readline installation detected. Try --with-libedit instead.
82+
])], [
83+
#include <stdio.h>
84+
#include <readline/readline.h>
85+
])
86+
87+
CFLAGS=$CFLAGS_SAVE
88+
LDFLAGS=$LDFLAGS_SAVE
89+
LIBS=$LIBS_SAVE
90+
7891
AC_DEFINE(HAVE_HISTORY_LIST, 1, [ ])
7992
AC_DEFINE(HAVE_LIBREADLINE, 1, [ ])
8093

0 commit comments

Comments
 (0)