]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Constify buffer tree API.
authorAndre Noll <maan@tuebingen.mpg.de>
Mon, 2 Jan 2023 13:43:42 +0000 (14:43 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Wed, 8 May 2024 17:45:52 +0000 (19:45 +0200)
A lot of functions of the buffer tree API don't modify the memory
referenced by the pointers passed. This patch marks these pointer
arguments as constant.

12 files changed:
aacdec_filter.c
afh_recv.c
buffer_tree.c
buffer_tree.h
check_wav.c
flacdec_filter.c
mp3dec_filter.c
oggdec_filter.c
opusdec_filter.c
resample_filter.c
spxdec_filter.c
wmadec_filter.c

index 87a7900af3ee9b43e1a661d66cdd54d1625b0952..ab07be8f18f2377f17cddf1668ca02f02cb407c2 100644 (file)
@@ -41,7 +41,8 @@ struct private_aacdec_data {
        unsigned int sample_rate;
 };
 
-static int aacdec_execute(struct btr_node *btrn, const char *cmd, char **result)
+static int aacdec_execute(const struct btr_node *btrn, const char *cmd,
+               char **result)
 {
        struct filter_node *fn = btr_context(btrn);
        struct private_aacdec_data *padd = fn->private_data;
index 8449e787f96fa24b60c2c3af9ec5218eb264ff53..687b77d9ecc385aa433cd90d8e027ffb110c135d 100644 (file)
@@ -30,7 +30,7 @@ struct private_afh_recv_data {
        void *afh_context;
 };
 
-static int afh_execute(struct btr_node *btrn, const char *cmd, char **result)
+static int afh_execute(const struct btr_node *btrn, const char *cmd, char **result)
 {
        struct receiver_node *rn = btr_context(btrn);
        struct private_afh_recv_data *pard = rn->private_data;
index 36a7e6e1804d1094e440b03e6e60e5f3931de777..255dc47531e9d94ebe32046ea85a0ece5be3b888 100644 (file)
@@ -103,12 +103,12 @@ void btr_pool_free(struct btr_pool *btrp)
  * \return The same value which was passed during creation time to
  * btr_pool_new().
  */
-size_t btr_pool_size(struct btr_pool *btrp)
+size_t btr_pool_size(const struct btr_pool *btrp)
 {
        return btrp->area_end - btrp->area_start;
 }
 
-static size_t btr_pool_filled(struct btr_pool *btrp)
+static size_t btr_pool_filled(const struct btr_pool *btrp)
 {
        if (!btrp->whead)
                return btr_pool_size(btrp);
@@ -129,7 +129,7 @@ static size_t btr_pool_filled(struct btr_pool *btrp)
  * the largest contiguous buffer that can currently be allocated from the
  * buffer pool.
  */
-size_t btr_pool_unused(struct btr_pool *btrp)
+size_t btr_pool_unused(const struct btr_pool *btrp)
 {
        return btr_pool_size(btrp) - btr_pool_filled(btrp);
 }
@@ -138,7 +138,7 @@ size_t btr_pool_unused(struct btr_pool *btrp)
  * Return maximal size available for one read. This is
  * smaller than the value returned by btr_pool_unused().
  */
-static size_t btr_pool_available(struct btr_pool *btrp)
+static size_t btr_pool_available(const struct btr_pool *btrp)
 {
        if (!btrp->whead)
                return 0;
@@ -156,7 +156,7 @@ static size_t btr_pool_available(struct btr_pool *btrp)
  * \return The maximal amount of bytes that may be written to the returned
  * buffer.
  */
-size_t btr_pool_get_buffer(struct btr_pool *btrp, char **result)
+size_t btr_pool_get_buffer(const struct btr_pool *btrp, char **result)
 {
        if (result)
                *result = btrp->whead;
@@ -174,7 +174,7 @@ size_t btr_pool_get_buffer(struct btr_pool *btrp, char **result)
  * consists of two buffers. If this function returns the value n, then n
  * elements of \a iov are initialized.
  */
-int btr_pool_get_buffers(struct btr_pool *btrp, struct iovec iov[2])
+int btr_pool_get_buffers(const struct btr_pool *btrp, struct iovec iov[2])
 {
        size_t sz, unused;
        char *buf;
@@ -322,7 +322,7 @@ static void dealloc_buffer(struct btr_buffer *btrb)
                free(btrb->buf);
 }
 
-static struct btr_buffer_reference *get_first_input_br(struct btr_node *btrn)
+static struct btr_buffer_reference *get_first_input_br(const struct btr_node *btrn)
 {
        if (list_empty(&btrn->input_queue))
                return NULL;
@@ -330,7 +330,7 @@ static struct btr_buffer_reference *get_first_input_br(struct btr_node *btrn)
                struct btr_buffer_reference, node);
 }
 
-static struct btr_buffer_reference *get_last_input_br(struct btr_node *btrn)
+static struct btr_buffer_reference *get_last_input_br(const struct btr_node *btrn)
 {
        if (list_empty(&btrn->input_queue))
                return NULL;
@@ -562,7 +562,7 @@ void btr_pushdown_one(struct btr_node *btrn)
  *
  * \return True if this node has no children. False otherwise.
  */
-static bool btr_no_children(struct btr_node *btrn)
+static bool btr_no_children(const struct btr_node *btrn)
 {
        return list_empty(&btrn->children);
 }
@@ -579,7 +579,7 @@ static bool btr_no_children(struct btr_node *btrn)
  * After a (non-leaf) node was removed removed from the tree, the function
  * returns true for all child nodes.
  */
-bool btr_no_parent(struct btr_node *btrn)
+bool btr_no_parent(const struct btr_node *btrn)
 {
        return !btrn->parent;
 }
@@ -602,7 +602,7 @@ bool btr_no_parent(struct btr_node *btrn)
  *
  * \return True if \a btrn has no siblings.
  */
-bool btr_inplace_ok(struct btr_node *btrn)
+bool btr_inplace_ok(const struct btr_node *btrn)
 {
        struct btr_buffer_reference *br;
        FOR_EACH_BUFFER_REF(br, btrn) {
@@ -615,12 +615,13 @@ bool btr_inplace_ok(struct btr_node *btrn)
        return true;
 }
 
-static inline size_t br_available_bytes(struct btr_buffer_reference *br)
+static inline size_t br_available_bytes(const struct btr_buffer_reference *br)
 {
        return br->btrb->size - br->consumed;
 }
 
-static size_t btr_get_buffer_by_reference(struct btr_buffer_reference *br, char **buf)
+static size_t btr_get_buffer_by_reference(const struct btr_buffer_reference *br,
+               char **buf)
 {
        if (buf)
                *buf = br->btrb->buf + br->consumed;
@@ -647,7 +648,8 @@ static size_t btr_get_buffer_by_reference(struct btr_buffer_reference *br, char
  * to by \a btrn, the function returns zero and the value of \a bufp is
  * undefined.
  */
-size_t btr_next_buffer_omit(struct btr_node *btrn, size_t omit, char **bufp)
+size_t btr_next_buffer_omit(const struct btr_node *btrn, size_t omit,
+               char **bufp)
 {
        struct btr_buffer_reference *br;
        size_t wrap_count, sz, rv = 0;
@@ -712,7 +714,7 @@ out:
  * The call of this function is is equivalent to calling \ref
  * btr_next_buffer_omit() with an \a omit value of zero.
  */
-size_t btr_next_buffer(struct btr_node *btrn, char **bufp)
+size_t btr_next_buffer(const struct btr_node *btrn, char **bufp)
 {
        return btr_next_buffer_omit(btrn, 0, bufp);
 }
@@ -844,7 +846,7 @@ out:
  * This simply iterates over all buffer references in the input queue and
  * returns the sum of the sizes of all references.
  */
-size_t btr_get_input_queue_size(struct btr_node *btrn)
+size_t btr_get_input_queue_size(const struct btr_node *btrn)
 {
        struct btr_buffer_reference *br;
        size_t size = 0, wrap_consumed = 0;
@@ -861,7 +863,7 @@ size_t btr_get_input_queue_size(struct btr_node *btrn)
        return size;
 }
 
-static bool min_iqs_available(size_t min_iqs, struct btr_node *btrn)
+static bool min_iqs_available(size_t min_iqs, const struct btr_node *btrn)
 {
        struct btr_buffer_reference *br;
        size_t have = 0, wrap_consumed = 0;
@@ -919,7 +921,7 @@ void btr_splice_out_node(struct btr_node **btrnp)
  * \return This function iterates over all children of the given node and
  * returns the size of the largest input queue.
  */
-size_t btr_get_output_queue_size(struct btr_node *btrn)
+size_t btr_get_output_queue_size(const struct btr_node *btrn)
 {
        size_t max_size = 0;
        struct btr_node *ch;
@@ -947,7 +949,7 @@ size_t btr_get_output_queue_size(struct btr_node *btrn)
  *
  * \sa \ref receiver::execute, \ref filter::execute, \ref writer::execute.
  */
-int btr_exec_up(struct btr_node *btrn, const char *command, char **value_result)
+int btr_exec_up(const struct btr_node *btrn, const char *command, char **value_result)
 {
        int ret;
 
@@ -977,12 +979,12 @@ int btr_exec_up(struct btr_node *btrn, const char *command, char **value_result)
  *
  * \sa \ref btr_new_node(), struct \ref btr_node_description.
  */
-void *btr_context(struct btr_node *btrn)
+void *btr_context(const struct btr_node *btrn)
 {
        return btrn->context;
 }
 
-static bool need_buffer_pool_merge(struct btr_node *btrn)
+static bool need_buffer_pool_merge(const struct btr_node *btrn)
 {
        struct btr_buffer_reference *br = get_first_input_br(btrn);
 
@@ -1157,7 +1159,7 @@ void btr_merge(struct btr_node *btrn, size_t dest_size)
        }
 }
 
-static bool btr_eof(struct btr_node *btrn)
+static bool btr_eof(const struct btr_node *btrn)
 {
        char *buf;
        size_t len = btr_next_buffer(btrn, &buf);
@@ -1165,7 +1167,7 @@ static bool btr_eof(struct btr_node *btrn)
        return (len == 0 && btr_no_parent(btrn));
 }
 
-static void log_tree_recursively(struct btr_node *btrn, int loglevel, int depth)
+static void log_tree_recursively(const struct btr_node *btrn, int loglevel, int depth)
 {
        struct btr_node *ch;
        const char spaces[] = "                 ", *space = spaces + 16 - depth;
@@ -1183,7 +1185,7 @@ static void log_tree_recursively(struct btr_node *btrn, int loglevel, int depth)
  * \param btrn Start logging at this node.
  * \param loglevel Set severity with which the tree should be logged.
  */
-void btr_log_tree(struct btr_node *btrn, int loglevel)
+void btr_log_tree(const struct btr_node *btrn, int loglevel)
 {
        return log_tree_recursively(btrn, loglevel, 0);
 }
@@ -1243,7 +1245,7 @@ struct btr_node *btr_search_node(const char *name, struct btr_node *root)
  * btrn, the function also returns zero in order to bound the memory usage of
  * the buffer tree.
  */
-int btr_node_status(struct btr_node *btrn, size_t min_iqs,
+int btr_node_status(const struct btr_node *btrn, size_t min_iqs,
        enum btr_node_type type)
 {
        if (type != BTR_NT_LEAF && btr_no_children(btrn))
@@ -1268,7 +1270,7 @@ int btr_node_status(struct btr_node *btrn, size_t min_iqs,
  *
  * Mainly useful for the time display of para_audiod.
  */
-void btr_get_node_start(struct btr_node *btrn, struct timeval *tv)
+void btr_get_node_start(const struct btr_node *btrn, struct timeval *tv)
 {
        *tv = btrn->start;
 }
@@ -1283,7 +1285,7 @@ void btr_get_node_start(struct btr_node *btrn, struct timeval *tv)
  * \return The parent of \a btrn, or \p NULL if \a btrn is the
  * root node of the buffer tree.
  */
-struct btr_node *btr_parent(struct btr_node *btrn)
+struct btr_node *btr_parent(const struct btr_node *btrn)
 {
        return btrn->parent;
 }
index 34535219364a6cdc2ce32efcc04ca2d44c2c20c2..5eb3d6e5321602fec854ae585d925e614c8c6a9d 100644 (file)
@@ -131,7 +131,7 @@ enum btr_node_type {
  * know the sample rate of its input known to e.g. the mp3dec node further up
  * in the buffer tree.
  */
-typedef int (*btr_command_handler)(struct btr_node *btrn,
+typedef int (*btr_command_handler)(const struct btr_node *btrn,
                const char *command, char **result);
 
 /**
@@ -166,38 +166,38 @@ struct btr_node_description {
        void *context;
 };
 
-size_t btr_pool_size(struct btr_pool *btrp);
+size_t btr_pool_size(const struct btr_pool *btrp);
 struct btr_pool *btr_pool_new(const char *name, size_t area_size);
 void btr_pool_free(struct btr_pool *btrp);
-size_t btr_pool_get_buffer(struct btr_pool *btrp, char **result);
-int btr_pool_get_buffers(struct btr_pool *btrp, struct iovec iov[2]);
+size_t btr_pool_get_buffer(const struct btr_pool *btrp, char **result);
+int btr_pool_get_buffers(const struct btr_pool *btrp, struct iovec iov[2]);
 void btr_add_output_pool(struct btr_pool *btrp, size_t size,
        struct btr_node *btrn);
-size_t btr_pool_unused(struct btr_pool *btrp);
+size_t btr_pool_unused(const struct btr_pool *btrp);
 void btr_copy(const void *src, size_t n, struct btr_pool *btrp,
        struct btr_node *btrn);
-
 struct btr_node *btr_new_node(struct btr_node_description *bnd);
 void btr_remove_node(struct btr_node **btrnp);
 void btr_add_output(char *buf, size_t size, struct btr_node *btrn);
 void btr_add_output_dont_free(const char *buf, size_t size, struct btr_node *btrn);
-size_t btr_get_input_queue_size(struct btr_node *btrn);
-size_t btr_get_output_queue_size(struct btr_node *btrn);
-bool btr_no_parent(struct btr_node *btrn);
-size_t btr_next_buffer(struct btr_node *btrn, char **bufp);
-size_t btr_next_buffer_omit(struct btr_node *btrn, size_t omit, char **bufp);
+size_t btr_get_input_queue_size(const struct btr_node *btrn);
+size_t btr_get_output_queue_size(const struct btr_node *btrn);
+bool btr_no_parent(const struct btr_node *btrn);
+size_t btr_next_buffer(const struct btr_node *btrn, char **bufp);
+size_t btr_next_buffer_omit(const struct btr_node *btrn, size_t omit,
+               char **bufp);
 void btr_consume(struct btr_node *btrn, size_t numbytes);
-int btr_exec_up(struct btr_node *btrn, const char *command, char **value_result);
+int btr_exec_up(const struct btr_node *btrn, const char *command, char **value_result);
 void btr_splice_out_node(struct btr_node **btrnp);
 void btr_pushdown(struct btr_node *btrn);
-void *btr_context(struct btr_node *btrn);
+void *btr_context(const struct btr_node *btrn);
 void btr_merge(struct btr_node *btrn, size_t dest_size);
-void btr_log_tree(struct btr_node *btrn, int ll);
+void btr_log_tree(const struct btr_node *btrn, int ll);
 void btr_pushdown_one(struct btr_node *btrn);
-bool btr_inplace_ok(struct btr_node *btrn);
-int btr_node_status(struct btr_node *btrn, size_t min_iqs,
+bool btr_inplace_ok(const struct btr_node *btrn);
+int btr_node_status(const struct btr_node *btrn, size_t min_iqs,
                enum btr_node_type type);
-void btr_get_node_start(struct btr_node *btrn, struct timeval *tv);
+void btr_get_node_start(const struct btr_node *btrn, struct timeval *tv);
 struct btr_node *btr_search_node(const char *name, struct btr_node *root);
 void btr_drain(struct btr_node *btrn);
-struct btr_node *btr_parent(struct btr_node *btrn);
+struct btr_node *btr_parent(const struct btr_node *btrn);
index 3789f30aa5a20ef5433df83362a6be02563c8d17..cb39eb540dafae31733623625bf31474c463a243 100644 (file)
@@ -54,7 +54,7 @@ void check_wav_pre_monitor(struct sched *s, struct check_wav_context *cwc)
                sched_min_delay(s);
 }
 
-static int check_wav_exec(struct btr_node *btrn, const char *cmd, char **result)
+static int check_wav_exec(const struct btr_node *btrn, const char *cmd, char **result)
 {
        struct check_wav_context *cwc = btr_context(btrn);
        int val, header_val, given, arg;
index fb8ebf15d1ec664e39923c58515a3704441ab0da..bc3a678b52cf7811ca6032e61f1eb6128766f819 100644 (file)
@@ -187,7 +187,7 @@ static int flacdec_init(struct filter_node *fn)
        return -E_FLACDEC_DECODER_INIT;
 }
 
-static int flacdec_execute(struct btr_node *btrn, const char *cmd,
+static int flacdec_execute(const struct btr_node *btrn, const char *cmd,
                char **result)
 {
        struct filter_node *fn = btr_context(btrn);
index cf3e5d4be6fcf267dcb497c24c7975a88c1df1c4..d4d4712f0d25a9e8981e8882ff0cbe1ddef14d0c 100644 (file)
@@ -175,7 +175,8 @@ static void mp3dec_open(struct filter_node *fn)
                mad_stream_options(&pmd->stream, MAD_OPTION_IGNORECRC);
 }
 
-static int mp3dec_execute(struct btr_node *btrn, const char *cmd, char **result)
+static int mp3dec_execute(const struct btr_node *btrn, const char *cmd,
+               char **result)
 {
        struct filter_node *fn = btr_context(btrn);
        struct private_mp3dec_data *pmd = fn->private_data;
index b1aec4bc2c4cb0049ed942d3b7e7708b2de84688..91c18c48899bd4741a6efe55c1d9a734e3ecfb14 100644 (file)
@@ -107,7 +107,8 @@ static void ogg_close(struct filter_node *fn)
        fn->private_data = NULL;
 }
 
-static int oggdec_execute(struct btr_node *btrn, const char *cmd, char **result)
+static int oggdec_execute(const struct btr_node *btrn, const char *cmd,
+               char **result)
 {
        struct filter_node *fn = btr_context(btrn);
        struct private_oggdec_data *pod = fn->private_data;
index f36990faf43a4110c8e7f7dc2f822f5a8e09046c..504ba0e881ef7fe268670be28d267b68c85188d2 100644 (file)
@@ -75,7 +75,7 @@ struct opusdec_context {
        ogg_int32_t opus_serialno;
 };
 
-static int opusdec_execute(struct btr_node *btrn, const char *cmd,
+static int opusdec_execute(const struct btr_node *btrn, const char *cmd,
                char **result)
 {
        struct filter_node *fn = btr_context(btrn);
index 72cb3f62ea766ee7ed94e3a68ed5a17591f2f133..6d4599a8f6718a4fafa7c3f2cf1e2296002609ac 100644 (file)
@@ -28,7 +28,8 @@ struct resample_context {
        struct check_wav_context *cwc;
 };
 
-static int resample_execute(struct btr_node *btrn, const char *cmd, char **result)
+static int resample_execute(const struct btr_node *btrn, const char *cmd,
+               char **result)
 {
        struct filter_node *fn = btr_context(btrn);
        struct resample_context *ctx = fn->private_data;
index 08eac02a557b2d503646666edd7ffb35e1c5c5f7..ce72125e125951feb2a14bd0add6e61762e77b1a 100644 (file)
@@ -102,7 +102,7 @@ static void speexdec_close(struct filter_node *fn)
        fn->private_data = NULL;
 }
 
-static int speexdec_execute(struct btr_node *btrn, const char *cmd,
+static int speexdec_execute(const struct btr_node *btrn, const char *cmd,
                char **result)
 {
        struct filter_node *fn = btr_context(btrn);
index f2ca273cd08979f33b42ab0a7f84b533fe29a583..5b3d9874bf5f905ef19c6b3689fd8006ad95c759 100644 (file)
@@ -1147,7 +1147,8 @@ static void wmadec_close(struct filter_node *fn)
        fn->private_data = NULL;
 }
 
-static int wmadec_execute(struct btr_node *btrn, const char *cmd, char **result)
+static int wmadec_execute(const struct btr_node *btrn, const char *cmd,
+               char **result)
 {
        struct filter_node *fn = btr_context(btrn);
        struct private_wmadec_data *pwd = fn->private_data;