Skip to content

Commit 1b7e3cb

Browse files
committed
Remove readline library
Readline library is not compatible with PHP license-wise and shouldn't be compiled into the executable. This can be simplified by using the libedit library with pkgconf determining its availability. This is a continuation of php#3823 and other discussions in the past.
1 parent b32d505 commit 1b7e3cb

File tree

14 files changed

+66
-229
lines changed

14 files changed

+66
-229
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
libxml2-dev \
6060
libxslt1-dev \
6161
libpq-dev \
62-
libreadline-dev \
62+
libedit-dev \
6363
libldap2-dev \
6464
libsodium-dev \
6565
libargon2-0-dev \

.github/actions/apt-x32/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ runs:
3030
libonig-dev:i386 \
3131
libpng-dev:i386 \
3232
libpq-dev:i386 \
33-
libreadline-dev:i386 \
33+
libedit-dev:i386 \
3434
libsasl2-dev:i386 \
3535
libsodium-dev:i386 \
3636
libsqlite3-dev:i386 \

.github/actions/apt-x64/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ runs:
4545
libxml2-dev \
4646
libxslt1-dev \
4747
libpq-dev \
48-
libreadline-dev \
48+
libedit-dev \
4949
libldap2-dev \
5050
libsodium-dev \
5151
libargon2-0-dev \

.github/actions/configure-macos/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ runs:
4545
--enable-sysvshm \
4646
--enable-shmop \
4747
--enable-pcntl \
48-
--with-readline=/usr/local/opt/readline \
48+
--with-readline \
4949
--enable-mbstring \
5050
--with-curl \
5151
--with-gettext=/usr/local/opt/gettext \

UPGRADING.INTERNALS

+6-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ PHP 8.4 INTERNALS UPGRADE NOTES
4747
b. Unix build system changes
4848
- The configure option --with-zlib-dir has been removed.
4949
- The configure option --enable-phpdbg-readline has been removed. Readline
50-
support in sapi/phpdbg is determined automatically whether ext/readline is
51-
enabled and built statically.
50+
support in sapi/phpdbg is determined automatically whether ext/readline has
51+
been enabled during the build.
52+
- The configure option --with-libedit has been removed (use --with-readline).
53+
- The configure option --with-readline now requires libedit library instead
54+
of Readline library and doesn't accept directory argument anymore. To
55+
customize libedit, use Pkgconf's EDIT_CFLAGS and EDIT_LIBS variables.
5256
- COOKIE_IO_FUNCTIONS_T symbol has been removed (use cookie_io_functions_t).
5357
- HAVE_SOCKADDR_UN_SUN_LEN symbol renamed to HAVE_STRUCT_SOCKADDR_UN_SUN_LEN.
5458
- PHP_CHECK_IN_ADDR_T M4 macro and 'in_addr_t' fallback definition to 'u_int'

build/php.m4

+19
Original file line numberDiff line numberDiff line change
@@ -2023,6 +2023,25 @@ AC_DEFUN([PHP_SETUP_EXPAT], [
20232023
AC_DEFINE(HAVE_LIBEXPAT, 1, [ ])
20242024
])
20252025

2026+
dnl
2027+
dnl
2028+
dnl PHP_SETUP_EDIT([shared-add],[action-if-found],[action-if-not-found])
2029+
dnl
2030+
dnl Common setup macro for linking libedit library.
2031+
dnl
2032+
AC_DEFUN([PHP_SETUP_EDIT], [
2033+
found_libedit=no
2034+
2035+
PKG_CHECK_MODULES([EDIT],[libedit],[found_libedit=yes],[found_libedit=no])
2036+
2037+
if test "$found_libedit" = "yes"; then
2038+
PHP_EVAL_LIBLINE($EDIT_LIBS, $1)
2039+
PHP_EVAL_INCLINE($EDIT_CFLAGS)
2040+
ifelse([$2],[],:,[$2])
2041+
ifelse([$3],[],,[else $3])
2042+
fi
2043+
])
2044+
20262045
dnl ----------------------------------------------------------------------------
20272046
dnl Misc. macros
20282047
dnl ----------------------------------------------------------------------------

ext/readline/config.m4

+10-88
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,14 @@
1-
PHP_ARG_WITH([libedit],
2-
[for libedit readline replacement],
3-
[AS_HELP_STRING([--with-libedit],
4-
[Include libedit readline replacement (CLI/CGI only)])])
5-
6-
if test "$PHP_LIBEDIT" = "no"; then
7-
PHP_ARG_WITH([readline],
8-
[for readline support],
9-
[AS_HELP_STRING([[--with-readline[=DIR]]],
10-
[Include readline support (CLI/CGI only)])])
11-
else
12-
dnl "register" the --with-readline option to prevent invalid "unknown
13-
dnl configure option" warning
14-
php_with_readline=no
15-
fi
1+
PHP_ARG_WITH([readline],
2+
[for readline support with libedit],
3+
[AS_HELP_STRING([[--with-readline]],
4+
[Include readline support using libedit (CLI/CGI only)])])
165

176
if test "$PHP_READLINE" && test "$PHP_READLINE" != "no"; then
18-
for i in $PHP_READLINE /usr/local /usr; do
19-
test -f $i/include/readline/readline.h && READLINE_DIR=$i && break
20-
done
21-
22-
if test -z "$READLINE_DIR"; then
23-
AC_MSG_ERROR(Please reinstall readline - I cannot find readline.h)
7+
if test "$PHP_READLINE" != "yes"; then
8+
AC_MSG_WARN([Library directory ignored, rely on pkg-config])
249
fi
2510

26-
PHP_ADD_INCLUDE($READLINE_DIR/include)
27-
28-
PHP_READLINE_LIBS=""
29-
AC_CHECK_LIB(ncurses, tgetent,
30-
[
31-
PHP_ADD_LIBRARY(ncurses,,READLINE_SHARED_LIBADD)
32-
PHP_READLINE_LIBS="$PHP_READLINE_LIBS -lncurses"
33-
],[
34-
AC_CHECK_LIB(termcap, tgetent,
35-
[
36-
PHP_ADD_LIBRARY(termcap,,READLINE_SHARED_LIBADD)
37-
PHP_READLINE_LIBS="$PHP_READLINE_LIBS -ltermcap"
38-
])
39-
])
40-
41-
PHP_CHECK_LIBRARY(readline, readline,
42-
[
43-
PHP_ADD_LIBRARY_WITH_PATH(readline, $READLINE_DIR/$PHP_LIBDIR, READLINE_SHARED_LIBADD)
44-
], [
45-
AC_MSG_ERROR(readline library not found)
46-
], [
47-
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
48-
])
49-
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-
57-
PHP_CHECK_LIBRARY(readline, rl_callback_read_char,
58-
[
59-
AC_DEFINE(HAVE_RL_CALLBACK_READ_CHAR, 1, [ ])
60-
],[],[
61-
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
62-
])
63-
64-
PHP_CHECK_LIBRARY(readline, rl_on_new_line,
65-
[
66-
AC_DEFINE(HAVE_RL_ON_NEW_LINE, 1, [ ])
67-
],[],[
68-
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
69-
])
70-
71-
PHP_CHECK_LIBRARY(readline, rl_completion_matches,
72-
[
73-
AC_DEFINE(HAVE_RL_COMPLETION_MATCHES, 1, [ ])
74-
],[],[
75-
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
76-
])
77-
78-
AC_DEFINE(HAVE_HISTORY_LIST, 1, [ ])
79-
AC_DEFINE(HAVE_LIBREADLINE, 1, [ ])
80-
81-
elif test "$PHP_LIBEDIT" != "no"; then
82-
if test "$PHP_LIBEDIT" != "yes"; then
83-
AC_MSG_WARN([libedit directory ignored, rely on pkg-config])
84-
fi
85-
86-
PKG_CHECK_MODULES([EDIT], [libedit])
87-
PHP_EVAL_LIBLINE($EDIT_LIBS, READLINE_SHARED_LIBADD)
88-
PHP_EVAL_INCLINE($EDIT_CFLAGS)
11+
PHP_SETUP_EDIT(READLINE_SHARED_LIBADD)
8912

9013
AC_CHECK_LIB(ncurses, tgetent,
9114
[
@@ -133,11 +56,10 @@ elif test "$PHP_LIBEDIT" != "no"; then
13356
$READLINE_SHARED_LIBADD
13457
])
13558

136-
AC_DEFINE(HAVE_LIBEDIT, 1, [ ])
137-
fi
59+
AC_DEFINE(HAVE_LIBEDIT,[1],[Whether libedit is available])
13860

