On Sun, Jun 16, 2024 at 04:29:10PM +0200, Patrice Dumas wrote: > Hello, > > In standalone info reader code in info/ most function pointers are > declared as a generic function pointer VFunction *, defined in info.h as > > typedef void VFunction (); > > I think that it would be much better to use actual prototypes depending > on the functions to have type checking by the compiler.
Here is a possible patch for the Info command functions, which seem to all have the same prototype. After that there only remains functions in terminal.h and terminal.c, which all have diverse prototypes, but it is easy to determine which one as the pointer and the default function are declared at the same place. -- Pat
diff --git a/ChangeLog b/ChangeLog index e35c0503aa..29830732e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2024-06-16 Patrice Dumas <pertu...@free.fr> + + Use explicit prototype for Info command functions + + * info/m-x.c (info_execute_command): call command function with two + arguments only, window and count. + + * info/doc.h (InfoCommand), info/echo-area.c + (read_and_dispatch_in_echo_area, ea_yank_pop) + (ea_possible_completions), info/info.h (COMMAND_FUNCTION), + info/makedoc.c (process_one_file), info/session.c + (info_read_and_dispatch, read_key_sequence), info/terminal.h + (VFunction): add a function type COMMAND_FUNCTION for pointers on info + commands function and replace the VFunction untyped generic function + type. Move VFunction definition to terminal.h. + 2024-06-16 Patrice Dumas <pertu...@free.fr> * system.h: remove strerror definition, the prototype looks wrong and diff --git a/info/doc.h b/info/doc.h index dde6cb697f..7756f6df84 100644 --- a/info/doc.h +++ b/info/doc.h @@ -41,10 +41,11 @@ typedef struct function_keyseq int *keyseq; } FUNCTION_KEYSEQ; +struct window_struct; /* Structure describing an Info command. */ typedef struct InfoCommand { - VFunction *func; /* Pointer to function implementing command. */ + COMMAND_FUNCTION *func; /* Pointer to function implementing command. */ char *func_name; /* Name of this command. */ FUNCTION_KEYSEQ *keys; /* Key sequences that could invoke this command. */ char *doc; /* Documentation string. */ diff --git a/info/echo-area.c b/info/echo-area.c index b25e104096..61d7b5acbe 100644 --- a/info/echo-area.c +++ b/info/echo-area.c @@ -31,7 +31,7 @@ int info_aborted_echo_area = 0; int echo_area_is_active = 0; /* The address of the last command executed in the echo area. */ -static VFunction *ea_last_executed_command = NULL; +static COMMAND_FUNCTION *ea_last_executed_command = NULL; /* Non-zero means that the last command executed while reading input killed some text. */ @@ -158,7 +158,7 @@ read_and_dispatch_in_echo_area (void) while (1) { int count; - VFunction *cmd; + COMMAND_FUNCTION *cmd; int lk = 0; lk = echo_area_last_command_was_kill; @@ -669,8 +669,8 @@ DECLARE_INFO_COMMAND (ea_yank_pop, _("Yank back a previous kill")) { register int len; - if (((ea_last_executed_command != (VFunction *) ea_yank) && - (ea_last_executed_command != (VFunction *) ea_yank_pop)) || + if (((ea_last_executed_command != ea_yank) && + (ea_last_executed_command != ea_yank_pop)) || (kill_ring_index == 0)) return; @@ -1166,7 +1166,7 @@ DECLARE_INFO_COMMAND (ea_possible_completions, _("List possible completions")) DECLARE_INFO_COMMAND (ea_complete, _("Insert completion")) { - if (ea_last_executed_command == (VFunction *) ea_complete) + if (ea_last_executed_command == ea_complete) { ea_possible_completions (window, count); return; diff --git a/info/info.h b/info/info.h index 3f4bfff596..294ca26d9f 100644 --- a/info/info.h +++ b/info/info.h @@ -23,8 +23,8 @@ /* System dependencies. */ #include "system.h" -/* Some of our other include files use this. */ -typedef void VFunction (); +struct window_struct; +typedef void COMMAND_FUNCTION (struct window_struct *window, int count); #include "string.h" #include "mbiter.h" diff --git a/info/m-x.c b/info/m-x.c index 99d2286cf7..897b0b382e 100644 --- a/info/m-x.c +++ b/info/m-x.c @@ -137,7 +137,7 @@ DECLARE_INFO_COMMAND (info_execute_command, free (line); if (command && command->func) - (*command->func) (active_window, count, 0); + (*command->func) (active_window, count); } } diff --git a/info/makedoc.c b/info/makedoc.c index 6e7daf286f..6810d4d228 100644 --- a/info/makedoc.c +++ b/info/makedoc.c @@ -436,7 +436,7 @@ process_one_file (char *filename, FILE *doc_stream, FILE *funs_stream) doc[offset - point] = '\0'; fprintf (doc_stream, - " { (VFunction *)%s, \"%s\", (FUNCTION_KEYSEQ *)0, %s },\n", + " { %s, \"%s\", (FUNCTION_KEYSEQ *)0, %s },\n", func, func_name, doc); free (func_name); diff --git a/info/session.c b/info/session.c index 9f1df25545..107a22d9c3 100644 --- a/info/session.c +++ b/info/session.c @@ -229,7 +229,7 @@ static int info_keyseq_displayed_p; void info_read_and_dispatch (void) { - VFunction *cmd; + COMMAND_FUNCTION *cmd; int count; for (quit_info_immediately = 0; !quit_info_immediately; ) @@ -5034,7 +5034,7 @@ incremental_search (WINDOW *window, int count) while (isearch_is_active) { - VFunction *func = NULL; + COMMAND_FUNCTION *func = NULL; int quoted = 0; /* Show the search string in the echo area. */ @@ -5562,7 +5562,7 @@ void info_add_digit_to_numeric_arg (WINDOW *, int count); If INSERT, call ea_insert if a printable character was input. */ -VFunction * +COMMAND_FUNCTION * read_key_sequence (Keymap map, int menu, int mouse, int insert, int *count) { @@ -5570,7 +5570,7 @@ read_key_sequence (Keymap map, int menu, int mouse, int reading_universal_argument = 0; int numeric_arg = 1, numeric_arg_sign = 1, *which_explicit_arg; - VFunction *func; + COMMAND_FUNCTION *func; /* Process the right numeric argument. */ if (!echo_area_is_active) diff --git a/info/session.h b/info/session.h index 157398c102..9316bf0b28 100644 --- a/info/session.h +++ b/info/session.h @@ -58,8 +58,8 @@ extern int scroll_last_node; int get_input_key (void); int get_another_input_key (void); -VFunction *read_key_sequence (Keymap map, int menu, int mouse, - int insert, int *count); +COMMAND_FUNCTION *read_key_sequence (Keymap map, int menu, int mouse, + int insert, int *count); unsigned char info_input_pending_p (void); void info_set_node_of_window (WINDOW *window, NODE *node); void info_set_node_of_window_fast (WINDOW *window, NODE *node); diff --git a/info/terminal.h b/info/terminal.h index 91498b63b6..9e37f38889 100644 --- a/info/terminal.h +++ b/info/terminal.h @@ -20,7 +20,7 @@ #if !defined (TERMINAL_H) #define TERMINAL_H -#include "info.h" +typedef void VFunction (); /* For almost every function externally visible from terminal.c, there is a corresponding "hook" function which can be bound in order to replace