From 868cb8a324802e97ee2375d75d62c4e4880ce62b Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Tue, 29 Aug 2023 21:48:41 +0900 Subject: [PATCH] gh-105323: Introduce --with-readline=apple option --- .github/workflows/build.yml | 1 + Doc/using/configure.rst | 10 +++++++--- ...023-08-30-11-56-31.gh-issue-105323.mT3plK.rst | 1 + Modules/readline.c | 16 ++++++++++++++-- configure | 16 ++++++++++++++++ configure.ac | 9 +++++++++ pyconfig.h.in | 3 +++ 7 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 Misc/NEWS.d/next/Build/2023-08-30-11-56-31.gh-issue-105323.mT3plK.rst diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d37eb4447ad11a..7cd3537ec270a5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -229,6 +229,7 @@ jobs: --config-cache \ --with-pydebug \ --prefix=/opt/python-dev \ + --with-readline=apple \ --with-openssl="$(brew --prefix openssl@3.0)" - name: Build CPython run: make -j4 diff --git a/Doc/using/configure.rst b/Doc/using/configure.rst index 6279b0efbf9321..045b31a9a3060b 100644 --- a/Doc/using/configure.rst +++ b/Doc/using/configure.rst @@ -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 diff --git a/Misc/NEWS.d/next/Build/2023-08-30-11-56-31.gh-issue-105323.mT3plK.rst b/Misc/NEWS.d/next/Build/2023-08-30-11-56-31.gh-issue-105323.mT3plK.rst new file mode 100644 index 00000000000000..1148a690c14d25 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2023-08-30-11-56-31.gh-issue-105323.mT3plK.rst @@ -0,0 +1 @@ +``--with-readline=apple`` is added for macOS build. Patch by Dong-hee Na. diff --git a/Modules/readline.c b/Modules/readline.c index 2531b236b6ef17..9dc717a4587cbd 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -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); @@ -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); diff --git a/configure b/configure index 57e3307266c0b1..cfa9cdf5b6d9e9 100755 --- a/configure +++ b/configure @@ -23755,6 +23755,7 @@ fi + # Check whether --with-readline was given. if test ${with_readline+y} then : @@ -23764,6 +23765,8 @@ then : with_readline=edit ;; #( yes|readline) : with_readline=readline ;; #( + apple) : + with_readline=apple ;; #( no) : ;; #( *) : @@ -23777,6 +23780,19 @@ else $as_nop fi +if test "x$with_readline" = xapple +then : + + case $ac_sys_system/$ac_sys_release in #( + Darwin/*) : + printf "%s\n" "#define WITH_APPLE_READLINE 1" >>confdefs.h + with_readline=readline ;; #( + *) : + ;; +esac + +fi + if test "x$with_readline" = xreadline then : diff --git a/configure.ac b/configure.ac index 6fb6e110647036..fdec6eb46da690 100644 --- a/configure.ac +++ b/configure.ac @@ -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], @@ -5822,6 +5823,7 @@ 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@:>@])] ) @@ -5829,6 +5831,13 @@ AC_ARG_WITH( [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 diff --git a/pyconfig.h.in b/pyconfig.h.in index 418ccade8e8bb1..1c34784aae74ab 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -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