139-
if test "$PHP_READLINE" != "no" || test "$PHP_LIBEDIT" != "no"; then
140-
dnl Add -Wno-strict-prototypes as depends on user libs
61+
dnl Add -Wno-strict-prototypes for Clang because of upstream library issues.
62+
# TODO: Libedit on macos seems to be working fine on current versions.
14163
PHP_NEW_EXTENSION(readline, readline.c readline_cli.c, $ext_shared, cli, "-Wno-strict-prototypes")
14264
PHP_SUBST(READLINE_SHARED_LIBADD)
14365
fi

ext/readline/php_readline.h

+2-7
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,8 @@
1717
#ifndef PHP_READLINE_H
1818
#define PHP_READLINE_H
1919

20-
#if HAVE_LIBEDIT
20+
#ifdef HAVE_LIBEDIT
2121
#define READLINE_LIB "libedit"
22-
#else
23-
#define READLINE_LIB "readline"
24-
#endif
25-
26-
#if HAVE_LIBREADLINE || HAVE_LIBEDIT
2722

2823
extern zend_module_entry readline_module_entry;
2924
#define phpext_readline_ptr &readline_module_entry
@@ -35,6 +30,6 @@ extern zend_module_entry readline_module_entry;
3530

3631
#define phpext_readline_ptr NULL
3732

38-
#endif /* HAVE_LIBREADLINE */
33+
#endif /* HAVE_LIBEDIT */
3934

4035
#endif /* PHP_READLINE_H */

ext/readline/readline.c

+4-93
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,13 @@
2525
#include "readline_cli.h"
2626
#include "readline_arginfo.h"
2727

28-
#if HAVE_LIBREADLINE || HAVE_LIBEDIT
28+
#ifdef HAVE_LIBEDIT
2929

3030
#ifndef HAVE_RL_COMPLETION_MATCHES
3131
#define rl_completion_matches completion_matches
3232
#endif
3333

34-
#ifdef HAVE_LIBEDIT
3534
#include <editline/readline.h>
36-
#else
37-
#include <readline/readline.h>
38-
#include <readline/history.h>
39-
#endif
4035

4136
#if HAVE_RL_CALLBACK_READ_CHAR
4237

@@ -74,10 +69,6 @@ ZEND_GET_MODULE(readline)
7469

7570
PHP_MINIT_FUNCTION(readline)
7671
{
77-
#if HAVE_LIBREADLINE
78-
/* libedit don't need this call which set the tty in cooked mode */
79-
using_history();
80-
#endif
8172
ZVAL_UNDEF(&_readline_completion);
8273
#if HAVE_RL_CALLBACK_READ_CHAR
8374
ZVAL_UNDEF(&_prepped_callback);
@@ -158,23 +149,6 @@ PHP_FUNCTION(readline_info)
158149
add_assoc_long(return_value,"point",rl_point);
159150
#ifndef PHP_WIN32
160151
add_assoc_long(return_value,"end",rl_end);
161-
#endif
162-
#ifdef HAVE_LIBREADLINE
163-
add_assoc_long(return_value,"mark",rl_mark);
164-
add_assoc_long(return_value,"done",rl_done);
165-
add_assoc_long(return_value,"pending_input",rl_pending_input);
166-
add_assoc_string(return_value,"prompt",SAFE_STRING(rl_prompt));
167-
add_assoc_string(return_value,"terminal_name",(char *)SAFE_STRING(rl_terminal_name));
168-
add_assoc_str(return_value, "completion_append_character",
169-
rl_completion_append_character == 0
170-
? ZSTR_EMPTY_ALLOC()
171-
: ZSTR_CHAR(rl_completion_append_character));
172-
add_assoc_bool(return_value,"completion_suppress_append",rl_completion_suppress_append);
173-
#endif
174-
#if HAVE_ERASE_EMPTY_LINE
175-
add_assoc_long(return_value,"erase_empty_line",rl_erase_empty_line);
176-
#endif
177-
#ifndef PHP_WIN32
178152
add_assoc_string(return_value,"library_version",(char *)SAFE_STRING(rl_library_version));
179153
#endif
180154
add_assoc_string(return_value,"readline_name",(char *)SAFE_STRING(rl_readline_name));
@@ -195,55 +169,6 @@ PHP_FUNCTION(readline_info)
195169
#ifndef PHP_WIN32
196170
} else if (zend_string_equals_literal_ci(what, "end")) {
197171
RETVAL_LONG(rl_end);
198-
#endif
199-
#ifdef HAVE_LIBREADLINE
200-
} else if (zend_string_equals_literal_ci(what, "mark")) {
201-
RETVAL_LONG(rl_mark);
202-
} else if (zend_string_equals_literal_ci(what, "done")) {
203-
oldval = rl_done;
204-
if (value) {
205-
rl_done = zval_get_long(value);
206-
}
207-
RETVAL_LONG(oldval);
208-
} else if (zend_string_equals_literal_ci(what, "pending_input")) {
209-
oldval = rl_pending_input;
210-
if (value) {
211-
if (!try_convert_to_string(value)) {
212-
RETURN_THROWS();
213-
}
214-
rl_pending_input = Z_STRVAL_P(value)[0];
215-
}
216-
RETVAL_LONG(oldval);
217-
} else if (zend_string_equals_literal_ci(what, "prompt")) {
218-
RETVAL_STRING(SAFE_STRING(rl_prompt));
219-
} else if (zend_string_equals_literal_ci(what, "terminal_name")) {
220-
RETVAL_STRING((char *)SAFE_STRING(rl_terminal_name));
221-
} else if (zend_string_equals_literal_ci(what, "completion_suppress_append")) {
222-
oldval = rl_completion_suppress_append;
223-
if (value) {
224-
rl_completion_suppress_append = zend_is_true(value);
225-
}
226-
RETVAL_BOOL(oldval);
227-
} else if (zend_string_equals_literal_ci(what, "completion_append_character")) {
228-
oldval = rl_completion_append_character;
229-
if (value) {
230-
if (!try_convert_to_string(value)) {
231-
RETURN_THROWS();
232-
}
233-
rl_completion_append_character = (int)Z_STRVAL_P(value)[0];
234-
}
235-
RETVAL_INTERNED_STR(
236-
oldval == 0 ? ZSTR_EMPTY_ALLOC() : ZSTR_CHAR(oldval));
237-
#endif
238-
#if HAVE_ERASE_EMPTY_LINE
239-
} else if (zend_string_equals_literal_ci(what, "erase_empty_line")) {
240-
oldval = rl_erase_empty_line;
241-
if (value) {
242-
rl_erase_empty_line = zval_get_long(value);
243-
}
244-
RETVAL_LONG(oldval);
245-
#endif
246-
#ifndef PHP_WIN32
247172
} else if (zend_string_equals_literal_ci(what,"library_version")) {
248173
RETVAL_STRING((char *)SAFE_STRING(rl_library_version));
249174
#endif
@@ -291,11 +216,9 @@ PHP_FUNCTION(readline_clear_history)
291216
RETURN_THROWS();
292217
}
293218

294-
#if HAVE_LIBEDIT
295219
/* clear_history is the only function where rl_initialize
296220
is not call to ensure correct allocation */
297221
using_history();
298-
#endif
299222
clear_history();
300223

301224
RETURN_TRUE;
@@ -315,7 +238,7 @@ PHP_FUNCTION(readline_list_history)
315238

316239
array_init(return_value);
317240

318-
#if defined(HAVE_LIBEDIT) && defined(PHP_WIN32) /* Winedit on Windows */
241+
#ifdef PHP_WIN32 /* Winedit on Windows */
319242
history = history_list();
320243

321244
if (history) {
@@ -325,7 +248,7 @@ PHP_FUNCTION(readline_list_history)
325248
}
326249
}
327250

328-
#elif defined(HAVE_LIBEDIT) /* libedit */
251+
#else
329252
{
330253
HISTORY_STATE *hs;
331254
int i;
@@ -342,16 +265,6 @@ PHP_FUNCTION(readline_list_history)
342265
}
343266
free(hs);
344267
}
345-
346-
#else /* readline */
347-
history = history_list();
348-
349-
if (history) {
350-
int i;
351-
for (i = 0; history[i]; i++) {
352-
add_next_index_string(return_value, history[i]->line);
353-
}
354-
}
355268
#endif
356269
}
357270
/* }}} */
@@ -572,11 +485,9 @@ PHP_FUNCTION(readline_redisplay)
572485
RETURN_THROWS();
573486
}
574487

575-
#if HAVE_LIBEDIT
576488
/* seems libedit doesn't take care of rl_initialize in rl_redisplay
577489
* see bug #72538 */
578490
using_history();
579-
#endif
580491
rl_redisplay();
581492
}
582493
/* }}} */
@@ -598,4 +509,4 @@ PHP_FUNCTION(readline_on_new_line)
598509
#endif
599510

600511

601-
#endif /* HAVE_LIBREADLINE */
512+
#endif /* HAVE_LIBEDIT */

0 commit comments

Comments
 (0)