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

Build failure with GCC 14 (initialization from incompatible pointer type) #41

Open
ebourg opened this issue Dec 11, 2024 · 1 comment
Open
Assignees

Comments

@ebourg
Copy link

ebourg commented Dec 11, 2024

Hi,

Readline fails to build with GCC 14, we get the following error in Debian:

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1075200

gcc -I /usr/lib/jvm/default-java/include -I /usr/lib/jvm/default-java/include/linux -I /usr/lib/jvm/default-java/include -I /usr/lib/jvm/default-java/include/linux -Wdate-time -D_FORTIFY_SOURCE=2 -g -O2 -Werror=implicit-function-declaration -ffile-prefix-map=/build/reproducible-path/libreadline-java-0.8.0.1+dfsg=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -fPIC -DPOSIX -fPIC -DPOSIX -DJavaReadline \
                                   -c org_gnu_readline_Readline.c
org_gnu_readline_Readline.c:85:3: error: initialization of 'int *' from incompatible pointer type 'long unsigned int *' [-Wincompatible-pointer-types]
   85 |   &rl_readline_state,
      |   ^
org_gnu_readline_Readline.c:85:3: note: (near initialization for 'globalIntegerInternals[2]')
org_gnu_readline_Readline.c:120:14: error: initialization of 'char **' from incompatible pointer type 'const char **' [-Wincompatible-pointer-types]
  120 |  /* const */ &rl_library_version,
      |              ^
org_gnu_readline_Readline.c:120:14: note: (near initialization for 'globalStringInternals[0]')
org_gnu_readline_Readline.c:121:14: error: initialization of 'char **' from incompatible pointer type 'const char **' [-Wincompatible-pointer-types]
  121 |  /* const */ &rl_readline_name,
      |              ^
org_gnu_readline_Readline.c:121:14: note: (near initialization for 'globalStringInternals[1]')
org_gnu_readline_Readline.c:124:14: error: initialization of 'char **' from incompatible pointer type 'const char **' [-Wincompatible-pointer-types]
  124 |  /* const */ &rl_terminal_name,
      |              ^
org_gnu_readline_Readline.c:124:14: note: (near initialization for 'globalStringInternals[4]')
org_gnu_readline_Readline.c:126:14: error: initialization of 'char **' from incompatible pointer type 'const char **' [-Wincompatible-pointer-types]
  126 |  /* const */ &rl_basic_word_break_characters,
      |              ^
org_gnu_readline_Readline.c:126:14: note: (near initialization for 'globalStringInternals[6]')
org_gnu_readline_Readline.c:127:14: error: initialization of 'char **' from incompatible pointer type 'const char **' [-Wincompatible-pointer-types]
  127 |  /* const */ &rl_completer_word_break_characters,
      |              ^
org_gnu_readline_Readline.c:127:14: note: (near initialization for 'globalStringInternals[7]')
org_gnu_readline_Readline.c:128:14: error: initialization of 'char **' from incompatible pointer type 'const char **' [-Wincompatible-pointer-types]
  128 |  /* const */ &rl_completer_quote_characters,
      |              ^
org_gnu_readline_Readline.c:128:14: note: (near initialization for 'globalStringInternals[8]')
org_gnu_readline_Readline.c:129:14: error: initialization of 'char **' from incompatible pointer type 'const char **' [-Wincompatible-pointer-types]
  129 |  /* const */ &rl_basic_quote_characters,
      |              ^
org_gnu_readline_Readline.c:129:14: note: (near initialization for 'globalStringInternals[9]')
org_gnu_readline_Readline.c:130:14: error: initialization of 'char **' from incompatible pointer type 'const char **' [-Wincompatible-pointer-types]
  130 |  /* const */ &rl_filename_quote_characters,
      |              ^
org_gnu_readline_Readline.c:130:14: note: (near initialization for 'globalStringInternals[10]')
org_gnu_readline_Readline.c:131:14: error: initialization of 'char **' from incompatible pointer type 'const char **' [-Wincompatible-pointer-types]
  131 |  /* const */ &rl_special_prefixes,
      |              ^
org_gnu_readline_Readline.c:131:14: note: (near initialization for 'globalStringInternals[11]')
aclemons added a commit that referenced this issue Dec 11, 2024
We have some compile issues on 24.04. The open issue #41 is tracking
this. We'll enable 24.04 when we commit the fix for that issue.
aclemons added a commit that referenced this issue Dec 12, 2024
These should take a pointer to a JNIEnv. These were introduced in b178aa0 to
replace:

```c
static char* utf2ucs(const char *utf8, char *ucs, size_t n);
static char* ucs2utf(const char *ucs, char *utf8, size_t n);
```

They were added as:

```c
static char* fromjstring(const JNIEnv *env, jstring value);
static jstring tojstring(const JNIEnv *env, const char* value);
```

In this case however, we actually just wanted to declare these as a
constant pointer not a pointer to a constant.

