Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible function pointer types assigning to 'Function *' at readline module #105323

Closed
corona10 opened this issue Jun 5, 2023 · 20 comments
Closed
Labels
OS-mac type-bug An unexpected behavior, bug, or error

Comments

@corona10
Copy link
Member

corona10 commented Jun 5, 2023

At macOS 12.5.1 with Apple clang version 14.0.0 (clang-1400.0.29.202)


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

Linked PRs

@corona10 corona10 added the type-bug An unexpected behavior, bug, or error label Jun 5, 2023
@corona10 corona10 changed the title ncompatible function pointer types assigning to 'Function *' at readline module Incompatible function pointer types assigning to 'Function *' at readline module Jun 5, 2023
@corona10 corona10 added the OS-mac label Jun 5, 2023
corona10 added a commit to corona10/cpython that referenced this issue Jun 30, 2023
@corona10
Copy link
Member Author

Header from apple Xcode.

/* typedefs */
typedef int	  Function(const char *, int);
typedef void	  VFunction(void);
typedef void	  VCPFunction(char *);
typedef char	 *CPFunction(const char *, int);
typedef char	**CPPFunction(const char *, int, int);
typedef char     *rl_compentry_func_t(const char *, int);
typedef int	  rl_command_func_t(int, int);

@erlend-aasland
Copy link
Contributor

@corona10, did you get any further with this? I'm getting annoyed at these warnings, myself :)

@corona10
Copy link
Member Author

@erlend-aasland I will try to solve this issue at this weekend ;)

@corona10
Copy link
Member Author

@ned-deily cc @erlend-aasland

Hi Ned,
AFAIK, Apple uses a different readline implementation from GNU and I checked API signatures were the same across versions.
https://github.com/phracker/MacOSX-SDKs
So we can easily solve this issue by using a conditional compile approach.

But if we have to care about linking with the GNU version on the macOS, the problem will be more difficult.
So we need to know that we should care or not.
https://stackoverflow.com/questions/7214374/how-do-i-link-against-the-gnu-readline-library-rather-than-libedit-in-macosx

@erlend-aasland
Copy link
Contributor

But if we have to care about linking with the GNU version on the macOS, the problem will be more difficult.

You can use the preprocessor define WITH_EDITLINE to check if we're compiling with editline or readline.

@corona10
Copy link
Member Author

You can use the preprocessor define WITH_EDITLINE to check if we're compiling with editline or readline.

Wow, That's good! I will prepare the patch by this weekend :)

@erlend-aasland
Copy link
Contributor

If you grep for READLINE in configure.ac, you'll find that the dependency resolver for readline is more complex than that for other extension modules with third party dependencies. See also the WITH_EDITLINE conditional at the top of Modules/readline.c :)

@erlend-aasland
Copy link
Contributor

See discussion on #108588

@corona10
Copy link
Member Author

For reference what I investigated

Backend configure header Real verison Macro Version (RL_READLINE_VERSION) Install Source rl_startup_hook rl_pre_input_hook User
readline --with-readline=readline readline/readline.h 8.2.1 0x0802 brew / MacPorts https://ftp.gnu.org/gnu/readline/ typedef int rl_hook_func_t (void); typedef int rl_hook_func_t (void); Linux/BSD/ macOS/...
libedit w/readline wrapper --with-readline=editline editline/readline.h 20221030-3.1 0x0402 brew / MacPorts https://www.thrysoee.dk/editline/ rl_hook_func_t(void); rl_hook_func_t(void); Linux/BSD/ macOS/...
libedit --with-readline=editline editline/editline.h 1.17.1 n/a https://github.com/troglobit/editline https://github.com/troglobit/editline n/a n/a Linux/BSD/ macOS/...
Apple editline --with-readline=apple readline/readline.h editline/readline.h libedit-57 0x0402 XCode SDK https://github.com/apple-oss-distributions/libedit/ typedef int Function(const char *, int); typedef int Function(const char *, int); macOS

