From: Peter Stuge Date: Sun, 21 Oct 2012 18:43:32 +0000 (+0200) Subject: Add struct sr_context to the sr_init() and sr_exit() calls X-Git-Tag: sigrok-cli-0.4.0~69 X-Git-Url: https://sigrok.org/gitweb/?p=sigrok-cli.git;a=commitdiff_plain;h=5acb76821f33f03745e26c91fbb9cc7bcf34512a Add struct sr_context to the sr_init() and sr_exit() calls libsigrok.git commit b8072700c1bc7d13ba004fd897668b56cec4ac62 adds struct sr_context to the public API, and changes sr_init() and sr_exit() to take a struct sr_context ** and struct sr_context * parameter, respectively. struct sr_context is opaque, and all sr_init() and sr_exit() calls must be balanced. Thanks to the new struct sr_context * the error path code flow can also be simplifed, and allow a single point in main() to clean up after any possible program state. --- diff --git a/sigrok-cli.c b/sigrok-cli.c index 2f6c59d..a626636 100644 --- a/sigrok-cli.c +++ b/sigrok-cli.c @@ -1478,6 +1478,7 @@ int main(int argc, char **argv) int ret = 1; GOptionContext *context; GError *error; + struct sr_context *sr_ctx = NULL; g_log_set_default_handler(logger, NULL); @@ -1487,19 +1488,19 @@ int main(int argc, char **argv) if (!g_option_context_parse(context, &argc, &argv, &error)) { g_critical("%s", error->message); - goto done_noexit; + goto done; } /* Set the loglevel (amount of messages to output) for libsigrok. */ if (sr_log_loglevel_set(opt_loglevel) != SR_OK) - goto done_noexit; + goto done; /* Set the loglevel (amount of messages to output) for libsigrokdecode. */ if (srd_log_loglevel_set(opt_loglevel) != SRD_OK) - goto done_noexit; + goto done; - if (sr_init() != SR_OK) - goto done_noexit; + if (sr_init(&sr_ctx) != SR_OK) + goto done; if (opt_pds) { if (srd_init(NULL) != SRD_OK) @@ -1539,9 +1540,9 @@ int main(int argc, char **argv) ret = 0; done: - sr_exit(); + if (sr_ctx) + sr_exit(sr_ctx); -done_noexit: g_option_context_free(context); return ret;