Skip to content

Commit 256d4c4

Browse files
committed
Drop support for libreadline
libreadline is GPL, so incompatible with PHP - remove --with-libedit option and rely on pkg-config instead - remove --with-readline DIR option - cleanup conditions using HAVELIBREADLINE or HAVE_LIBEDIT - keep HAVE_LIBEDIT in php_config.h is some extension use it - add libedit-dev for travis - add readline_list_history, as available in libedit >= 3.1
1 parent 81eff22 commit 256d4c4

File tree

5 files changed

+35
-198
lines changed

5 files changed

+35
-198
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ addons:
1010
- locales
1111
- language-pack-de
1212
- re2c
13+
- libedit-dev
1314
- libgmp-dev
1415
- libicu-dev
1516
- libtidy-dev

ext/readline/config.m4

+19-96
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,17 @@
11
dnl config.m4 for extension readline
22

3-
PHP_ARG_WITH(libedit,for libedit readline replacement,
4-
[ --with-libedit[=DIR] Include libedit readline replacement (CLI/CGI only)])
3+
PHP_ARG_WITH(readline, whether to enable readline extension ,
4+
[ --with-readline Enable readline extension using libedit system library (CLI/CGI only)])
55

6-
if test "$PHP_LIBEDIT" = "no"; then
7-
PHP_ARG_WITH(readline,for readline support,
8-
[ --with-readline[=DIR] Include readline support (CLI/CGI only)])
9-
else
10-
dnl "register" the --with-readline option to preven invalid "unknown configure option" warning
11-
php_with_readline=no
12-
fi
13-
14-
if test "$PHP_READLINE" && test "$PHP_READLINE" != "no"; then
15-
for i in $PHP_READLINE /usr/local /usr; do
16-
test -f $i/include/readline/readline.h && READLINE_DIR=$i && break
17-
done
18-
19-
if test -z "$READLINE_DIR"; then
20-
AC_MSG_ERROR(Please reinstall readline - I cannot find readline.h)
6+
if test "$PHP_READLINE" != "no"; then
7+
if test "$PHP_READLINE" != "yes"; then
8+
AC_MSG_ERROR("Using libreadline PATH is no more supported. Use libedit and pkg-config instead.")
219
fi
2210

23-
PHP_ADD_INCLUDE($READLINE_DIR/include)
24-
25-
PHP_READLINE_LIBS=""
26-
AC_CHECK_LIB(ncurses, tgetent,
27-
[
28-
PHP_ADD_LIBRARY(ncurses,,READLINE_SHARED_LIBADD)
29-
PHP_READLINE_LIBS="$PHP_READLINE_LIBS -lncurses"
30-
],[
31-
AC_CHECK_LIB(termcap, tgetent,
32-
[
33-
PHP_ADD_LIBRARY(termcap,,READLINE_SHARED_LIBADD)
34-
PHP_READLINE_LIBS="$PHP_READLINE_LIBS -ltermcap"
35-
])
36-
])
37-
38-
PHP_CHECK_LIBRARY(readline, readline,
39-
[
40-
PHP_ADD_LIBRARY_WITH_PATH(readline, $READLINE_DIR/$PHP_LIBDIR, READLINE_SHARED_LIBADD)
41-
], [
42-
AC_MSG_ERROR(readline library not found)
43-
], [
44-
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
45-
])
46-
47-
PHP_CHECK_LIBRARY(readline, rl_pending_input,
48-
[], [
49-
AC_MSG_ERROR([invalid readline installation detected. Try --with-libedit instead.])
50-
], [
51-
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
52-
])
53-
54-
PHP_CHECK_LIBRARY(readline, rl_callback_read_char,
55-
[
56-
AC_DEFINE(HAVE_RL_CALLBACK_READ_CHAR, 1, [ ])
57-
],[],[
58-
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
59-
])
60-
61-
PHP_CHECK_LIBRARY(readline, rl_on_new_line,
62-
[
63-
AC_DEFINE(HAVE_RL_ON_NEW_LINE, 1, [ ])
64-
],[],[
65-
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
66-
])
67-
68-
PHP_CHECK_LIBRARY(readline, rl_completion_matches,
69-
[
70-
AC_DEFINE(HAVE_RL_COMPLETION_MATCHES, 1, [ ])
71-
],[],[
72-
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
73-
])
74-
75-
AC_DEFINE(HAVE_LIBREADLINE, 1, [ ])
76-
77-
elif test "$PHP_LIBEDIT" != "no"; then
78-
79-
for i in $PHP_LIBEDIT /usr/local /usr; do
80-
test -f $i/include/editline/readline.h && LIBEDIT_DIR=$i && break
81-
done
11+
PKG_CHECK_MODULES([EDIT], [libedit])
12+
PHP_EVAL_LIBLINE($EDIT_LIBS, READLINE_SHARED_LIBADD)
13+
PHP_EVAL_INCLINE($EDIT_CFLAGS)
8214

83-
if test -z "$LIBEDIT_DIR"; then
84-
AC_MSG_ERROR(Please reinstall libedit - I cannot find readline.h)
85-
fi
86-
87-
PHP_ADD_INCLUDE($LIBEDIT_DIR/include)
8815

8916
AC_CHECK_LIB(ncurses, tgetent,
9017
[
@@ -96,40 +23,36 @@ elif test "$PHP_LIBEDIT" != "no"; then
9623
])
9724
])
9825

99-
PHP_CHECK_LIBRARY(edit, readline,
100-
[
101-
PHP_ADD_LIBRARY_WITH_PATH(edit, $LIBEDIT_DIR/$PHP_LIBDIR, READLINE_SHARED_LIBADD)
102-
], [
103-
AC_MSG_ERROR(edit library required by readline not found)
104-
], [
105-
-L$READLINE_DIR/$PHP_LIBDIR
106-
])
107-
10826
PHP_CHECK_LIBRARY(edit, rl_callback_read_char,
10927
[
11028
AC_DEFINE(HAVE_RL_CALLBACK_READ_CHAR, 1, [ ])
11129
],[],[
112-
-L$READLINE_DIR/$PHP_LIBDIR
30+
$READLINE_SHARED_LIBADD
11331
])
11432

11533
PHP_CHECK_LIBRARY(edit, rl_on_new_line,
11634
[
11735
AC_DEFINE(HAVE_RL_ON_NEW_LINE, 1, [ ])
11836
],[],[
119-
-L$READLINE_DIR/$PHP_LIBDIR
37+
$READLINE_SHARED_LIBADD
12038
])
12139

12240
PHP_CHECK_LIBRARY(edit, rl_completion_matches,
12341
[
12442
AC_DEFINE(HAVE_RL_COMPLETION_MATCHES, 1, [ ])
12543
],[],[
126-
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
44+
$READLINE_SHARED_LIBADD
12745
])
12846

129-
AC_DEFINE(HAVE_LIBEDIT, 1, [ ])
130-
fi
47+
PHP_CHECK_LIBRARY(edit, history_list,
48+
[
49+
AC_DEFINE(HAVE_HISTORY_LIST, 1, [ ])
50+
],[],[
51+
$READLINE_SHARED_LIBADD
52+
])
13153

132-
if test "$PHP_READLINE" != "no" || test "$PHP_LIBEDIT" != "no"; then
54+
AC_DEFINE(HAVE_LIBEDIT, 1, [ ])
13355
PHP_NEW_EXTENSION(readline, readline.c readline_cli.c, $ext_shared, cli)
13456
PHP_SUBST(READLINE_SHARED_LIBADD)
13557
fi
58+

ext/readline/php_readline.h

-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#ifndef PHP_READLINE_H
2020
#define PHP_READLINE_H
2121

22-
#if HAVE_LIBREADLINE || HAVE_LIBEDIT
2322
#ifndef PHP_WIN32
2423
#ifdef ZTS
2524
#warning Readline module will *NEVER* be thread-safe
@@ -36,6 +35,4 @@ extern zend_module_entry readline_module_entry;
3635

3736
#define phpext_readline_ptr NULL
3837

39-
#endif /* HAVE_LIBREADLINE */
40-
4138
#endif /* PHP_READLINE_H */

ext/readline/readline.c

+15-86
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,17 @@
2626
#include "php_readline.h"
2727
#include "readline_cli.h"
2828

29-
#if HAVE_LIBREADLINE || HAVE_LIBEDIT
30-
3129
#ifndef HAVE_RL_COMPLETION_MATCHES
3230
#define rl_completion_matches completion_matches
3331
#endif
3432

