Skip to content

Commit 868cb8a

Browse files
committed
gh-105323: Introduce --with-readline=apple option
1 parent 30305d6 commit 868cb8a

File tree

7 files changed

+51
-5
lines changed

7 files changed

+51
-5
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ jobs:
229229
--config-cache \
230230
--with-pydebug \
231231
--prefix=/opt/python-dev \
232+
--with-readline=apple \
232233
--with-openssl="$(brew --prefix [email protected])"
233234
- name: Build CPython
234235
run: make -j4

Doc/using/configure.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,13 +515,17 @@ Libraries options
515515

516516
.. versionadded:: 3.3
517517

518-
.. cmdoption:: --with-readline=editline
518+
.. cmdoption:: --with-readline=readline|editline|apple
519519

520-
Use ``editline`` library for backend of the :mod:`readline` module.
520+
Desinate a backend library of the :mod:`readline` module.
521521

522-
Define the ``WITH_EDITLINE`` macro.
522+
readline: default backend
523+
editline: Define the ``WITH_EDITLINE`` macro.
524+
apple: Define the ``WITH_APPLE_READLINE`` macro.
523525

524526
.. versionadded:: 3.10
527+
.. versionchanged:: 3.13
528+
``apple`` for macOS specific backend library option is added.
525529

526530
.. cmdoption:: --without-readline
527531

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``--with-readline=apple`` is added for macOS build. Patch by Dong-hee Na.

Modules/readline.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,10 +1019,16 @@ on_hook(PyObject *func)
10191019
static int
10201020
#if defined(_RL_FUNCTION_TYPEDEF)
10211021
on_startup_hook(void)
1022+
{
1023+
#elif defined(__APPLE__) && defined(WITH_APPLE_READLINE)
1024+
on_startup_hook(const char *text, int state)
1025+
{
1026+
(void)text;
1027+
(void)state;
10221028
#else
10231029
on_startup_hook(void)
1024-
#endif
10251030
{
1031+
#endif
10261032
int r;
10271033
PyGILState_STATE gilstate = PyGILState_Ensure();
10281034
r = on_hook(readlinestate_global->startup_hook);
@@ -1034,10 +1040,16 @@ on_startup_hook(void)
10341040
static int
10351041
#if defined(_RL_FUNCTION_TYPEDEF)
10361042
on_pre_input_hook(void)
1043+
{
1044+
#elif defined(__APPLE__) && defined(WITH_APPLE_READLINE)
1045+
on_pre_input_hook(const char *text, int state)
1046+
{
1047+
(void)text;
1048+
(void)state;
10371049
#else
10381050
on_pre_input_hook(void)
1039-
#endif
10401051
{
1052+
#endif
10411053
int r;
10421054
PyGILState_STATE gilstate = PyGILState_Ensure();
10431055
r = on_hook(readlinestate_global->pre_input_hook);

configure

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5813,6 +5813,7 @@ dnl library (tinfo ncursesw ncurses termcap). We now assume that libreadline
58135813
dnl or readline.pc provide correct linker information.
58145814

58155815
AH_TEMPLATE([WITH_EDITLINE], [Define to build the readline module against libedit.])
5816+
AH_TEMPLATE([WITH_APPLE_READLINE], [Define to build the readline module agains apple builtin readline.])
58165817

58175818
AC_ARG_WITH(
58185819
[readline],
@@ -5822,13 +5823,21 @@ AC_ARG_WITH(
58225823
AS_CASE([$with_readline],
58235824
[editline|edit], [with_readline=edit],
58245825
[yes|readline], [with_readline=readline],
5826+
[apple], [with_readline=apple],
58255827
[no], [],
58265828
[AC_MSG_ERROR([proper usage is --with(out)-readline@<:@=editline|readline|no@:>@])]
58275829
)
58285830
],
58295831
[with_readline=readline]
58305832
)
58315833

5834+
dnl gh-105323: Need to handle the macOS editline as an alias of readline.
5835+
AS_VAR_IF([with_readline], [apple], [
5836+
AS_CASE([$ac_sys_system/$ac_sys_release],
5837+
[Darwin/*], [AC_DEFINE([WITH_APPLE_READLINE]) with_readline=readline],
5838+
[])]
5839+
)
5840+
58325841
AS_VAR_IF([with_readline], [readline], [
58335842
PKG_CHECK_MODULES([LIBREADLINE], [readline], [
58345843
LIBREADLINE=readline

pyconfig.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,6 +1791,9 @@
17911791
/* Define if WINDOW in curses.h offers a field _flags. */
17921792
#undef WINDOW_HAS_FLAGS
17931793

1794+
/* Define to build the readline module agains apple builtin readline. */
1795+
#undef WITH_APPLE_READLINE
1796+
17941797
/* Define if you want build the _decimal module using a coroutine-local rather
17951798
than a thread-local context */
17961799
#undef WITH_DECIMAL_CONTEXTVAR

0 commit comments

Comments
 (0)