Skip to content

Commit

Permalink
Cast const char** in globalStringInternals to char**.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aclemons committed Dec 12, 2024
1 parent 99fe57e commit 7e18ab1
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/native/org_gnu_readline_Readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,18 @@ static int* globalIntegerInternals[] = {
};

static char** globalStringInternals[] = {
/* const */ &rl_library_version,
/* const */ &rl_readline_name,
/* const */ (char**) &rl_library_version,
/* const */ (char**) &rl_readline_name,
&rl_prompt,
&rl_line_buffer,
/* const */ &rl_terminal_name,
/* const */ (char**) &rl_terminal_name,
&rl_executing_macro,
/* const */ &rl_basic_word_break_characters,
/* const */ &rl_completer_word_break_characters,
/* const */ &rl_completer_quote_characters,
/* const */ &rl_basic_quote_characters,
/* const */ &rl_filename_quote_characters,
/* const */ &rl_special_prefixes,
/* const */ (char**) &rl_basic_word_break_characters,
/* const */ (char**) &rl_completer_word_break_characters,
/* const */ (char**) &rl_completer_quote_characters,
/* const */ (char**) &rl_basic_quote_characters,
/* const */ (char**) &rl_filename_quote_characters,
/* const */ (char**) &rl_special_prefixes,

&history_word_delimiters,
&history_no_expand_chars,
Expand Down Expand Up @@ -198,18 +198,18 @@ static int* globalIntegerInternals[] = {
};

static char** globalStringInternals[] = {
/* const */ &rl_library_version,
/* const */ &rl_readline_name,
/* const */ (char**) &rl_library_version,
/* const */ (char**) &rl_readline_name,
&undefinedInternalString, /* &rl_prompt, */
&rl_line_buffer,
&undefinedInternalString, /* const &rl_terminal_name, */
&undefinedInternalString, /* &rl_executing_macro, */
/* const */ &rl_basic_word_break_characters,
/* const */ &rl_completer_word_break_characters,
/* const */ &rl_completer_quote_characters,
/* const */ (char**) &rl_basic_word_break_characters,
/* const */ (char**) &rl_completer_word_break_characters,
/* const */ (char**) &rl_completer_quote_characters,
&undefinedInternalString, /* const &rl_basic_quote_characters, */
&undefinedInternalString, /* const &rl_filename_quote_characters, */
/* const */ &rl_special_prefixes,
/* const */ (char**) &rl_special_prefixes,

&undefinedInternalString, /* &history_word_delimiters, */
&undefinedInternalString, /* &history_no_expand_chars, */
Expand Down

0 comments on commit 7e18ab1

Please sign in to comment.