Skip to content

Commit

Permalink
Drop support for libreadline
Browse files Browse the repository at this point in the history
libreadline is GPL, so incompatible with PHP
  • Loading branch information
remicollet committed Feb 22, 2019
1 parent 3cfe80d commit 5256d35
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 179 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -10,6 +10,7 @@ addons:
- locales
- language-pack-de
- re2c
- libedit-dev
- libgmp-dev
- libicu-dev
- libtidy-dev
Expand Down
78 changes: 2 additions & 76 deletions ext/readline/config.m4
Expand Up @@ -3,79 +3,7 @@ dnl config.m4 for extension readline
PHP_ARG_WITH(libedit,for libedit readline replacement,
[ --with-libedit Include libedit readline replacement (CLI/CGI only)])

if test "$PHP_LIBEDIT" = "no"; then
PHP_ARG_WITH(readline,for readline support,
[ --with-readline[=DIR] Include readline support (CLI/CGI only)])
else
dnl "register" the --with-readline option to preven invalid "unknown configure option" warning
php_with_readline=no
fi

if test "$PHP_READLINE" && test "$PHP_READLINE" != "no"; then
for i in $PHP_READLINE /usr/local /usr; do
test -f $i/include/readline/readline.h && READLINE_DIR=$i && break
done

if test -z "$READLINE_DIR"; then
AC_MSG_ERROR(Please reinstall readline - I cannot find readline.h)
fi

PHP_ADD_INCLUDE($READLINE_DIR/include)

PHP_READLINE_LIBS=""
AC_CHECK_LIB(ncurses, tgetent,
[
PHP_ADD_LIBRARY(ncurses,,READLINE_SHARED_LIBADD)
PHP_READLINE_LIBS="$PHP_READLINE_LIBS -lncurses"
],[
AC_CHECK_LIB(termcap, tgetent,
[
PHP_ADD_LIBRARY(termcap,,READLINE_SHARED_LIBADD)
PHP_READLINE_LIBS="$PHP_READLINE_LIBS -ltermcap"
])
])

PHP_CHECK_LIBRARY(readline, readline,
[
PHP_ADD_LIBRARY_WITH_PATH(readline, $READLINE_DIR/$PHP_LIBDIR, READLINE_SHARED_LIBADD)
], [
AC_MSG_ERROR(readline library not found)
], [
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
])

PHP_CHECK_LIBRARY(readline, rl_pending_input,
[], [
AC_MSG_ERROR([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, [ ])
],[],[
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
])

PHP_CHECK_LIBRARY(readline, rl_on_new_line,
[
AC_DEFINE(HAVE_RL_ON_NEW_LINE, 1, [ ])
],[],[
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
])

PHP_CHECK_LIBRARY(readline, rl_completion_matches,
[
AC_DEFINE(HAVE_RL_COMPLETION_MATCHES, 1, [ ])
],[],[
-L$READLINE_DIR/$PHP_LIBDIR $PHP_READLINE_LIBS
])

AC_DEFINE(HAVE_HISTORY_LIST, 1, [ ])
AC_DEFINE(HAVE_LIBREADLINE, 1, [ ])

elif test "$PHP_LIBEDIT" != "no"; then
if test "$PHP_LIBEDIT" != "no"; then
if test "$PHP_LIBEDIT" != "yes"; then
AC_MSG_WARN([libedit directory ignored, rely on pkg-config])
fi
Expand Down Expand Up @@ -131,9 +59,7 @@ elif test "$PHP_LIBEDIT" != "no"; then
])

AC_DEFINE(HAVE_LIBEDIT, 1, [ ])
fi

if test "$PHP_READLINE" != "no" || test "$PHP_LIBEDIT" != "no"; then
PHP_NEW_EXTENSION(readline, readline.c readline_cli.c, $ext_shared, cli)
PHP_SUBST(READLINE_SHARED_LIBADD)
fi

4 changes: 2 additions & 2 deletions ext/readline/php_readline.h
Expand Up @@ -19,7 +19,7 @@
#ifndef PHP_READLINE_H
#define PHP_READLINE_H

