From aaf7bf072e29b009cea74a2383700ea7358a812a Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Tue, 29 Aug 2023 21:48:41 +0900 Subject: [PATCH 1/6] gh-105223: Add special workround for macOS default editline --- Modules/readline.c | 16 ++++++++++++++-- configure | 19 +++++++++++++++++-- configure.ac | 15 +++++++++++++-- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/Modules/readline.c b/Modules/readline.c index 2531b236b6ef17..b3c60a1a841fcc 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_EDITLINE) +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_EDITLINE) +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..ddb7009296ad82 100755 --- a/configure +++ b/configure @@ -23765,18 +23765,33 @@ then : yes|readline) : with_readline=readline ;; #( no) : - ;; #( + with_readline=default ;; #( *) : as_fn_error $? "proper usage is --with(out)-readline[=editline|readline|no]" "$LINENO" 5 ;; esac else $as_nop - with_readline=readline + with_readline=default fi +if test "x$with_readline" = xdefault +then : + + case $ac_sys_system/$ac_sys_release in + Darwin/*) printf "%s\n" "#define WITH_EDITLINE 1" >>confdefs.h + + with_readline=readline + ;; + *) + with_readline=readline + ;; + esac + +fi + if test "x$with_readline" = xreadline then : diff --git a/configure.ac b/configure.ac index 6fb6e110647036..e752c9bf5593d5 100644 --- a/configure.ac +++ b/configure.ac @@ -5822,13 +5822,24 @@ AC_ARG_WITH( AS_CASE([$with_readline], [editline|edit], [with_readline=edit], [yes|readline], [with_readline=readline], - [no], [], + [no], [with_readline=default], [AC_MSG_ERROR([proper usage is --with(out)-readline@<:@=editline|readline|no@:>@])] ) ], - [with_readline=readline] + [with_readline=default] ) +AS_VAR_IF([with_readline], [default], [ + case $ac_sys_system/$ac_sys_release in + Darwin/*) AC_DEFINE([WITH_EDITLINE], [1]) + with_readline=readline + ;; + *) + with_readline=readline + ;; + esac +]) + AS_VAR_IF([with_readline], [readline], [ PKG_CHECK_MODULES([LIBREADLINE], [readline], [ LIBREADLINE=readline From 19fbfa87523e2a59e17980a6eb15a570baf3983a Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Tue, 29 Aug 2023 21:51:08 +0900 Subject: [PATCH 2/6] Add NEWS.d --- .../next/Tests/2023-08-29-21-51-04.gh-issue-105223.lqw_5B.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Tests/2023-08-29-21-51-04.gh-issue-105223.lqw_5B.rst diff --git a/Misc/NEWS.d/next/Tests/2023-08-29-21-51-04.gh-issue-105223.lqw_5B.rst b/Misc/NEWS.d/next/Tests/2023-08-29-21-51-04.gh-issue-105223.lqw_5B.rst new file mode 100644 index 00000000000000..b863350845f85f --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2023-08-29-21-51-04.gh-issue-105223.lqw_5B.rst @@ -0,0 +1 @@ +Add special workround for macOS default editline. Patch By Dong-hee Na. From da9156ff663df248500e78109734f1f24f6f1fec Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Tue, 29 Aug 2023 22:16:41 +0900 Subject: [PATCH 3/6] Address code review --- ...023-08-29-21-51-04.gh-issue-105223.lqw_5B.rst | 1 - configure | 16 +++++++--------- configure.ac | 11 +++-------- 3 files changed, 10 insertions(+), 18 deletions(-) delete mode 100644 Misc/NEWS.d/next/Tests/2023-08-29-21-51-04.gh-issue-105223.lqw_5B.rst diff --git a/Misc/NEWS.d/next/Tests/2023-08-29-21-51-04.gh-issue-105223.lqw_5B.rst b/Misc/NEWS.d/next/Tests/2023-08-29-21-51-04.gh-issue-105223.lqw_5B.rst deleted file mode 100644 index b863350845f85f..00000000000000 --- a/Misc/NEWS.d/next/Tests/2023-08-29-21-51-04.gh-issue-105223.lqw_5B.rst +++ /dev/null @@ -1 +0,0 @@ -Add special workround for macOS default editline. Patch By Dong-hee Na. diff --git a/configure b/configure index ddb7009296ad82..bf0e83e4e2f02c 100755 --- a/configure +++ b/configure @@ -23780,15 +23780,13 @@ fi if test "x$with_readline" = xdefault then : - case $ac_sys_system/$ac_sys_release in - Darwin/*) printf "%s\n" "#define WITH_EDITLINE 1" >>confdefs.h - - with_readline=readline - ;; - *) - with_readline=readline - ;; - esac + case $ac_sys_system/$ac_sys_release in #( + Darwin/*) : + printf "%s\n" "#define WITH_EDITLINE 1" >>confdefs.h + with_readline=readline ;; #( + *) : + with_readline=readline ;; +esac fi diff --git a/configure.ac b/configure.ac index e752c9bf5593d5..3ed89d80472859 100644 --- a/configure.ac +++ b/configure.ac @@ -5830,14 +5830,9 @@ AC_ARG_WITH( ) AS_VAR_IF([with_readline], [default], [ - case $ac_sys_system/$ac_sys_release in - Darwin/*) AC_DEFINE([WITH_EDITLINE], [1]) - with_readline=readline - ;; - *) - with_readline=readline - ;; - esac + AS_CASE([$ac_sys_system/$ac_sys_release], + [Darwin/*], [AC_DEFINE([WITH_EDITLINE], [1]) with_readline=readline], + [with_readline=readline]) ]) AS_VAR_IF([with_readline], [readline], [ From b89dd4cafa72546069b67c6f47a98032fb1dca81 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Tue, 29 Aug 2023 23:30:42 +0900 Subject: [PATCH 4/6] Add comment --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index 3ed89d80472859..2937ec266bd570 100644 --- a/configure.ac +++ b/configure.ac @@ -5829,6 +5829,7 @@ AC_ARG_WITH( [with_readline=default] ) +dnl gh-105323: Need to handle the macOS editline as an alias of readline. AS_VAR_IF([with_readline], [default], [ AS_CASE([$ac_sys_system/$ac_sys_release], [Darwin/*], [AC_DEFINE([WITH_EDITLINE], [1]) with_readline=readline], From 67e3a54c99ece3eee7ba763a1dc7f0b1ec4848e2 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Wed, 30 Aug 2023 01:43:36 +0900 Subject: [PATCH 5/6] Address code review --- Modules/readline.c | 4 ++-- configure | 3 ++- configure.ac | 3 ++- pyconfig.h.in | 3 +++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Modules/readline.c b/Modules/readline.c index b3c60a1a841fcc..9dc717a4587cbd 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -1020,7 +1020,7 @@ static int #if defined(_RL_FUNCTION_TYPEDEF) on_startup_hook(void) { -#elif defined(__APPLE__) && defined(WITH_EDITLINE) +#elif defined(__APPLE__) && defined(WITH_APPLE_READLINE) on_startup_hook(const char *text, int state) { (void)text; @@ -1041,7 +1041,7 @@ static int #if defined(_RL_FUNCTION_TYPEDEF) on_pre_input_hook(void) { -#elif defined(__APPLE__) && defined(WITH_EDITLINE) +#elif defined(__APPLE__) && defined(WITH_APPLE_READLINE) on_pre_input_hook(const char *text, int state) { (void)text; diff --git a/configure b/configure index bf0e83e4e2f02c..fa5e46bdf93f9f 100755 --- a/configure +++ b/configure @@ -23755,6 +23755,7 @@ fi + # Check whether --with-readline was given. if test ${with_readline+y} then : @@ -23782,7 +23783,7 @@ then : case $ac_sys_system/$ac_sys_release in #( Darwin/*) : - printf "%s\n" "#define WITH_EDITLINE 1" >>confdefs.h + printf "%s\n" "#define WITH_APPLE_READLINE 1" >>confdefs.h with_readline=readline ;; #( *) : with_readline=readline ;; diff --git a/configure.ac b/configure.ac index 2937ec266bd570..f7876f898c3270 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], @@ -5832,7 +5833,7 @@ AC_ARG_WITH( dnl gh-105323: Need to handle the macOS editline as an alias of readline. AS_VAR_IF([with_readline], [default], [ AS_CASE([$ac_sys_system/$ac_sys_release], - [Darwin/*], [AC_DEFINE([WITH_EDITLINE], [1]) with_readline=readline], + [Darwin/*], [AC_DEFINE([WITH_APPLE_READLINE], [1]) with_readline=readline], [with_readline=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 From 2e2377f2a54e61647d3f0526fbc89433a4983d24 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Wed, 30 Aug 2023 11:43:41 +0900 Subject: [PATCH 6/6] Address code review --- configure | 10 +++++++--- configure.ac | 9 +++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/configure b/configure index fa5e46bdf93f9f..f022efb42c019f 100755 --- a/configure +++ b/configure @@ -23766,7 +23766,7 @@ then : yes|readline) : with_readline=readline ;; #( no) : - with_readline=default ;; #( + ;; #( *) : as_fn_error $? "proper usage is --with(out)-readline[=editline|readline|no]" "$LINENO" 5 ;; @@ -23784,12 +23784,16 @@ then : case $ac_sys_system/$ac_sys_release in #( Darwin/*) : printf "%s\n" "#define WITH_APPLE_READLINE 1" >>confdefs.h - with_readline=readline ;; #( + ;; #( *) : - with_readline=readline ;; + ;; esac fi +if test "x$with_readline" = xdefault +then : + with_readline=readline +fi if test "x$with_readline" = xreadline then : diff --git a/configure.ac b/configure.ac index f7876f898c3270..c660e60af7f481 100644 --- a/configure.ac +++ b/configure.ac @@ -5823,7 +5823,7 @@ AC_ARG_WITH( AS_CASE([$with_readline], [editline|edit], [with_readline=edit], [yes|readline], [with_readline=readline], - [no], [with_readline=default], + [no], [], [AC_MSG_ERROR([proper usage is --with(out)-readline@<:@=editline|readline|no@:>@])] ) ], @@ -5833,9 +5833,10 @@ AC_ARG_WITH( dnl gh-105323: Need to handle the macOS editline as an alias of readline. AS_VAR_IF([with_readline], [default], [ AS_CASE([$ac_sys_system/$ac_sys_release], - [Darwin/*], [AC_DEFINE([WITH_APPLE_READLINE], [1]) with_readline=readline], - [with_readline=readline]) -]) + [Darwin/*], [AC_DEFINE([WITH_APPLE_READLINE])], + [])] +) +AS_VAR_IF([with_readline], [default], [with_readline=readline]) AS_VAR_IF([with_readline], [readline], [ PKG_CHECK_MODULES([LIBREADLINE], [readline], [