1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 19:12:48 -05:00

Change vtable defs to use C99 designated initialisers.

This is a sweeping change applied across the whole code base by a spot
of Emacs Lisp. Now, everywhere I declare a vtable filled with function
pointers (and the occasional const data member), all the members of
the vtable structure are initialised by name using the '.fieldname =
value' syntax introduced in C99.

We were already using this syntax for a handful of things in the new
key-generation progress report system, so it's not new to the code
base as a whole.

The advantage is that now, when a vtable only declares a subset of the
available fields, I can initialise the rest to NULL or zero just by
leaving them out. This is most dramatic in a couple of the outlying
vtables in things like psocks (which has a ConnectionLayerVtable
containing only one non-NULL method), but less dramatically, it means
that the new 'flags' field in BackendVtable can be completely left out
of every backend definition except for the SUPDUP one which defines it
to a nonzero value. Similarly, the test_for_upstream method only used
by SSH doesn't have to be mentioned in the rest of the backends;
network Plugs for listening sockets don't have to explicitly null out
'receive' and 'sent', and vice versa for 'accepting', and so on.

While I'm at it, I've normalised the declarations so they don't use
the unnecessarily verbose 'struct' keyword. Also a handful of them
weren't const; now they are.
This commit is contained in:
Simon Tatham
2020-03-10 21:06:29 +00:00
parent ade10f1304
commit b4e1bca2c3
80 changed files with 1647 additions and 1528 deletions

View File

@ -1001,10 +1001,10 @@ static int win_gui_askappend(LogPolicy *lp, Filename *filename,
}
const LogPolicyVtable win_gui_logpolicy_vt = {
win_gui_eventlog,
win_gui_askappend,
win_gui_logging_error,
null_lp_verbose_yes,
.eventlog = win_gui_eventlog,
.askappend = win_gui_askappend,
.logging_error = win_gui_logging_error,
.verbose = null_lp_verbose_yes,
};
/*

View File

@ -256,34 +256,34 @@ static const char *wintw_get_title(TermWin *, bool icon);
static bool wintw_is_utf8(TermWin *);
static const TermWinVtable windows_termwin_vt = {
wintw_setup_draw_ctx,
wintw_draw_text,
wintw_draw_cursor,
wintw_draw_trust_sigil,
wintw_char_width,
wintw_free_draw_ctx,
wintw_set_cursor_pos,
wintw_set_raw_mouse_mode,
wintw_set_scrollbar,
wintw_bell,
wintw_clip_write,
wintw_clip_request_paste,
wintw_refresh,
wintw_request_resize,
wintw_set_title,
wintw_set_icon_title,
wintw_set_minimised,
wintw_is_minimised,
wintw_set_maximised,
wintw_move,
wintw_set_zorder,
wintw_palette_get,
wintw_palette_set,
wintw_palette_reset,
wintw_get_pos,
wintw_get_pixels,
wintw_get_title,
wintw_is_utf8,
.setup_draw_ctx = wintw_setup_draw_ctx,
.draw_text = wintw_draw_text,
.draw_cursor = wintw_draw_cursor,
.draw_trust_sigil = wintw_draw_trust_sigil,
.char_width = wintw_char_width,
.free_draw_ctx = wintw_free_draw_ctx,
.set_cursor_pos = wintw_set_cursor_pos,
.set_raw_mouse_mode = wintw_set_raw_mouse_mode,
.set_scrollbar = wintw_set_scrollbar,
.bell = wintw_bell,
.clip_write = wintw_clip_write,
.clip_request_paste = wintw_clip_request_paste,
.refresh = wintw_refresh,
.request_resize = wintw_request_resize,
.set_title = wintw_set_title,
.set_icon_title = wintw_set_icon_title,
.set_minimised = wintw_set_minimised,
.is_minimised = wintw_is_minimised,
.set_maximised = wintw_set_maximised,
.move = wintw_move,
.set_zorder = wintw_set_zorder,
.palette_get = wintw_palette_get,
.palette_set = wintw_palette_set,
.palette_reset = wintw_palette_reset,
.get_pos = wintw_get_pos,
.get_pixels = wintw_get_pixels,
.get_title = wintw_get_title,
.is_utf8 = wintw_is_utf8,
};
static TermWin wintw[1];
@ -339,27 +339,27 @@ static bool win_seat_set_trust_status(Seat *seat, bool trusted);
static bool win_seat_get_cursor_position(Seat *seat, int *x, int *y);
static const SeatVtable win_seat_vt = {
win_seat_output,
win_seat_eof,
win_seat_get_userpass_input,
win_seat_notify_remote_exit,
win_seat_connection_fatal,
win_seat_update_specials_menu,
win_seat_get_ttymode,
win_seat_set_busy_status,
win_seat_verify_ssh_host_key,
win_seat_confirm_weak_crypto_primitive,
win_seat_confirm_weak_cached_hostkey,
win_seat_is_utf8,
nullseat_echoedit_update,
nullseat_get_x_display,
nullseat_get_windowid,
win_seat_get_window_pixel_size,
win_seat_stripctrl_new,
win_seat_set_trust_status,
nullseat_verbose_yes,
nullseat_interactive_yes,
win_seat_get_cursor_position,
.output = win_seat_output,
.eof = win_seat_eof,
.get_userpass_input = win_seat_get_userpass_input,
.notify_remote_exit = win_seat_notify_remote_exit,
.connection_fatal = win_seat_connection_fatal,
.update_specials_menu = win_seat_update_specials_menu,
.get_ttymode = win_seat_get_ttymode,
.set_busy_status = win_seat_set_busy_status,
.verify_ssh_host_key = win_seat_verify_ssh_host_key,
.confirm_weak_crypto_primitive = win_seat_confirm_weak_crypto_primitive,
.confirm_weak_cached_hostkey = win_seat_confirm_weak_cached_hostkey,
.is_utf8 = win_seat_is_utf8,
.echoedit_update = nullseat_echoedit_update,
.get_x_display = nullseat_get_x_display,
.get_windowid = nullseat_get_windowid,
.get_window_pixel_size = win_seat_get_window_pixel_size,
.stripctrl_new = win_seat_stripctrl_new,
.set_trust_status = win_seat_set_trust_status,
.verbose = nullseat_verbose_yes,
.interactive = nullseat_interactive_yes,
.get_cursor_position = win_seat_get_cursor_position,
};
static WinGuiSeat wgs = { .seat.vt = &win_seat_vt,
.logpolicy.vt = &win_gui_logpolicy_vt };

View File

@ -304,14 +304,14 @@ static SocketPeerInfo *sk_handle_peer_info(Socket *s)
}
static const SocketVtable HandleSocket_sockvt = {
sk_handle_plug,
sk_handle_close,
sk_handle_write,
sk_handle_write_oob,
sk_handle_write_eof,
sk_handle_set_frozen,
sk_handle_socket_error,
sk_handle_peer_info,
.plug = sk_handle_plug,
.close = sk_handle_close,
.write = sk_handle_write,
.write_oob = sk_handle_write_oob,
.write_eof = sk_handle_write_eof,
.set_frozen = sk_handle_set_frozen,
.socket_error = sk_handle_socket_error,
.peer_info = sk_handle_peer_info,
};
Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H,

View File

@ -831,14 +831,14 @@ static const char *sk_net_socket_error(Socket *s);
static SocketPeerInfo *sk_net_peer_info(Socket *s);
static const SocketVtable NetSocket_sockvt = {
sk_net_plug,
sk_net_close,
sk_net_write,
sk_net_write_oob,
sk_net_write_eof,
sk_net_set_frozen,
sk_net_socket_error,
sk_net_peer_info,
.plug = sk_net_plug,
.close = sk_net_close,
.write = sk_net_write,
.write_oob = sk_net_write_oob,
.write_eof = sk_net_write_eof,
.set_frozen = sk_net_set_frozen,
.socket_error = sk_net_socket_error,
.peer_info = sk_net_peer_info,
};
static Socket *sk_net_accept(accept_ctx_t ctx, Plug *plug)

View File

@ -195,14 +195,10 @@ static void named_pipe_connect_callback(void *vps)
* be asked to write or set_frozen.
*/
static const SocketVtable NamedPipeServerSocket_sockvt = {
sk_namedpipeserver_plug,
sk_namedpipeserver_close,
NULL /* write */,
NULL /* write_oob */,
NULL /* write_eof */,
NULL /* set_frozen */,
sk_namedpipeserver_socket_error,
sk_namedpipeserver_peer_info,
.plug = sk_namedpipeserver_plug,
.close = sk_namedpipeserver_close,
.socket_error = sk_namedpipeserver_socket_error,
.peer_info = sk_namedpipeserver_peer_info,
};
Socket *new_named_pipe_listener(const char *pipename, Plug *plug)

View File

