]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: const struct index_mm as applicable
authorEmil Velikov <emil.l.velikov@gmail.com>
Mon, 4 Nov 2024 14:32:39 +0000 (14:32 +0000)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Thu, 7 Nov 2024 19:43:49 +0000 (13:43 -0600)
The index_mm_{search,read,dump}* API does not mutate the index_mm
struct. So let's annotate it as constant.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/224
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
libkmod/libkmod-index.c
libkmod/libkmod-index.h

index 0c0078908e20d44d1b6536c52b9424e0071234e1..7909c774815f3350ae8e48b14e0853d7511b0508 100644 (file)
@@ -613,7 +613,7 @@ struct index_mm_value {
 };
 
 struct index_mm_node {
-       struct index_mm *idx;
+       const struct index_mm *idx;
        const char *prefix; /* mmap'ed value */
        unsigned char first;
        unsigned char last;
@@ -657,7 +657,8 @@ static inline void read_value_mm(const void **p, struct index_mm_value *v)
 }
 
 /* reads node into given node struct and returns its address on success or NULL on error. */
-static struct index_mm_node *index_mm_read_node(struct index_mm *idx, uint32_t offset,
+static struct index_mm_node *index_mm_read_node(const struct index_mm *idx,
+                                               uint32_t offset,
                                                struct index_mm_node *node)
 {
        const void *p;
@@ -797,7 +798,7 @@ void index_mm_close(struct index_mm *idx)
        free(idx);
 }
 
-static struct index_mm_node *index_mm_readroot(struct index_mm *idx,
+static struct index_mm_node *index_mm_readroot(const struct index_mm *idx,
                                               struct index_mm_node *root)
 {
        return index_mm_read_node(idx, idx->root_offset, root);
@@ -854,7 +855,7 @@ static void index_mm_dump_node(struct index_mm_node *node, struct strbuf *buf, i
        strbuf_popchars(buf, pushed);
 }
 
-void index_mm_dump(struct index_mm *idx, int fd, bool alias_prefix)
+void index_mm_dump(const struct index_mm *idx, int fd, bool alias_prefix)
 {
        struct index_mm_node nbuf, *root;
        struct strbuf buf;
@@ -911,7 +912,7 @@ static char *index_mm_search_node(struct index_mm_node *node, const char *key)
  *
  * Returns the value of the first match
  */
-char *index_mm_search(struct index_mm *idx, const char *key)
+char *index_mm_search(const struct index_mm *idx, const char *key)
 {
        // FIXME: return value by reference instead of strdup
        struct index_mm_node nbuf, *root;
@@ -1035,7 +1036,7 @@ static void index_mm_searchwild_node(struct index_mm_node *node, struct strbuf *
  *
  * Returns a list of all the values of matching keys.
  */
-struct index_value *index_mm_searchwild(struct index_mm *idx, const char *key)
+struct index_value *index_mm_searchwild(const struct index_mm *idx, const char *key)
 {
        struct index_mm_node nbuf, *root;
        struct strbuf buf;
index 1fbbd491fe6366d7f736363d4f3be8ab07a4f731..47c50d386a12cedf839ed89b4dbee1a76fb1026b 100644 (file)
@@ -29,6 +29,6 @@ struct index_mm;
 int index_mm_open(const struct kmod_ctx *ctx, const char *filename,
                  unsigned long long *stamp, struct index_mm **pidx);
 void index_mm_close(struct index_mm *index);
-char *index_mm_search(struct index_mm *idx, const char *key);
-struct index_value *index_mm_searchwild(struct index_mm *idx, const char *key);
-void index_mm_dump(struct index_mm *idx, int fd, bool alias_prefix);
+char *index_mm_search(const struct index_mm *idx, const char *key);
+struct index_value *index_mm_searchwild(const struct index_mm *idx, const char *key);
+void index_mm_dump(const struct index_mm *idx, int fd, bool alias_prefix);