Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_EDITLINE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that other distributors and users of Python on macOS may be linking to a libedit that is not the Apple-supplied libedit on macOS. For example, MacPorts supplies their own newer version of libedit. So tests like this might not be appropriate. It needs to be tested (see my comments on the issue).

Copy link
Member Author

@corona10 corona10 Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ned, then how about defining the new macro WITH_APPLE_READLINE and using it?
(It will only enabled if the user does not designate the readline option through ./configure`)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you established that there aren't also warnings when compiling with versions of editline other than the macOS system one? I literally don't have time to delve into this now as I'm traveling but I did try to do a quick compile with the current MacPorts version of editline I have installed with me and that also produced compile warnings though not exactly the same ones.

Copy link
Member Author

@corona10 corona10 Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ./configure: Follow apple readline
  • ./configure --with-readline=editline: Follow custom editline
  • ./configure --with-readline=readline: Follow custom readline

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we can add a version check also: RL_READLINE_VERSION==0x0402, all macOS are using identical versions for built-in readline.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

@corona10 corona10 Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm traveling but I did try to do a quick compile with the current MacPorts version of editline I have installed with me and that also produced compile warnings though not exactly the same ones.

Well, it's up to which commits of Python you are using.
After we reverted Irit's patch, there is no compiler warning for system one too.
But it does not mean that the issue is solved because we don't use proper parameters for apple system built-in library and in the future clang compiler will not skip such a mistake.

Please see my comment: #108588 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's up to which commits of Python you are using.
After we reverted Irit's patch, there is no compiler warning for system one too.

Umm, sorry, it was not reverted yet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you established that there aren't also warnings when compiling with versions of editline other than the macOS system one?

I will test them and share soon.

Copy link
Member Author

@corona10 corona10 Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay with b89dd4c
I detected the following warnings with homebrew libedit. (./configure --with-readline=editline)

./Modules/readline.c:1269:21: warning: incompatible function pointer types assigning to 'rl_hook_func_t *' (aka 'int (*)(void)') from 'int (const char *, int)' [-Wincompatible-function-pointer-types]
    rl_startup_hook = on_startup_hook;
                    ^ ~~~~~~~~~~~~~~~
./Modules/readline.c:1271:23: warning: incompatible function pointer types assigning to 'rl_hook_func_t *' (aka 'int (*)(void)') from 'int (const char *, int)' [-Wincompatible-function-pointer-types]
    rl_pre_input_hook = on_pre_input_hook;

And with 67e3a54
there were no compiler warnings.

So I would like to propose updating the policy as I proposed from #108633 (comment)
If people want to custom readline library passing the explicit option looks reasonable and if people want to use the builtin readline library ./configure will be enough.

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_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);
Expand Down
17 changes: 15 additions & 2 deletions configure

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

10 changes: 8 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -5822,13 +5822,19 @@ AC_ARG_WITH(
AS_CASE([$with_readline],
[editline|edit], [with_readline=edit],
[yes|readline], [with_readline=readline],
[no], [],
[no], [with_readline=default],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not feel right; if --with-readline=no we ... default to system readline?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah it was my mistake.

[AC_MSG_ERROR([proper usage is --with(out)-readline@<:@=editline|readline|no@:>@])]
)
],
[with_readline=readline]
[with_readline=default]
)

AS_VAR_IF([with_readline], [default], [
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], [
PKG_CHECK_MODULES([LIBREADLINE], [readline], [
LIBREADLINE=readline
Expand Down