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:
43
pageant.c
43
pageant.c
@ -442,9 +442,9 @@ static void signop_coroutine(PageantAsyncOp *pao)
|
||||
crFinishFreedV;
|
||||
}
|
||||
|
||||
static struct PageantAsyncOpVtable signop_vtable = {
|
||||
signop_coroutine,
|
||||
signop_free,
|
||||
static const PageantAsyncOpVtable signop_vtable = {
|
||||
.coroutine = signop_coroutine,
|
||||
.free = signop_free,
|
||||
};
|
||||
|
||||
static void fail_requests_for_key(PageantKey *pk, const char *reason)
|
||||
@ -572,9 +572,9 @@ static void immop_coroutine(PageantAsyncOp *pao)
|
||||
crFinishFreedV;
|
||||
}
|
||||
|
||||
static struct PageantAsyncOpVtable immop_vtable = {
|
||||
immop_coroutine,
|
||||
immop_free,
|
||||
static const PageantAsyncOpVtable immop_vtable = {
|
||||
.coroutine = immop_coroutine,
|
||||
.free = immop_free,
|
||||
};
|
||||
|
||||
static bool reencrypt_key(PageantKey *pk)
|
||||
@ -1482,10 +1482,10 @@ static bool pageant_conn_ask_passphrase(
|
||||
return pageant_listener_client_ask_passphrase(pcs->plc, dlgid, msg);
|
||||
}
|
||||
|
||||
static const struct PageantClientVtable pageant_connection_clientvt = {
|
||||
pageant_conn_log,
|
||||
pageant_conn_got_response,
|
||||
pageant_conn_ask_passphrase,
|
||||
static const PageantClientVtable pageant_connection_clientvt = {
|
||||
.log = pageant_conn_log,
|
||||
.got_response = pageant_conn_got_response,
|
||||
.ask_passphrase = pageant_conn_ask_passphrase,
|
||||
};
|
||||
|
||||
static void pageant_conn_receive(
|
||||
@ -1569,11 +1569,9 @@ static void pageant_listen_closing(Plug *plug, const char *error_msg,
|
||||
}
|
||||
|
||||
static const PlugVtable pageant_connection_plugvt = {
|
||||
NULL, /* no log function, because that's for outgoing connections */
|
||||
pageant_conn_closing,
|
||||
pageant_conn_receive,
|
||||
pageant_conn_sent,
|
||||
NULL /* no accepting function, because we've already done it */
|
||||
.closing = pageant_conn_closing,
|
||||
.receive = pageant_conn_receive,
|
||||
.sent = pageant_conn_sent,
|
||||
};
|
||||
|
||||
static int pageant_listen_accepting(Plug *plug,
|
||||
@ -1620,11 +1618,8 @@ static int pageant_listen_accepting(Plug *plug,
|
||||
}
|
||||
|
||||
static const PlugVtable pageant_listener_plugvt = {
|
||||
NULL, /* no log function, because that's for outgoing connections */
|
||||
pageant_listen_closing,
|
||||
NULL, /* no receive function on a listening socket */
|
||||
NULL, /* no sent function on a listening socket */
|
||||
pageant_listen_accepting
|
||||
.closing = pageant_listen_closing,
|
||||
.accepting = pageant_listen_accepting,
|
||||
};
|
||||
|
||||
struct pageant_listen_state *pageant_listener_new(
|
||||
@ -1680,10 +1675,10 @@ static bool internal_client_ask_passphrase(
|
||||
return false;
|
||||
}
|
||||
|
||||
static const struct PageantClientVtable internal_clientvt = {
|
||||
NULL /* log */,
|
||||
internal_client_got_response,
|
||||
internal_client_ask_passphrase,
|
||||
static const PageantClientVtable internal_clientvt = {
|
||||
.log = NULL,
|
||||
.got_response = internal_client_got_response,
|
||||
.ask_passphrase = internal_client_ask_passphrase,
|
||||
};
|
||||
|
||||
typedef struct PageantClientOp {
|
||||
|
Reference in New Issue
Block a user