@erlend-aasland
Copy link
Contributor

Ok, it looks like the libedit I linked to would be unusable with CPython, so we can disregard that.

@erlend-aasland
Copy link
Contributor

BTW, we have some really outdated readline checks in configure.ac. Any check for functionality introduced in readline versions before 4.2 could probably be tossed out.

@gaogaotiantian
Copy link
Member

gaogaotiantian commented Nov 29, 2023

I think this issue impacts more than MacOS.

I tried to link libedit on Ubuntu and it has the same issue.

sudo apt install libedit-dev
./configure --with-readline=editline
make
gcc -pthread -I/usr/include/editline -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall    -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden  -I./Include/internal -I./Include/internal/mimalloc  -I. -I./Include    -fPIC -c ./Modules/readline.c -o Modules/readline.o
./Modules/readline.c: In function ‘setup_readline’:
./Modules/readline.c:1309:21: warning: assignment to ‘int (*)(const char *, int)’ from incompatible pointer type ‘int (*)(void)’ [-Wincompatible-pointer-types]
 1309 |     rl_startup_hook = on_startup_hook;
      |                     ^
./Modules/readline.c:1311:23: warning: assignment to ‘int (*)(const char *, int)’ from incompatible pointer type ‘int (*)(void)’ [-Wincompatible-pointer-types]
 1311 |     rl_pre_input_hook = on_pre_input_hook;
      |                       ^

We only use two headers, <editline/readline.h> if with-readline=editline and <readline/readline.h> if with-readline=readline (default). I think <editline/readline.h> always uses the "old" declaration with typedef int Function(const char *, int);.

I was wondering if we need WITH_APPLE_EDITLINE. _RL_FUNCTION_TYPEDEF seems to be the macro to indicate that the rl_* functions have the new style declarations, and the corresponding "old style" is the one with Function.

I think we should do something like

static int
#if defined(_RL_FUNCTION_TYPEDEF)
on_startup_hook(void)
#else
on_startup_hook(const char *Py_UNUSED(text), int Py_UNUSED(state))
#endif

@corona10
Copy link
Member Author

I was wondering if we need WITH_APPLE_EDITLINE. RL_FUNCTION_TYPEDEF seems to be the macro to indicate that the rl* functions have the new style declarations, and the corresponding "old style" is the one with Function.

Okay if this issue is happening outside of macOS too. We can use your suggestion for this issue.
The patch itself tried to reduce impact to outside of macOS.

@corona10
Copy link
Member Author

@gaogaotiantian Do you want to submit the patch?

@gaogaotiantian
Copy link
Member

Yeah I'll do it. As WITH_APPLE_EDITLINE is only used for this, should I just basically revert all the changes in #108665? The docs change to --with-readline should be kept I presume. Anything else?

@corona10
Copy link
Member Author

Yeah I'll do it. As WITH_APPLE_EDITLINE is only used for this, should I just basically revert all the changes in #108665?

Just remove WITH_APPLE_EDITLINE please

@corona10
Copy link
Member Author

Two things are needed.

  1. Remove WITH_APPLE_EDITLINE from configure.ac and regendeate configure file.
  2. Replace #elif defined(WITH_APPLE_EDITLINE) to #else

@gaogaotiantian
Copy link
Member

Two things are needed.

  1. Remove WITH_APPLE_EDITLINE from configure.ac and regendeate configure file.
  2. Replace #elif defined(WITH_APPLE_EDITLINE) to #else

Done in #112513

corona10 pushed a commit that referenced this issue Dec 5, 2023
@erlend-aasland
Copy link
Contributor

Can this be closed, @corona10?

@corona10
Copy link
Member Author

corona10 commented Dec 5, 2023

Can this be closed, @corona10?

Yeah sure!

@corona10 corona10 closed this as completed Dec 5, 2023
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-mac type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants