From bf53457d1ddea58d1cb7e4feea83ad0cc1d63031 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Thu, 13 Dec 2012 21:07:53 +0000 Subject: [PATCH] Pass sr_datafeed_packets and payloads with const pointers This patch marks packet structures and their payloads as const. This indicates to packet receivers that modifications to these are not allowed. In general all pointers should be marked const unless modification of the referenced data is explicitly allowed. --- libsigrok-internal.h | 2 +- libsigrok.h | 4 ++-- output/analog.c | 8 ++++---- proto.h | 2 +- session.c | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libsigrok-internal.h b/libsigrok-internal.h index 0dfbbe8a..e63ea930 100644 --- a/libsigrok-internal.h +++ b/libsigrok-internal.h @@ -122,7 +122,7 @@ SR_PRIV int sr_source_add(int fd, int events, int timeout, /*--- session.c -------------------------------------------------------------*/ SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi, - struct sr_datafeed_packet *packet); + const struct sr_datafeed_packet *packet); /*--- hardware/common/serial.c ----------------------------------------------*/ diff --git a/libsigrok.h b/libsigrok.h index 9946691e..f371c944 100644 --- a/libsigrok.h +++ b/libsigrok.h @@ -268,7 +268,7 @@ struct sr_context; struct sr_datafeed_packet { uint16_t type; - void *payload; + const void *payload; }; struct sr_datafeed_header { @@ -336,7 +336,7 @@ struct sr_output_format { int (*event) (struct sr_output *o, int event_type, uint8_t **data_out, uint64_t *length_out); GString *(*recv) (struct sr_output *o, const struct sr_dev_inst *sdi, - struct sr_datafeed_packet *packet); + const struct sr_datafeed_packet *packet); int (*cleanup) (struct sr_output *o); }; diff --git a/output/analog.c b/output/analog.c index 448b112e..d2f28b6b 100644 --- a/output/analog.c +++ b/output/analog.c @@ -189,11 +189,11 @@ static void fancyprint(int unit, int mqflags, float value, GString *out) } static GString *receive(struct sr_output *o, const struct sr_dev_inst *sdi, - struct sr_datafeed_packet *packet) + const struct sr_datafeed_packet *packet) { - struct sr_datafeed_analog *analog; + const struct sr_datafeed_analog *analog; struct context *ctx; - float *fdata; + const float *fdata; int i, j; (void)sdi; @@ -214,7 +214,7 @@ static GString *receive(struct sr_output *o, const struct sr_dev_inst *sdi, break; case SR_DF_ANALOG: analog = packet->payload; - fdata = (float *)analog->data; + fdata = (const float *)analog->data; for (i = 0; i < analog->num_samples; i++) { for (j = 0; j < ctx->num_enabled_probes; j++) { g_string_append_printf(ctx->out, "%s: ", diff --git a/proto.h b/proto.h index c93a796e..870dc985 100644 --- a/proto.h +++ b/proto.h @@ -89,7 +89,7 @@ SR_API const struct sr_hwcap_option *sr_devopt_name_get(const char *optname); /*--- session.c -------------------------------------------------------------*/ typedef void (*sr_datafeed_callback_t)(const struct sr_dev_inst *sdi, - struct sr_datafeed_packet *packet); + const struct sr_datafeed_packet *packet); /* Session setup */ SR_API int sr_session_load(const char *filename); diff --git a/session.c b/session.c index 81e09b11..6a4a3c99 100644 --- a/session.c +++ b/session.c @@ -370,10 +370,10 @@ SR_API int sr_session_stop(void) * * @param packet The packet to show debugging information for. */ -static void datafeed_dump(struct sr_datafeed_packet *packet) +static void datafeed_dump(const struct sr_datafeed_packet *packet) { - struct sr_datafeed_logic *logic; - struct sr_datafeed_analog *analog; + const struct sr_datafeed_logic *logic; + const struct sr_datafeed_analog *analog; switch (packet->type) { case SR_DF_HEADER: @@ -426,7 +426,7 @@ static void datafeed_dump(struct sr_datafeed_packet *packet) * @private */ SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi, - struct sr_datafeed_packet *packet) + const struct sr_datafeed_packet *packet) { GSList *l; sr_datafeed_callback_t cb;