#if HAVE_LIBREADLINE || HAVE_LIBEDIT
#if HAVE_LIBEDIT
#ifndef PHP_WIN32
#ifdef ZTS
#warning Readline module will *NEVER* be thread-safe
Expand All @@ -36,6 +36,6 @@ extern zend_module_entry readline_module_entry;

#define phpext_readline_ptr NULL

#endif /* HAVE_LIBREADLINE */
#endif /* HAVE_LIBEDIT */

#endif /* PHP_READLINE_H */
91 changes: 4 additions & 87 deletions ext/readline/readline.c
Expand Up @@ -26,18 +26,13 @@
#include "php_readline.h"
#include "readline_cli.h"

#if HAVE_LIBREADLINE || HAVE_LIBEDIT
#if HAVE_LIBEDIT

#ifndef HAVE_RL_COMPLETION_MATCHES
#define rl_completion_matches completion_matches
#endif

#ifdef HAVE_LIBEDIT
#include <editline/readline.h>
#else
#include <readline/readline.h>
#include <readline/history.h>
#endif

PHP_FUNCTION(readline);
PHP_FUNCTION(readline_add_history);
Expand Down Expand Up @@ -170,10 +165,6 @@ ZEND_GET_MODULE(readline)

PHP_MINIT_FUNCTION(readline)
{
#if HAVE_LIBREADLINE
/* libedit don't need this call which set the tty in cooked mode */
using_history();
#endif
ZVAL_UNDEF(&_readline_completion);
#if HAVE_RL_CALLBACK_READ_CHAR
ZVAL_UNDEF(&_prepped_callback);
Expand Down Expand Up @@ -254,21 +245,6 @@ PHP_FUNCTION(readline_info)
#ifndef PHP_WIN32
add_assoc_long(return_value,"end",rl_end);
#endif
#ifdef HAVE_LIBREADLINE
add_assoc_long(return_value,"mark",rl_mark);
add_assoc_long(return_value,"done",rl_done);
add_assoc_long(return_value,"pending_input",rl_pending_input);
add_assoc_string(return_value,"prompt",SAFE_STRING(rl_prompt));
add_assoc_string(return_value,"terminal_name",(char *)SAFE_STRING(rl_terminal_name));
add_assoc_str(return_value, "completion_append_character",
rl_completion_append_character == 0
? ZSTR_EMPTY_ALLOC()
: ZSTR_CHAR(rl_completion_append_character));
add_assoc_bool(return_value,"completion_suppress_append",rl_completion_suppress_append);
#endif
#if HAVE_ERASE_EMPTY_LINE
add_assoc_long(return_value,"erase_empty_line",rl_erase_empty_line);
#endif
#ifndef PHP_WIN32
add_assoc_string(return_value,"library_version",(char *)SAFE_STRING(rl_library_version));
#endif
Expand All @@ -289,51 +265,6 @@ PHP_FUNCTION(readline_info)
} else if (!strcasecmp(what, "end")) {
RETVAL_LONG(rl_end);
#endif
#ifdef HAVE_LIBREADLINE
} else if (!strcasecmp(what, "mark")) {
RETVAL_LONG(rl_mark);
} else if (!strcasecmp(what, "done")) {
oldval = rl_done;
if (value) {
convert_to_long_ex(value);
rl_done = Z_LVAL_P(value);
}
RETVAL_LONG(oldval);
} else if (!strcasecmp(what, "pending_input")) {
oldval = rl_pending_input;
if (value) {
convert_to_string_ex(value);
rl_pending_input = Z_STRVAL_P(value)[0];
}
RETVAL_LONG(oldval);
} else if (!strcasecmp(what, "prompt")) {
RETVAL_STRING(SAFE_STRING(rl_prompt));
} else if (!strcasecmp(what, "terminal_name")) {
RETVAL_STRING((char *)SAFE_STRING(rl_terminal_name));
} else if (!strcasecmp(what, "completion_suppress_append")) {
oldval = rl_completion_suppress_append;
if (value) {
rl_completion_suppress_append = zend_is_true(value);
}
RETVAL_BOOL(oldval);
} else if (!strcasecmp(what, "completion_append_character")) {
oldval = rl_completion_append_character;
if (value) {
convert_to_string_ex(value)
rl_completion_append_character = (int)Z_STRVAL_P(value)[0];
}
RETVAL_INTERNED_STR(
oldval == 0 ? ZSTR_EMPTY_ALLOC() : ZSTR_CHAR(oldval));
#endif
#if HAVE_ERASE_EMPTY_LINE
} else if (!strcasecmp(what, "erase_empty_line")) {
oldval = rl_erase_empty_line;
if (value) {
convert_to_long_ex(value);
rl_erase_empty_line = Z_LVAL_P(value);
}
RETVAL_LONG(oldval);
#endif
#ifndef PHP_WIN32
} else if (!strcasecmp(what,"library_version")) {
RETVAL_STRING((char *)SAFE_STRING(rl_library_version));
Expand Down Expand Up @@ -383,11 +314,9 @@ PHP_FUNCTION(readline_clear_history)
return;
}

#if HAVE_LIBEDIT
/* clear_history is the only function where rl_initialize
is not call to ensure correct allocation */
using_history();
#endif
clear_history();

RETURN_TRUE;
Expand All @@ -408,7 +337,7 @@ PHP_FUNCTION(readline_list_history)

array_init(return_value);

#if defined(HAVE_LIBEDIT) && defined(PHP_WIN32) /* Winedit on Windows */
#ifdef PHP_WIN32 /* Winedit on Windows */
history = history_list();

if (history) {
Expand All @@ -418,7 +347,7 @@ PHP_FUNCTION(readline_list_history)
}
}

#elif defined(HAVE_LIBEDIT) /* libedit */
#else /* libedit */
{
HISTORY_STATE *hs;
int i;
Expand All @@ -434,16 +363,6 @@ PHP_FUNCTION(readline_list_history)
}
}
}

#else /* readline */
history = history_list();

if (history) {
int i;
for (i = 0; history[i]; i++) {
add_next_index_string(return_value, history[i]->line);
}
}
#endif
}
/* }}} */
Expand Down Expand Up @@ -669,11 +588,9 @@ PHP_FUNCTION(readline_callback_handler_remove)
Ask readline to redraw the display */
PHP_FUNCTION(readline_redisplay)
{
#if HAVE_LIBEDIT
/* seems libedit doesn't take care of rl_initialize in rl_redisplay
* see bug #72538 */
using_history();
#endif
rl_redisplay();
}
/* }}} */
Expand All @@ -692,4 +609,4 @@ PHP_FUNCTION(readline_on_new_line)
#endif


#endif /* HAVE_LIBREADLINE */
#endif /* HAVE_LIBEDIT */
13 changes: 0 additions & 13 deletions ext/readline/readline_cli.c
Expand Up @@ -50,12 +50,7 @@
#include <unixlib/local.h>
#endif

#if HAVE_LIBEDIT
#include <editline/readline.h>
#else
#include <readline/readline.h>
#include <readline/history.h>
#endif

#include "zend_compile.h"
#include "zend_execute.h"
Expand Down Expand Up @@ -667,11 +662,7 @@ static int readline_shell_run(void) /* {{{ */
}

if (history_lines_to_write) {
#if HAVE_LIBEDIT
write_history(history_file);
#else
append_history(history_lines_to_write, history_file);
#endif
history_lines_to_write = 0;
}

Expand Down Expand Up @@ -750,11 +741,7 @@ PHP_MINIT_FUNCTION(cli_readline)
ZEND_INIT_MODULE_GLOBALS(cli_readline, cli_readline_init_globals, NULL);
REGISTER_INI_ENTRIES();

#if HAVE_LIBEDIT
REGISTER_STRING_CONSTANT("READLINE_LIB", "libedit", CONST_CS|CONST_PERSISTENT);
#else
REGISTER_STRING_CONSTANT("READLINE_LIB", "readline", CONST_CS|CONST_PERSISTENT);
#endif

GET_SHELL_CB(cb);
if (cb) {
Expand Down
2 changes: 1 addition & 1 deletion travis/compile.sh
Expand Up @@ -58,7 +58,7 @@ $TS \
--enable-sysvshm \
--enable-shmop \
--enable-pcntl \
--with-readline \
--with-libedit \
--enable-mbstring \
--with-curl \
--with-gettext \
Expand Down

0 comments on commit 5256d35

Please sign in to comment.