@ -170,13 +170,13 @@ static void win_progress_report_phase_complete(ProgressReceiver *prog)
}
static const ProgressReceiverVtable win_progress_vt = {
win_progress_add_linear,
win_progress_add_probabilistic,
win_progress_ready,
win_progress_start_phase,
win_progress_report,
win_progress_report_attempt,
win_progress_report_phase_complete,
.add_linear = win_progress_add_linear,
.add_probabilistic = win_progress_add_probabilistic,
.ready = win_progress_ready,
.start_phase = win_progress_start_phase,
.report = win_progress_report,
.report_attempt = win_progress_report_attempt,
.report_phase_complete = win_progress_report_phase_complete,
};
static void win_progress_initialise(struct progress *p)

View File

@ -796,9 +796,9 @@ static bool wm_copydata_ask_passphrase(
}
static const PageantClientVtable wmcpc_vtable = {
NULL, /* no logging in this client */
wm_copydata_got_response,
wm_copydata_ask_passphrase,
.log = NULL, /* no logging in this client */
.got_response = wm_copydata_got_response,
.ask_passphrase = wm_copydata_ask_passphrase,
};
static char *answer_filemapping_message(const char *mapname)
@ -1188,8 +1188,8 @@ struct winpgnt_client {
PageantListenerClient plc;
};
static const PageantListenerClientVtable winpgnt_vtable = {
NULL, /* no logging */
winpgnt_listener_ask_passphrase,
.log = NULL, /* no logging */
.ask_passphrase = winpgnt_listener_ask_passphrase,
};
static struct winpgnt_client wpc[1];

View File

@ -81,27 +81,27 @@ static bool plink_seat_interactive(Seat *seat)
}
static const SeatVtable plink_seat_vt = {
plink_output,
plink_eof,
plink_get_userpass_input,
nullseat_notify_remote_exit,
console_connection_fatal,
nullseat_update_specials_menu,
nullseat_get_ttymode,
nullseat_set_busy_status,
console_verify_ssh_host_key,
console_confirm_weak_crypto_primitive,
console_confirm_weak_cached_hostkey,
nullseat_is_never_utf8,
plink_echoedit_update,
nullseat_get_x_display,
nullseat_get_windowid,
nullseat_get_window_pixel_size,
console_stripctrl_new,
console_set_trust_status,
cmdline_seat_verbose,
plink_seat_interactive,
nullseat_get_cursor_position,
.output = plink_output,
.eof = plink_eof,
.get_userpass_input = plink_get_userpass_input,
.notify_remote_exit = nullseat_notify_remote_exit,
.connection_fatal = console_connection_fatal,
.update_specials_menu = nullseat_update_specials_menu,
.get_ttymode = nullseat_get_ttymode,
.set_busy_status = nullseat_set_busy_status,
.verify_ssh_host_key = console_verify_ssh_host_key,
.confirm_weak_crypto_primitive = console_confirm_weak_crypto_primitive,
.confirm_weak_cached_hostkey = console_confirm_weak_cached_hostkey,
.is_utf8 = nullseat_is_never_utf8,
.echoedit_update = plink_echoedit_update,
.get_x_display = nullseat_get_x_display,
.get_windowid = nullseat_get_windowid,
.get_window_pixel_size = nullseat_get_window_pixel_size,
.stripctrl_new = console_stripctrl_new,
.set_trust_status = console_set_trust_status,
.verbose = cmdline_seat_verbose,
.interactive = plink_seat_interactive,
.get_cursor_position = nullseat_get_cursor_position,
};
static Seat plink_seat[1] = {{ &plink_seat_vt }};

View File

@ -427,24 +427,23 @@ static int serial_cfg_info(Backend *be)
return 0;
}
const struct BackendVtable serial_backend = {
serial_init,
serial_free,
serial_reconfig,
serial_send,
serial_sendbuffer,
serial_size,
serial_special,
serial_get_specials,
serial_connected,
serial_exitcode,
serial_sendok,
serial_ldisc,
serial_provide_ldisc,
serial_unthrottle,
serial_cfg_info,
NULL /* test_for_upstream */,
"serial", "Serial",
PROT_SERIAL,
0
const BackendVtable serial_backend = {
.init = serial_init,
.free = serial_free,
.reconfig = serial_reconfig,
.send = serial_send,
.sendbuffer = serial_sendbuffer,
.size = serial_size,
.special = serial_special,
.get_specials = serial_get_specials,
.connected = serial_connected,
.exitcode = serial_exitcode,
.sendok = serial_sendok,
.ldisc_option_state = serial_ldisc,
.provide_ldisc = serial_provide_ldisc,
.unthrottle = serial_unthrottle,
.cfg_info = serial_cfg_info,
.id = "serial",
.displayname = "Serial",
.protocol = PROT_SERIAL,
};