]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
qptrie: allow NULL trie_cb callback
authorDaniel Salzman <daniel.salzman@nic.cz>
Mon, 29 Apr 2019 07:53:49 +0000 (09:53 +0200)
committerDaniel Salzman <daniel.salzman@nic.cz>
Mon, 29 Apr 2019 07:53:49 +0000 (09:53 +0200)
src/contrib/qp-trie/trie.c
src/contrib/qp-trie/trie.h

index dc397770041b358ee528bbc080182eff9097aae4..9c11202e0cc2d4edfb3125af030b8711424565f7 100644 (file)
@@ -1246,9 +1246,11 @@ static void mark_cow(trie_cow_t *cow, node_t *t)
                object->i |= TFLAG_COW;
        } else {
                tkey_t *lkey = tkey(t);
-               trie_val_t *valp = tvalp(t);
                lkey->cow = 1;
-               cow->mark_shared(*valp, lkey->chars, lkey->len, cow->d);
+               if (cow->mark_shared != NULL) {
+                       trie_val_t *valp = tvalp(t);
+                       cow->mark_shared(*valp, lkey->chars, lkey->len, cow->d);
+               }
        }
 }
 
@@ -1376,8 +1378,10 @@ static void cow_cleanup(trie_cow_t *cow, node_t *t, trie_cb *cb, void *d)
        } else {
                // application must decide how to clean up its values
                tkey_t *lkey = tkey(t);
-               trie_val_t *valp = tvalp(t);
-               cb(*valp, lkey->chars, lkey->len, d);
+               if (cb != NULL) {
+                       trie_val_t *valp = tvalp(t);
+                       cb(*valp, lkey->chars, lkey->len, d);
+               }
                // clean up exclusively-owned keys
                if (lkey->cow)
                        lkey->cow = 0;
index 1ddbb324f44b392b12a088eb95e68d469bb876ec..0e0cb5436bbdbc03d733283af175890b5ae6175c 100644 (file)
@@ -212,7 +212,7 @@ void trie_it_del(trie_it_t *it);
  * There must be only one write transaction at a time.
  *
  * \param old          the old trie
- * \param mark_shared  callback to mark a leaf as shared
+ * \param mark_shared  callback to mark a leaf as shared (can be NULL)
  * \param d            extra data for the callback
  * \return             a pointer to a COW context,
  *                     or NULL if there was a failure
@@ -253,6 +253,8 @@ int trie_del_cow(trie_cow_t *cow, const trie_key_t *key, uint32_t len, trie_val_
  * cleaning up; you must free any objects you have marked as old-only
  * and retain objects with shared reachability.
  *
+ * \note The callback can be NULL.
+ *
  * The cow object is free()d, and the new trie root is returned.
  */
 trie_t* trie_cow_commit(trie_cow_t *cow, trie_cb *cb, void *d);
@@ -263,6 +265,8 @@ trie_t* trie_cow_commit(trie_cow_t *cow, trie_cb *cb, void *d);
  * cleaning up; you must free any objects you have marked as new-only
  * and retain objects with shared reachability.
  *
+ * \note The callback can be NULL.
+ *
  * The cow object is free()d, and the old trie root is returned.
  */
 trie_t* trie_cow_rollback(trie_cow_t *cow, trie_cb *cb, void *d);