Skip to content

Commit

Permalink
gh-105323: Introduce --with-readline=apple option
Browse files Browse the repository at this point in the history
  • Loading branch information
corona10 committed Aug 30, 2023
1 parent 30305d6 commit 868cb8a
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ jobs:
--config-cache \
--with-pydebug \
--prefix=/opt/python-dev \
--with-readline=apple \
--with-openssl="$(brew --prefix [email protected])"
- name: Build CPython
run: make -j4
Expand Down
10 changes: 7 additions & 3 deletions Doc/using/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -515,13 +515,17 @@ Libraries options

.. versionadded:: 3.3

.. cmdoption:: --with-readline=editline
.. cmdoption:: --with-readline=readline|editline|apple

Use ``editline`` library for backend of the :mod:`readline` module.
Desinate a backend library of the :mod:`readline` module.

Define the ``WITH_EDITLINE`` macro.
readline: default backend
editline: Define the ``WITH_EDITLINE`` macro.
apple: Define the ``WITH_APPLE_READLINE`` macro.

.. versionadded:: 3.10
.. versionchanged:: 3.13
``apple`` for macOS specific backend library option is added.

.. cmdoption:: --without-readline

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
``--with-readline=apple`` is added for macOS build. Patch by Dong-hee Na.
16 changes: 14 additions & 2 deletions Modules/readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -1019,10 +1019,16 @@ on_hook(PyObject *func)
static int
#if defined(_RL_FUNCTION_TYPEDEF)
on_startup_hook(void)
{
#elif defined(__APPLE__) && defined(WITH_APPLE_READLINE)
on_startup_hook(const char *text, int state)
{
(void)text;
(void)state;
#else
on_startup_hook(void)
#endif
{
#endif
int r;
PyGILState_STATE gilstate = PyGILState_Ensure();
r = on_hook(readlinestate_global->startup_hook);
Expand All @@ -1034,10 +1040,16 @@ on_startup_hook(void)
static int
#if defined(_RL_FUNCTION_TYPEDEF)
on_pre_input_hook(void)
{
#elif defined(__APPLE__) && defined(WITH_APPLE_READLINE)
on_pre_input_hook(const char *text, int state)
{
(void)text;
(void)state;
#else
on_pre_input_hook(void)
#endif
{
#endif
int r;
PyGILState_STATE gilstate = PyGILState_Ensure();
r = on_hook(readlinestate_global->pre_input_hook);
Expand Down
16 changes: 16 additions & 0 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -5813,6 +5813,7 @@ dnl library (tinfo ncursesw ncurses termcap). We now assume that libreadline
dnl or readline.pc provide correct linker information.

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

AC_ARG_WITH(
[readline],
Expand All @@ -5822,13 +5823,21 @@ AC_ARG_WITH(
AS_CASE([$with_readline],
[editline|edit], [with_readline=edit],
[yes|readline], [with_readline=readline],
[apple], [with_readline=apple],
[no], [],
[AC_MSG_ERROR([proper usage is --with(out)-readline@<:@=editline|readline|no@:>@])]
)
],
[with_readline=readline]
)

dnl gh-105323: Need to handle the macOS editline as an alias of readline.
AS_VAR_IF([with_readline], [apple], [
AS_CASE([$ac_sys_system/$ac_sys_release],
[Darwin/*], [AC_DEFINE([WITH_APPLE_READLINE]) with_readline=readline],
[])]
)

AS_VAR_IF([with_readline], [readline], [
PKG_CHECK_MODULES([LIBREADLINE], [readline], [
LIBREADLINE=readline
Expand Down
3 changes: 3 additions & 0 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,9 @@
/* Define if WINDOW in curses.h offers a field _flags. */
#undef WINDOW_HAS_FLAGS

/* Define to build the readline module agains apple builtin readline. */
#undef WITH_APPLE_READLINE

/* Define if you want build the _decimal module using a coroutine-local rather
than a thread-local context */
#undef WITH_DECIMAL_CONTEXTVAR
Expand Down

0 comments on commit 868cb8a

Please sign in to comment.