35-
#ifdef HAVE_LIBEDIT
3633
#include <editline/readline.h>
37-
#else
38-
#include <readline/readline.h>
39-
#include <readline/history.h>
40-
#endif
4134

4235
PHP_FUNCTION(readline);
4336
PHP_FUNCTION(readline_add_history);
4437
PHP_FUNCTION(readline_info);
4538
PHP_FUNCTION(readline_clear_history);
46-
#ifndef HAVE_LIBEDIT
39+
#ifdef HAVE_HISTORY_LIST
4740
PHP_FUNCTION(readline_list_history);
4841
#endif
4942
PHP_FUNCTION(readline_read_history);
@@ -88,7 +81,7 @@ ZEND_END_ARG_INFO()
8881
ZEND_BEGIN_ARG_INFO(arginfo_readline_clear_history, 0)
8982
ZEND_END_ARG_INFO()
9083

91-
#ifndef HAVE_LIBEDIT
84+
#ifdef HAVE_HISTORY_LIST
9285
ZEND_BEGIN_ARG_INFO(arginfo_readline_list_history, 0)
9386
ZEND_END_ARG_INFO()
9487
#endif
@@ -133,7 +126,7 @@ static const zend_function_entry php_readline_functions[] = {
133126
PHP_FE(readline_info, arginfo_readline_info)
134127
PHP_FE(readline_add_history, arginfo_readline_add_history)
135128
PHP_FE(readline_clear_history, arginfo_readline_clear_history)
136-
#ifndef HAVE_LIBEDIT
129+
#ifdef HAVE_HISTORY_LIST
137130
PHP_FE(readline_list_history, arginfo_readline_list_history)
138131
#endif
139132
PHP_FE(readline_read_history, arginfo_readline_read_history)
@@ -170,10 +163,8 @@ ZEND_GET_MODULE(readline)
170163

171164
PHP_MINIT_FUNCTION(readline)
172165
{
173-
#if HAVE_LIBREADLINE
174-
/* libedit don't need this call which set the tty in cooked mode */
175-
using_history();
176-
#endif
166+
/* libedit don't need "using_history" call which set the tty in cooked mode */
167+
177168
ZVAL_UNDEF(&_readline_completion);
178169
#if HAVE_RL_CALLBACK_READ_CHAR
179170
ZVAL_UNDEF(&_prepped_callback);
@@ -254,21 +245,6 @@ PHP_FUNCTION(readline_info)
254245
#ifndef PHP_WIN32
255246
add_assoc_long(return_value,"end",rl_end);
256247
#endif
257-
#ifdef HAVE_LIBREADLINE
258-
add_assoc_long(return_value,"mark",rl_mark);
259-
add_assoc_long(return_value,"done",rl_done);
260-
add_assoc_long(return_value,"pending_input",rl_pending_input);
261-
add_assoc_string(return_value,"prompt",SAFE_STRING(rl_prompt));
262-
add_assoc_string(return_value,"terminal_name",(char *)SAFE_STRING(rl_terminal_name));
263-
add_assoc_str(return_value, "completion_append_character",
264-
rl_completion_append_character == 0
265-
? ZSTR_EMPTY_ALLOC()
266-
: ZSTR_CHAR(rl_completion_append_character));
267-
add_assoc_bool(return_value,"completion_suppress_append",rl_completion_suppress_append);
268-
#endif
269-
#if HAVE_ERASE_EMPTY_LINE
270-
add_assoc_long(return_value,"erase_empty_line",rl_erase_empty_line);
271-
#endif
272248
#ifndef PHP_WIN32
273249
add_assoc_string(return_value,"library_version",(char *)SAFE_STRING(rl_library_version));
274250
#endif
@@ -289,51 +265,6 @@ PHP_FUNCTION(readline_info)
289265
} else if (!strcasecmp(what, "end")) {
290266
RETVAL_LONG(rl_end);
291267
#endif
292-
#ifdef HAVE_LIBREADLINE
293-
} else if (!strcasecmp(what, "mark")) {
294-
RETVAL_LONG(rl_mark);
295-
} else if (!strcasecmp(what, "done")) {
296-
oldval = rl_done;
297-
if (value) {
298-
convert_to_long_ex(value);
299-
rl_done = Z_LVAL_P(value);
300-
}
301-
RETVAL_LONG(oldval);
302-
} else if (!strcasecmp(what, "pending_input")) {
303-
oldval = rl_pending_input;
304-
if (value) {
305-
convert_to_string_ex(value);
306-
rl_pending_input = Z_STRVAL_P(value)[0];
307-
}
308-
RETVAL_LONG(oldval);
309-
} else if (!strcasecmp(what, "prompt")) {
310-
RETVAL_STRING(SAFE_STRING(rl_prompt));
311-
} else if (!strcasecmp(what, "terminal_name")) {
312-
RETVAL_STRING((char *)SAFE_STRING(rl_terminal_name));
313-
} else if (!strcasecmp(what, "completion_suppress_append")) {
314-
oldval = rl_completion_suppress_append;
315-
if (value) {
316-
rl_completion_suppress_append = zend_is_true(value);
317-
}
318-
RETVAL_BOOL(oldval);
319-
} else if (!strcasecmp(what, "completion_append_character")) {
320-
oldval = rl_completion_append_character;
321-
if (value) {
322-
convert_to_string_ex(value)
323-
rl_completion_append_character = (int)Z_STRVAL_P(value)[0];
324-
}
325-
RETVAL_INTERNED_STR(
326-
oldval == 0 ? ZSTR_EMPTY_ALLOC() : ZSTR_CHAR(oldval));
327-
#endif
328-
#if HAVE_ERASE_EMPTY_LINE
329-
} else if (!strcasecmp(what, "erase_empty_line")) {
330-
oldval = rl_erase_empty_line;
331-
if (value) {
332-
convert_to_long_ex(value);
333-
rl_erase_empty_line = Z_LVAL_P(value);
334-
}
335-
RETVAL_LONG(oldval);
336-
#endif
337268
#ifndef PHP_WIN32
338269
} else if (!strcasecmp(what,"library_version")) {
339270
RETVAL_STRING((char *)SAFE_STRING(rl_library_version));
@@ -383,41 +314,43 @@ PHP_FUNCTION(readline_clear_history)
383314
return;
384315
}
385316

386-
#if HAVE_LIBEDIT
387317
/* clear_history is the only function where rl_initialize
388318
is not call to ensure correct allocation */
389319
using_history();
390-
#endif
391320
clear_history();
392321

393322
RETURN_TRUE;
394323
}
395324

396325
/* }}} */
326+
327+
#ifdef HAVE_HISTORY_LIST
397328
/* {{{ proto array readline_list_history(void)
398329
Lists the history */
399-
#ifndef HAVE_LIBEDIT
400330
PHP_FUNCTION(readline_list_history)
401331
{
402332
HIST_ENTRY **history;
333+
HISTORY_STATE *hs;
403334

404335
if (zend_parse_parameters_none() == FAILURE) {
405336
return;
406337
}
407338

339+
using_history();
408340
history = history_list();
409-
341+
hs = history_get_history_state();
410342
array_init(return_value);
411343

412-
if (history) {
344+
if (history && hs) {
413345
int i;
414-
for (i = 0; history[i]; i++) {
415-
add_next_index_string(return_value,history[i]->line);
346+
for (i = 0; i < hs->length; i++) {
347+
add_next_index_string(return_value, history[i]->line);
416348
}
417349
}
418350
}
419-
#endif
420351
/* }}} */
352+
#endif
353+
421354
/* {{{ proto bool readline_read_history([string filename])
422355
Reads the history */
423356
PHP_FUNCTION(readline_read_history)
@@ -638,11 +571,9 @@ PHP_FUNCTION(readline_callback_handler_remove)
638571
Ask readline to redraw the display */
639572
PHP_FUNCTION(readline_redisplay)
640573
{
641-
#if HAVE_LIBEDIT
642574
/* seems libedit doesn't take care of rl_initialize in rl_redisplay
643575
* see bug #72538 */
644576
using_history();
645-
#endif
646577
rl_redisplay();
647578
}
648579
/* }}} */
@@ -660,5 +591,3 @@ PHP_FUNCTION(readline_on_new_line)
660591

661592
#endif
662593

663-
664-
#endif /* HAVE_LIBREADLINE */

0 commit comments

Comments
 (0)