]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/generic/lru: doc nitpicks
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 24 Sep 2018 15:16:36 +0000 (17:16 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 12 Oct 2018 15:36:45 +0000 (17:36 +0200)
lib/generic/lru.c
lib/generic/lru.h

index c04f6f09fc49715fdbbe3fb9a2feb5407f191e1e..7ab31ae9b8e082b550d00ff32e260f0430b7a38f 100644 (file)
@@ -21,7 +21,15 @@ typedef struct lru_group lru_group_t;
 
 struct lru_item {
        uint16_t key_len, val_len; /**< Two bytes should be enough for our purposes. */
-       char data[];               /**< Place for both key and value. */
+       char data[];
+       /**< Place for both key and value.
+        *
+        * We use "char" to satisfy the C99+ aliasing rules.
+        * See C99 section 6.5 Expressions, paragraph 7.
+        * Any type can be accessed through char-pointer,
+        * so we can use a common struct definition
+        * for all types being held.
+        */
 };
 
 /** @internal Compute offset of value in struct lru_item. */
index 397e9bb4159ee83d6f7b5e74684fe0818373b8a4..61f3ce085866dada7dfcdc9aebc0bfaf160202a8 100644 (file)
  *  most frequent keys/hashes.  This tracking is done for *more* keys than
  *  those that are actually stored.
  *
- * # Example usage:
- *
+ * Example usage:
  * @code{.c}
  *     // Define new LRU type
  *     typedef lru_t(int) lru_int_t;
  *
  *     // Create LRU
  *     lru_int_t *lru;
- *     lru_create(&lru, 5, NULL);
+ *     lru_create(&lru, 5, NULL, NULL);
  *
  *     // Insert some values
- *     int *pi = lru_get_new(lru, "luke", strlen("luke"));
+ *     int *pi = lru_get_new(lru, "luke", strlen("luke"), NULL);
  *     if (pi)
  *             *pi = 42;
- *     pi = lru_get_new(lru, "leia", strlen("leia"));
+ *     pi = lru_get_new(lru, "leia", strlen("leia"), NULL);
  *     if (pi)
  *             *pi = 24;
  *
  *     // Retrieve values
- *     int *ret = lru_get_try(lru, "luke", strlen("luke"));
+ *     int *ret = lru_get_try(lru, "luke", strlen("luke"), NULL);
  *     if (!ret) printf("luke dropped out!\n");
  *         else  printf("luke's number is %d\n", *ret);
  *
  *     char *enemies[] = {"goro", "raiden", "subzero", "scorpion"};
  *     for (int i = 0; i < 4; ++i) {
- *             int *val = lru_get_new(lru, enemies[i], strlen(enemies[i]));
+ *             int *val = lru_get_new(lru, enemies[i], strlen(enemies[i]), NULL);
  *             if (val)
  *                     *val = i;
  *     }