From: Gerhard Sittig Date: Sun, 3 Jun 2018 08:31:17 +0000 (+0200) Subject: input/logicport: don't re-create channels after input module reset X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=4c40d096d4cde1b0538dea216e50846a14f33aaa;p=libsigrok.git input/logicport: don't re-create channels after input module reset Split the creation of channels and groups as well as the creation of the session feed buffer into separate routines. Re-allocate the buffer after reset but do not re-create the channels and groups. This implementation assumes that after reset() of the input module, the very same set of channels (including their order, names and enabled state, as well as group membership) results from processing the subsequently fed file content. Reading rather different configurations from the same input file by means of repeated reset and re-read may not work as expected. --- diff --git a/src/input/logicport.c b/src/input/logicport.c index e165cb04..01173530 100644 --- a/src/input/logicport.c +++ b/src/input/logicport.c @@ -767,8 +767,8 @@ static int parse_header(struct sr_input *in) return SR_OK; } -/* Create sigrok channels and groups. Allocate the session feed buffer. */ -static int create_channels_groups_buffer(struct sr_input *in) +/* Create sigrok channels and groups. */ +static int create_channels_groups(struct sr_input *in) { struct context *inc; uint64_t mask; @@ -783,6 +783,9 @@ static int create_channels_groups_buffer(struct sr_input *in) inc = in->priv; + if (inc->channels) + return SR_OK; + mask = UINT64_C(1); for (idx = 0; idx < inc->channel_count; idx++, mask <<= 1) { name = inc->signal_names[idx]; @@ -814,6 +817,16 @@ static int create_channels_groups_buffer(struct sr_input *in) } } + return SR_OK; +} + +/* Allocate the session feed buffer. */ +static int create_feed_buffer(struct sr_input *in) +{ + struct context *inc; + + inc = in->priv; + inc->unitsize = (inc->channel_count + 7) / 8; inc->samples_per_chunk = CHUNK_SIZE / inc->unitsize; inc->samples_in_buffer = 0; @@ -1004,7 +1017,10 @@ static int prepare_session_feed(struct sr_input *in) * header to the session. Optionally send the sample * rate before sample data will be sent. */ - rc = create_channels_groups_buffer(in); + rc = create_channels_groups(in); + if (rc) + return rc; + rc = create_feed_buffer(in); if (rc) return rc; @@ -1149,9 +1165,21 @@ static void cleanup(struct sr_input *in) static int reset(struct sr_input *in) { struct context *inc; + GSList *channels; inc = in->priv; + + /* + * The input module's .reset() routine clears the 'inc' context, + * but 'in' is kept which contains channel groups which reference + * channels. Since we cannot re-create the channels (applications + * don't expect us to, see bug #1215), make sure to keep the + * channels across the reset operation. + */ + channels = inc->channels; + inc->channels = NULL; cleanup(in); + inc->channels = channels; inc->ch_feed_prep = FALSE; inc->header_sent = FALSE; inc->rate_sent = FALSE;