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

Refactor 'struct context *ctx = &actx' pattern.

When I'm declaring a local instance of some context structure type to
pass to a function which will pass it in turn to a callback, I've
tended to use a declaration of the form

    struct context actx, *ctx = &actx;

so that the outermost caller can initialise the context, and/or read
out fields of it afterwards, by the same syntax 'ctx->foo' that the
callback function will be using. So you get visual consistency between
the two functions that share this context.

It only just occurred to me that there's a much neater way to declare
a context struct of this kind, which still makes 'ctx' behave like a
pointer in the owning function, and doesn't need all that weird
verbiage or a spare variable name:

    struct context ctx[1];

That's much nicer! I've switched to doing that in all existing cases I
could find, and also in a couple of cases where I hadn't previously
bothered to do the previous more cumbersome idiom.
This commit is contained in:
Simon Tatham
2019-12-22 08:15:52 +00:00
parent 421a8ca5d9
commit 5e468129f6
7 changed files with 21 additions and 21 deletions

View File

@ -569,7 +569,7 @@ const bool buildinfo_gtk_relevant = true;
char *gtk_askpass_main(const char *display, const char *wintitle,
const char *prompt, bool *success)
{
struct askpass_ctx actx, *ctx = &actx;
struct askpass_ctx ctx[1];
const char *err;
ctx->passphrase = NULL;

View File

@ -4408,7 +4408,7 @@ static void compute_geom_hints(GtkFrontend *inst, GdkGeometry *geom)
* ourselves.
*/
{
struct find_app_menu_bar_ctx actx, *ctx = &actx;
struct find_app_menu_bar_ctx ctx[1];
ctx->area = inst->area;
ctx->menubar = NULL;
gtk_container_foreach(GTK_CONTAINER(inst->window),

View File

@ -498,7 +498,7 @@ void key_find_callback(void *vctx, const char *fingerprint,
struct pageant_pubkey *find_key(const char *string, char **retstr)
{
struct key_find_ctx actx, *ctx = &actx;
struct key_find_ctx ctx[1];
struct pageant_pubkey key_in, *key_ret;
bool try_file = true, try_fp = true, try_comment = true;
bool file_errors = false;