From: Bert Vermeulen Date: Fri, 15 Aug 2014 21:31:20 +0000 (+0200) Subject: input: Actually return a NULL-terminated array. X-Git-Tag: libsigrok-0.4.0~1112 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=bd0bfaafd863ef1eb0cd7d1711c28d66bca3359b;p=libsigrok.git input: Actually return a NULL-terminated array. --- diff --git a/include/libsigrok/proto.h b/include/libsigrok/proto.h index 5ca98d40..c99d4c65 100644 --- a/include/libsigrok/proto.h +++ b/include/libsigrok/proto.h @@ -129,8 +129,8 @@ SR_API const char *sr_input_id_get(const struct sr_input_module *in); SR_API const char *sr_input_name_get(const struct sr_input_module *in); SR_API const char *sr_input_description_get(const struct sr_input_module *in); SR_API const struct sr_input_module *sr_input_find(char *id); -SR_API const struct sr_option *sr_input_options_get(const struct sr_input_module *in); -SR_API void sr_input_options_free(const struct sr_input_module *in); +SR_API const struct sr_option **sr_input_options_get(const struct sr_input_module *in); +SR_API void sr_input_options_free(const struct sr_option **options); SR_API struct sr_input *sr_input_new(const struct sr_input_module *imod, GHashTable *options); SR_API const struct sr_input *sr_input_scan_buffer(GString *buf); diff --git a/src/input/input.c b/src/input/input.c index c7855434..46bff0e3 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -157,29 +157,41 @@ SR_API const struct sr_input_module *sr_input_find(char *id) * * @since 0.4.0 */ -SR_API const struct sr_option *sr_input_options_get(const struct sr_input_module *o) +SR_API const struct sr_option **sr_input_options_get(const struct sr_input_module *imod) { + const struct sr_option *mod_opts, **opts; + int size, i; - if (!o || !o->options) + if (!imod || !imod->options) return NULL; - return o->options(); + mod_opts = imod->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_input_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_input_options_free(const struct sr_input_module *o) +SR_API void sr_input_options_free(const struct sr_option **options) { struct sr_option *opt; - if (!o || !o->options) + if (!options) return; - for (opt = o->options(); opt->id; opt++) { + for (opt = (struct sr_option *)options[0]; opt; opt++) { if (opt->def) { g_variant_unref(opt->def); opt->def = NULL; @@ -190,6 +202,7 @@ SR_API void sr_input_options_free(const struct sr_input_module *o) opt->values = NULL; } } + g_free(options); } /**