1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 11:32: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

@ -216,18 +216,18 @@ struct x11font {
unifont u;
};
static const struct UnifontVtable x11font_vtable = {
x11font_create,
NULL, /* no fallback fonts in X11 */
x11font_destroy,
x11font_has_glyph,
x11font_draw_text,
x11font_draw_combining,
x11font_enum_fonts,
x11font_canonify_fontname,
x11font_scale_fontname,
x11font_size_increment,
"server",
static const UnifontVtable x11font_vtable = {
.create = x11font_create,
.create_fallback = NULL, /* no fallback fonts in X11 */
.destroy = x11font_destroy,
.has_glyph = x11font_has_glyph,
.draw_text = x11font_draw_text,
.draw_combining = x11font_draw_combining,
.enum_fonts = x11font_enum_fonts,
.canonify_fontname = x11font_canonify_fontname,
.scale_fontname = x11font_scale_fontname,
.size_increment = x11font_size_increment,
.prefix = "server",
};
#define XLFD_STRING_PARTS_LIST(S,I) \
@ -1353,18 +1353,18 @@ struct pangofont {
struct unifont u;
};
static const struct UnifontVtable pangofont_vtable = {
pangofont_create,
pangofont_create_fallback,
pangofont_destroy,
pangofont_has_glyph,
pangofont_draw_text,
pangofont_draw_combining,
pangofont_enum_fonts,
pangofont_canonify_fontname,
pangofont_scale_fontname,
pangofont_size_increment,
"client",
static const UnifontVtable pangofont_vtable = {
.create = pangofont_create,
.create_fallback = pangofont_create_fallback,
.destroy = pangofont_destroy,
.has_glyph = pangofont_has_glyph,
.draw_text = pangofont_draw_text,
.draw_combining = pangofont_draw_combining,
.enum_fonts = pangofont_enum_fonts,
.canonify_fontname = pangofont_canonify_fontname,
.scale_fontname = pangofont_scale_fontname,
.size_increment = pangofont_size_increment,
.prefix = "client",
};
/*
@ -2190,18 +2190,18 @@ struct multifont {
struct unifont u;
};
static const struct UnifontVtable multifont_vtable = {
NULL, /* creation is done specially */
NULL,
multifont_destroy,
NULL,
multifont_draw_text,
multifont_draw_combining,
NULL,
NULL,
NULL,
multifont_size_increment,
"client",
static const UnifontVtable multifont_vtable = {
.create = NULL, /* creation is done specially */
.create_fallback = NULL,
.destroy = multifont_destroy,
.has_glyph = NULL,
.draw_text = multifont_draw_text,
.draw_combining = multifont_draw_combining,
.enum_fonts = NULL,
.canonify_fontname = NULL,
.scale_fontname = NULL,
.size_increment = multifont_size_increment,
.prefix = "client",
};
unifont *multifont_create(GtkWidget *widget, const char *name,

View File

@ -49,7 +49,8 @@
/*
* Exports from gtkfont.c.
*/
struct UnifontVtable; /* contents internal to gtkfont.c */
typedef struct UnifontVtable UnifontVtable; /* contents internal to
* gtkfont.c */
typedef struct unifont {
const struct UnifontVtable *vt;
/*

View File

@ -376,31 +376,31 @@ static bool gtk_seat_set_trust_status(Seat *seat, bool trusted);
static bool gtk_seat_get_cursor_position(Seat *seat, int *x, int *y);
static const SeatVtable gtk_seat_vt = {
gtk_seat_output,
gtk_seat_eof,
gtk_seat_get_userpass_input,
gtk_seat_notify_remote_exit,
gtk_seat_connection_fatal,
gtk_seat_update_specials_menu,
gtk_seat_get_ttymode,
gtk_seat_set_busy_status,
gtk_seat_verify_ssh_host_key,
gtk_seat_confirm_weak_crypto_primitive,
gtk_seat_confirm_weak_cached_hostkey,
gtk_seat_is_utf8,
nullseat_echoedit_update,
gtk_seat_get_x_display,
.output = gtk_seat_output,
.eof = gtk_seat_eof,
.get_userpass_input = gtk_seat_get_userpass_input,
.notify_remote_exit = gtk_seat_notify_remote_exit,
.connection_fatal = gtk_seat_connection_fatal,
.update_specials_menu = gtk_seat_update_specials_menu,
.get_ttymode = gtk_seat_get_ttymode,
.set_busy_status = gtk_seat_set_busy_status,
.verify_ssh_host_key = gtk_seat_verify_ssh_host_key,
.confirm_weak_crypto_primitive = gtk_seat_confirm_weak_crypto_primitive,
.confirm_weak_cached_hostkey = gtk_seat_confirm_weak_cached_hostkey,
.is_utf8 = gtk_seat_is_utf8,
.echoedit_update = nullseat_echoedit_update,
.get_x_display = gtk_seat_get_x_display,
#ifdef NOT_X_WINDOWS
nullseat_get_windowid,
.get_windowid = nullseat_get_windowid,
#else
gtk_seat_get_windowid,
.get_windowid = gtk_seat_get_windowid,
#endif
gtk_seat_get_window_pixel_size,
gtk_seat_stripctrl_new,
gtk_seat_set_trust_status,
nullseat_verbose_yes,
nullseat_interactive_yes,
gtk_seat_get_cursor_position,
.get_window_pixel_size = gtk_seat_get_window_pixel_size,
.stripctrl_new = gtk_seat_stripctrl_new,
.set_trust_status = gtk_seat_set_trust_status,
.verbose = nullseat_verbose_yes,
.interactive = nullseat_interactive_yes,
.get_cursor_position = gtk_seat_get_cursor_position,
};
static void gtk_eventlog(LogPolicy *lp, const char *string)
@ -427,10 +427,10 @@ static void gtk_logging_error(LogPolicy *lp, const char *event)
}
static const LogPolicyVtable gtk_logpolicy_vt = {
gtk_eventlog,
gtk_askappend,
gtk_logging_error,
null_lp_verbose_yes,
.eventlog = gtk_eventlog,
.askappend = gtk_askappend,
.logging_error = gtk_logging_error,
.verbose = null_lp_verbose_yes,
};
/*
@ -5152,34 +5152,34 @@ static void get_monitor_geometry(GtkWidget *widget, GdkRectangle *geometry)
#endif
static const TermWinVtable gtk_termwin_vt = {
gtkwin_setup_draw_ctx,
gtkwin_draw_text,
gtkwin_draw_cursor,
gtkwin_draw_trust_sigil,
gtkwin_char_width,
gtkwin_free_draw_ctx,
gtkwin_set_cursor_pos,
gtkwin_set_raw_mouse_mode,
gtkwin_set_scrollbar,
gtkwin_bell,
gtkwin_clip_write,
gtkwin_clip_request_paste,
gtkwin_refresh,
gtkwin_request_resize,
gtkwin_set_title,
gtkwin_set_icon_title,
gtkwin_set_minimised,
gtkwin_is_minimised,
gtkwin_set_maximised,
gtkwin_move,
gtkwin_set_zorder,
gtkwin_palette_get,
gtkwin_palette_set,
gtkwin_palette_reset,
gtkwin_get_pos,
gtkwin_get_pixels,
gtkwin_get_title,
gtkwin_is_utf8,
.setup_draw_ctx = gtkwin_setup_draw_ctx,
.draw_text = gtkwin_draw_text,
.draw_cursor = gtkwin_draw_cursor,
.draw_trust_sigil = gtkwin_draw_trust_sigil,
.char_width = gtkwin_char_width,
.free_draw_ctx = gtkwin_free_draw_ctx,
.set_cursor_pos = gtkwin_set_cursor_pos,
.set_raw_mouse_mode = gtkwin_set_raw_mouse_mode,
.set_scrollbar = gtkwin_set_scrollbar,
.bell = gtkwin_bell,
.clip_write = gtkwin_clip_write,
.clip_request_paste = gtkwin_clip_request_paste,
.refresh = gtkwin_refresh,
.request_resize = gtkwin_request_resize,
.set_title = gtkwin_set_title,
.set_icon_title = gtkwin_set_icon_title,
.set_minimised = gtkwin_set_minimised,
.is_minimised = gtkwin_is_minimised,
.set_maximised = gtkwin_set_maximised,
.move = gtkwin_move,
.set_zorder = gtkwin_set_zorder,
.palette_get = gtkwin_palette_get,
.palette_set = gtkwin_palette_set,
.palette_reset = gtkwin_palette_reset,
.get_pos = gtkwin_get_pos,
.get_pixels = gtkwin_get_pixels,
.get_title = gtkwin_get_title,
.is_utf8 = gtkwin_is_utf8,
};
void new_session_window(Conf *conf, const char *geometry_string)

View File

@ -304,14 +304,14 @@ static void fdsocket_select_result_input_error(int fd, int event)
}
static const SocketVtable FdSocket_sockvt = {
fdsocket_plug,
fdsocket_close,
fdsocket_write,
fdsocket_write_oob,
fdsocket_write_eof,
fdsocket_set_frozen,
fdsocket_socket_error,
NULL, /* peer_info */
.plug = fdsocket_plug,
.close = fdsocket_close,
.write = fdsocket_write,
.write_oob = fdsocket_write_oob,
.write_eof = fdsocket_write_eof,
.set_frozen = fdsocket_set_frozen,
.socket_error = fdsocket_socket_error,
.peer_info = NULL,
};
Socket *make_fd_socket(int infd, int outfd, int inerrfd, Plug *plug)

View File

@ -505,15 +505,15 @@ static void sk_net_set_frozen(Socket *s, bool is_frozen);
static SocketPeerInfo *sk_net_peer_info(Socket *s);
static const char *sk_net_socket_error(Socket *s);
static struct 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,
static const SocketVtable NetSocket_sockvt = {
.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

@ -150,8 +150,8 @@ static void passphrase_done(struct uxpgnt_client *upc, bool success)
}
static const PageantListenerClientVtable uxpgnt_vtable = {
uxpgnt_log,
uxpgnt_ask_passphrase,
.log = uxpgnt_log,
.ask_passphrase = uxpgnt_ask_passphrase,
};
/*
@ -916,11 +916,10 @@ void run_client(void)
}
static const PlugVtable X11Connection_plugvt = {
x11_log,
x11_closing,
x11_receive,
x11_sent,
NULL
.log = x11_log,
.closing = x11_closing,
.receive = x11_receive,
.sent = x11_sent,
};

View File

@ -387,27 +387,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,
plink_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 = plink_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

@ -123,10 +123,10 @@ static int server_askappend(
}
static const LogPolicyVtable server_logpolicy_vt = {
server_eventlog,
server_askappend,
server_logging_error,
null_lp_verbose_no,
.eventlog = server_eventlog,
.askappend = server_askappend,
.logging_error = server_logging_error,
.verbose = null_lp_verbose_no,
};
static void show_help(FILE *fp)

View File

@ -1585,24 +1585,23 @@ static int pty_cfg_info(Backend *be)
return 0;
}
const struct BackendVtable pty_backend = {
pty_init,
pty_free,
pty_reconfig,
pty_send,
pty_sendbuffer,
pty_size,
pty_special,
pty_get_specials,
pty_connected,
pty_exitcode,
pty_sendok,
pty_ldisc,
pty_provide_ldisc,
pty_unthrottle,
pty_cfg_info,
NULL /* test_for_upstream */,
"pty", "pty",
-1,
0
const BackendVtable pty_backend = {
.init = pty_init,
.free = pty_free,
.reconfig = pty_reconfig,
.send = pty_send,
.sendbuffer = pty_sendbuffer,
.size = pty_size,
.special = pty_special,
.get_specials = pty_get_specials,
.connected = pty_connected,
.exitcode = pty_exitcode,
.sendok = pty_sendok,
.ldisc_option_state = pty_ldisc,
.provide_ldisc = pty_provide_ldisc,
.unthrottle = pty_unthrottle,
.cfg_info = pty_cfg_info,
.id = "pty",
.displayname = "pty",
.protocol = -1,
};

View File

@ -559,24 +559,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,
};

View File

@ -153,10 +153,10 @@ static int server_askappend(
}
static const LogPolicyVtable server_logpolicy_vt = {
server_eventlog,
server_askappend,
server_logging_error,
null_lp_verbose_no,
.eventlog = server_eventlog,
.askappend = server_askappend,
.logging_error = server_logging_error,
.verbose = null_lp_verbose_no,
};
struct AuthPolicy_ssh1_pubkey {
@ -504,11 +504,9 @@ static int server_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx)
}
static const PlugVtable server_plugvt = {
server_log,
server_closing,
NULL, /* recv */
NULL, /* send */
server_accepting
.log = server_log,
.closing = server_closing,
.accepting = server_accepting,
};
int main(int argc, char **argv)

View File

@ -681,22 +681,22 @@ static void uss_readdir(SftpServer *srv, SftpReplyBuilder *reply,
}
}
const struct SftpServerVtable unix_live_sftpserver_vt = {
uss_new,
uss_free,
uss_realpath,
uss_open,
uss_opendir,
uss_close,
uss_mkdir,
uss_rmdir,
uss_remove,
uss_rename,
uss_stat,
uss_fstat,
uss_setstat,
uss_fsetstat,
uss_read,
uss_write,
uss_readdir,
const SftpServerVtable unix_live_sftpserver_vt = {
.new = uss_new,
.free = uss_free,
.realpath = uss_realpath,
.open = uss_open,
.opendir = uss_opendir,
.close = uss_close,
.mkdir = uss_mkdir,
.rmdir = uss_rmdir,
.remove = uss_remove,
.rename = uss_rename,
.stat = uss_stat,
.fstat = uss_fstat,
.setstat = uss_setstat,
.fsetstat = uss_fsetstat,
.read = uss_read,
.write = uss_write,
.readdir = uss_readdir,
};