diff options
author | Nicholas Marriott <nicm@openbsd.org> | 2013-03-22 15:49:55 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@openbsd.org> | 2013-03-22 15:49:55 +0000 |
commit | d1e6ce26722e3a0774d240e39bbc69b07e93c48b (patch) | |
tree | 4ac0c275feab5c23da70c25dbc62a605208a45e5 /cmd.c | |
parent | 29613f2f31117ed898455fdf75dd7b69d18129f3 (diff) |
Add functions to allocate and free command contexts rather than doing it
all on the stack.
Diffstat (limited to 'cmd.c')
-rw-r--r-- | cmd.c | 46 |
1 files changed, 33 insertions, 13 deletions
@@ -133,6 +133,39 @@ struct winlink *cmd_find_window_offset(const char *, struct session *, int *); int cmd_find_index_offset(const char *, struct session *, int *); struct window_pane *cmd_find_pane_offset(const char *, struct winlink *); +struct cmd_ctx * +cmd_get_ctx(void) +{ + struct cmd_ctx *ctx; + + ctx = xcalloc(1, sizeof *ctx); + ctx->references = 0; + + cmd_ref_ctx(ctx); + return (ctx); +} + +void +cmd_free_ctx(struct cmd_ctx *ctx) +{ + if (ctx->cmdclient != NULL) + ctx->cmdclient->references--; + if (ctx->curclient != NULL) + ctx->curclient->references--; + if (--ctx->references == 0) + free(ctx); +} + +void +cmd_ref_ctx(struct cmd_ctx *ctx) +{ + ctx->references++; + if (ctx->cmdclient != NULL) + ctx->cmdclient->references++; + if (ctx->curclient != NULL) + ctx->curclient->references++; +} + int cmd_pack_argv(int argc, char **argv, char *buf, size_t len) { @@ -282,19 +315,6 @@ usage: return (NULL); } -enum cmd_retval -cmd_exec(struct cmd *cmd, struct cmd_ctx *ctx) -{ - return (cmd->entry->exec(cmd, ctx)); -} - -void -cmd_free(struct cmd *cmd) -{ - args_free(cmd->args); - free(cmd); -} - size_t cmd_print(struct cmd *cmd, char *buf, size_t len) { |