From: Daniel Salzman Date: Mon, 29 Apr 2019 07:53:49 +0000 (+0200) Subject: qptrie: allow NULL trie_cb callback X-Git-Tag: v2.9.0~284^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b1941884f6bdeead8aae4874314fff9e22e1ba4f;p=thirdparty%2Fknot-dns.git qptrie: allow NULL trie_cb callback --- diff --git a/src/contrib/qp-trie/trie.c b/src/contrib/qp-trie/trie.c index dc39777004..9c11202e0c 100644 --- a/src/contrib/qp-trie/trie.c +++ b/src/contrib/qp-trie/trie.c @@ -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; diff --git a/src/contrib/qp-trie/trie.h b/src/contrib/qp-trie/trie.h index 1ddbb324f4..0e0cb5436b 100644 --- a/src/contrib/qp-trie/trie.h +++ b/src/contrib/qp-trie/trie.h @@ -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);