php-src/ext/readline
Peter Kokot 17df11e3f7
Fix bug #51558: shared readline build fails (#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

Closes GH-19259.
2025-07-27 15:33:48 +02:00
..
tests CI disable leak sanitizer on two libedit tests temporarily. 2024-08-07 22:38:30 +01:00
config.m4 Fix bug #51558: shared readline build fails (#15242) 2025-07-27 15:33:48 +02:00
config.w32
CREDITS
php_readline.h Declare ext/readline constants in stubs (#9110) 2022-07-23 12:33:44 +02:00
readline.c Fix memory leak when calloc() fails in php_readline_completion_cb() 2025-05-24 20:39:14 +02:00
readline.stub.php Declare ext/readline constants in stubs (#9110) 2022-07-23 12:33:44 +02:00
readline_arginfo.h Do not generate CONST_CS when registering constants (#9439) 2022-08-28 08:27:19 +02:00
readline_cli.c Merge branch 'PHP-8.2' into PHP-8.3 2024-05-10 16:48:59 +02:00
readline_cli.h Update http->https in license (#6945) 2021-05-06 12:16:35 +02:00
README.md Allow overriding completion in auto_prepend_file 2020-08-01 11:39:08 -04:00

readline

Provides generic line editing, history, and tokenization functions. See https://www.php.net/manual/en/book.readline.php

Implementation Details

C variables starting with rl_* are declared by the readline library (or are macros referring to variables from the libedit library). See http://web.mit.edu/gnu/doc/html/rlman_2.html

This should only be used in the CLI SAPI. Historically, the code lived in sapi/cli, but many distributions build readline as a shared extension. Therefore, that code was split into ext/readline so that this can dynamically be loaded. With other SAPIs, readline is/should be disabled.

readline_cli.c implements most of the interactive shell(php -a).