Newer gcc versions complain with:

```
org_gnu_readline_Readline.c: In function ‘fromjstring’:
org_gnu_readline_Readline.c:780:54: warning: passing argument 1 of ‘((const struct JNINativeInterface_ *)*env)->GetObjectClass’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  780 |   const jclass jstringClass = (*env)->GetObjectClass(env, value);
      |                                                      ^~~
org_gnu_readline_Readline.c:780:54: note: expected ‘const struct JNINativeInterface_ **’ but argument is of type ‘const struct JNINativeInterface_ * const*’
org_gnu_readline_Readline.c:781:58: warning: passing argument 1 of ‘((const struct JNINativeInterface_ *)*env)->GetMethodID’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  781 |   const jmethodID getBytesMethodId = (*env)->GetMethodID(env, jstringClass, "getBytes", "()[B");
      |                                                          ^~~
org_gnu_readline_Readline.c:781:58: note: expected ‘const struct JNINativeInterface_ **’ but argument is of type ‘const struct JNINativeInterface_ * const*’
org_gnu_readline_Readline.c:783:74: warning: passing argument 1 of ‘((const struct JNINativeInterface_ *)*env)->CallObjectMethod’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  783 |   const jbyteArray jstringJBytes = (jbyteArray) (*env)->CallObjectMethod(env, value, getBytesMethodId);
      |                                                                          ^~~
```

Newer clang versions complain with:

```
org_gnu_readline_Readline.c:780:54: warning: passing 'const JNIEnv *' (aka 'const struct JNINativeInterface_ *const *') to parameter of type 'JNIEnv *' (aka 'const struct JNINativeInterface_ **') discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
  780 |   const jclass jstringClass = (*env)->GetObjectClass(env, value);
      |                                                      ^~~
org_gnu_readline_Readline.c:781:58: warning: passing 'const JNIEnv *' (aka 'const struct JNINativeInterface_ *const *') to parameter of type 'JNIEnv *' (aka 'const struct JNINativeInterface_ **') discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
  781 |   const jmethodID getBytesMethodId = (*env)->GetMethodID(env, jstringClass, "getBytes", "()[B");
      |                                                          ^~~
org_gnu_readline_Readline.c:783:74: warning: passing 'const JNIEnv *' (aka 'const struct JNINativeInterface_ *const *') to parameter of type 'JNIEnv *' (aka 'const struct JNINativeInterface_ **') discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
  783 |   const jbyteArray jstringJBytes = (jbyteArray) (*env)->CallObjectMethod(env, value, getBytesMethodId);
      |                                                                          ^~~
```

Related to #41
aclemons added a commit that referenced this issue Dec 12, 2024
I thought I had resolved the warning here in 8078536, but it is still a
warning when using `env` inside of these functions by passing them into
say `GetObjectClass` etc.

Removing `const` completely silences any warnings.

Related to #41
aclemons added a commit that referenced this issue Dec 12, 2024
I removed this in 73e5c52, but I actually just needed to declare it
correct as:

```c
static char* fromjstring(JNIEnv *const env, jstring value);
static jstring tojstring(JNIEnv *const env, const char* value);
```

This is what actually meant to do in 8078536, but failed to do.

Related to #41
aclemons added a commit that referenced this issue Dec 12, 2024
It returns a poineter to a jbyte, but it was incorrectly declared as a
pointer to a const jbyte.

The warning here is now resolved.

Related to #41.
aclemons added a commit that referenced this issue Dec 12, 2024
Newer compilers error on this. They should do that - the code is
incorrect - we are putting const char** values into this global array.
If someone uses setVarStringImpl to write to one of these, it will
crash.

This is however already mentioned in the documentation:

https://github.com/aclemons/java-readline/blob/99fe57e6c3544be476187fb7c66a664e6326c3ea/src/native/org_gnu_readline_Readline.c#L63-L64

and they all had a comment in front indicating they were:

```c
const `/* const */*
```

Basically we are relying on code using java-readline to not call the
wrong thing.

It has been this way for more than 20 years, so for now I will not
change this and will simply cast away the compiler error.

Related to #41
@aclemons
Copy link
Owner

Thanks @ebourg. I have handled all of these apart from:

org_gnu_readline_Readline.c:98:3: error: initialization of ‘int *’ from incompatible pointer type ‘long unsigned int *’ [-Wincompatible-pointer-types]
   98 |   &rl_readline_state,
      |   ^
org_gnu_readline_Readline.c:98:3: note: (near initialization for ‘globalIntegerInternals[2]’)

this is from an ABI change introduced in readline 7.0 where rl_readline_state changed from int to long unsigned int.

I raised an issue to track that (#45), and I need to think about how I best want to do it. I guess it will also be a breaking change for anything using java-readline if I bubble up the type change to java-readline's interface too.

@aclemons aclemons self-assigned this Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants