mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 09:27:59 +00: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:
parent
421a8ca5d9
commit
5e468129f6
4
psftp.c
4
psftp.c
@ -1588,7 +1588,7 @@ static bool sftp_action_mv(void *vctx, char *srcfname)
|
||||
|
||||
int sftp_cmd_mv(struct sftp_command *cmd)
|
||||
{
|
||||
struct sftp_context_mv actx, *ctx = &actx;
|
||||
struct sftp_context_mv ctx[1];
|
||||
int i, ret;
|
||||
|
||||
if (!backend) {
|
||||
@ -1677,7 +1677,7 @@ int sftp_cmd_chmod(struct sftp_command *cmd)
|
||||
{
|
||||
char *mode;
|
||||
int i, ret;
|
||||
struct sftp_context_chmod actx, *ctx = &actx;
|
||||
struct sftp_context_chmod ctx[1];
|
||||
|
||||
if (!backend) {
|
||||
not_connected();
|
||||
|
14
ssh.c
14
ssh.c
@ -1052,21 +1052,21 @@ static const SessionSpecial *ssh_get_specials(Backend *be)
|
||||
* and amalgamate the list into one combined one.
|
||||
*/
|
||||
|
||||
struct ssh_add_special_ctx ctx;
|
||||
struct ssh_add_special_ctx ctx[1];
|
||||
|
||||
ctx.specials = NULL;
|
||||
ctx.nspecials = ctx.specials_size = 0;
|
||||
ctx->specials = NULL;
|
||||
ctx->nspecials = ctx->specials_size = 0;
|
||||
|
||||
if (ssh->base_layer)
|
||||
ssh_ppl_get_specials(ssh->base_layer, ssh_add_special, &ctx);
|
||||
ssh_ppl_get_specials(ssh->base_layer, ssh_add_special, ctx);
|
||||
|
||||
if (ctx.specials) {
|
||||
if (ctx->specials) {
|
||||
/* If the list is non-empty, terminate it with a SS_EXITMENU. */
|
||||
ssh_add_special(&ctx, NULL, SS_EXITMENU, 0);
|
||||
ssh_add_special(ctx, NULL, SS_EXITMENU, 0);
|
||||
}
|
||||
|
||||
sfree(ssh->specials);
|
||||
ssh->specials = ctx.specials;
|
||||
ssh->specials = ctx->specials;
|
||||
return ssh->specials;
|
||||
}
|
||||
|
||||
|
16
tree234.c
16
tree234.c
@ -1211,12 +1211,12 @@ int chknode(chkctx * ctx, int level, node234 * node,
|
||||
|
||||
void verify(void)
|
||||
{
|
||||
chkctx ctx;
|
||||
chkctx ctx[1];
|
||||
int i;
|
||||
void *p;
|
||||
|
||||
ctx.treedepth = -1; /* depth unknown yet */
|
||||
ctx.elemcount = 0; /* no elements seen yet */
|
||||
ctx->treedepth = -1; /* depth unknown yet */
|
||||
ctx->elemcount = 0; /* no elements seen yet */
|
||||
/*
|
||||
* Verify validity of tree properties.
|
||||
*/
|
||||
@ -1225,7 +1225,7 @@ void verify(void)
|
||||
error("root->parent is %p should be null", tree->root->parent);
|
||||
chknode(&ctx, 0, tree->root, NULL, NULL);
|
||||
}
|
||||
printf("tree depth: %d\n", ctx.treedepth);
|
||||
printf("tree depth: %d\n", ctx->treedepth);
|
||||
/*
|
||||
* Enumerate the tree and ensure it matches up to the array.
|
||||
*/
|
||||
@ -1236,17 +1236,17 @@ void verify(void)
|
||||
error("enum at position %d: array says %s, tree says %s",
|
||||
i, array[i], p);
|
||||
}
|
||||
if (ctx.elemcount != i) {
|
||||
if (ctx->elemcount != i) {
|
||||
error("tree really contains %d elements, enum gave %d",
|
||||
ctx.elemcount, i);
|
||||
ctx->elemcount, i);
|
||||
}
|
||||
if (i < arraylen) {
|
||||
error("enum gave only %d elements, array has %d", i, arraylen);
|
||||
}
|
||||
i = count234(tree);
|
||||
if (ctx.elemcount != i) {
|
||||
if (ctx->elemcount != i) {
|
||||
error("tree really contains %d elements, count234 gave %d",
|
||||
ctx.elemcount, i);
|
||||
ctx->elemcount, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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),
|
||||
|
@ -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;
|
||||
|
@ -705,7 +705,7 @@ static DWORD WINAPI command_read_thread(void *param)
|
||||
char *ssh_sftp_get_cmdline(const char *prompt, bool no_fds_ok)
|
||||
{
|
||||
int ret;
|
||||
struct command_read_ctx actx, *ctx = &actx;
|
||||
struct command_read_ctx ctx[1];
|
||||
DWORD threadid;
|
||||
HANDLE hThread;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user