From: Bert Vermeulen Date: Fri, 15 Aug 2014 18:16:31 +0000 (+0200) Subject: output: Actually return a NULL-terminated array. X-Git-Tag: libsigrok-0.4.0~1148 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=fc74643098877824b7a3cf16cc24de624b191615;p=libsigrok.git output: Actually return a NULL-terminated array. This returned an array of structs with an NULL-ed element at the end. The drivers still do this, but the wrappers now make and free a NULL- terminated array around it. sr_output_options_free() now takes the pointer returned by sr_output_options_get(), instead of the module owning it. --- diff --git a/include/libsigrok/proto.h b/include/libsigrok/proto.h index edcd4c97..a159baed 100644 --- a/include/libsigrok/proto.h +++ b/include/libsigrok/proto.h @@ -133,8 +133,8 @@ SR_API const char *sr_output_id_get(const struct sr_output_module *o); SR_API const char *sr_output_name_get(const struct sr_output_module *o); SR_API const char *sr_output_description_get(const struct sr_output_module *o); SR_API const struct sr_output_module *sr_output_find(char *id); -SR_API const struct sr_option *sr_output_options_get(const struct sr_output_module *o); -SR_API void sr_output_options_free(const struct sr_output_module *o); +SR_API const struct sr_option **sr_output_options_get(const struct sr_output_module *o); +SR_API void sr_output_options_free(const struct sr_option **opts); SR_API const struct sr_output *sr_output_new(const struct sr_output_module *o, GHashTable *params, const struct sr_dev_inst *sdi); SR_API int sr_output_send(const struct sr_output *o, diff --git a/src/output/output.c b/src/output/output.c index 3e432c9f..0dd1fe27 100644 --- a/src/output/output.c +++ b/src/output/output.c @@ -160,29 +160,41 @@ SR_API const struct sr_output_module *sr_output_find(char *id) * * @since 0.4.0 */ -SR_API const struct sr_option *sr_output_options_get(const struct sr_output_module *o) +SR_API const struct sr_option **sr_output_options_get(const struct sr_output_module *o) { + const struct sr_option *mod_opts, **opts; + int size, i; if (!o || !o->options) return NULL; - return o->options(); + mod_opts = o->options(); + + for (size = 1; mod_opts[size].id; size++) + ; + opts = g_malloc(size * sizeof(struct sr_option *)); + + for (i = 0; i < size; i++) + opts[i] = &mod_opts[i]; + opts[i] = NULL; + + return opts; } /** * After a call to sr_output_options_get(), this function cleans up all - * resources allocated by that call. + * resources returned by that call. * * @since 0.4.0 */ -SR_API void sr_output_options_free(const struct sr_output_module *o) +SR_API void sr_output_options_free(const struct sr_option **opts) { struct sr_option *opt; - if (!o || !o->options) + if (!opts) return; - for (opt = o->options(); opt->id; opt++) { + for (opt = (struct sr_option *)opts[0]; opt; opt++) { if (opt->def) { g_variant_unref(opt->def); opt->def = NULL; @@ -193,6 +205,7 @@ SR_API void sr_output_options_free(const struct sr_output_module *o) opt->values = NULL; } } + g_free(opts); } /**