Skip to content

Instantly share code, notes, and snippets.

@pcmoore
Created February 28, 2018 17:27
Show Gist options
  • Save pcmoore/f644341a85c6ad7131a26f68f99e3fc6 to your computer and use it in GitHub Desktop.
Save pcmoore/f644341a85c6ad7131a26f68f99e3fc6 to your computer and use it in GitHub Desktop.
XXX - work in progress, do not submit/push!
From: Paul Moore <paul@paul-moore.com>
things to do:
* investigate _db_tree_prune(), that likely needs some logic (lt/gt)
flipping to compensate for the changes in _db_tree_add()
* run the full regression test to ensure we aren't accidentally breaking
anything
* separate patch to add this test case to the regression tests
* separate patch to clear up the macros in src/db.h, see db_chain_lt() as
an example
---
src/db.c | 8 +++++++-
src/db.h | 21 ++++++++++++---------
2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/src/db.c b/src/db.c
index 1793e1d5c..d99dbc1d0 100644
--- a/src/db.c
+++ b/src/db.c
@@ -619,7 +619,7 @@ static int _db_tree_add(struct db_arg_chain_tree **existing,
}
return 0;
- } else if (db_chain_lt(x_iter, n_iter)) {
+ } else if (!db_chain_lt(x_iter, n_iter)) {
/* try to move along the current level */
if (x_iter->lvl_nxt == NULL) {
/* add to the end of this level */
@@ -640,6 +640,12 @@ static int _db_tree_add(struct db_arg_chain_tree **existing,
n_iter->lvl_prv = x_iter->lvl_prv;
n_iter->lvl_nxt = x_iter;
x_iter->lvl_prv = n_iter;
+#if 1
+ /* XXX - this should be patches separately, it applies
+ * to the old code too i think */
+ if (*existing == x_iter)
+ *existing = n_iter;
+#endif
return 0;
}
} while (x_iter);
diff --git a/src/db.h b/src/db.h
index 33811d21e..9503b0c1b 100644
--- a/src/db.h
+++ b/src/db.h
@@ -78,17 +78,20 @@ struct db_arg_chain_tree {
};
#define ARG_MASK_MAX ((uint32_t)-1)
#define db_chain_lt(x,y) \
- (((x)->arg < (y)->arg) || \
- (((x)->arg == (y)->arg) && \
- (((x)->op < (y)->op) || (((x)->mask & (y)->mask) == (y)->mask))))
+ ( ((x)->arg < (y)->arg) || \
+ ( ((x)->arg == (y)->arg) && \
+ ( ( (x)->op < (y)->op ) || \
+ ( ((x)->op == (y)->op) && \
+ ( ((x)->mask < (y)->mask) || \
+ ( ((x)->mask == (y)->mask) && \
+ ((x)->datum < (y)->datum) ) ) ) ) ) )
#define db_chain_eq(x,y) \
- (((x)->arg == (y)->arg) && \
- ((x)->op == (y)->op) && ((x)->datum == (y)->datum) && \
- ((x)->mask == (y)->mask))
+ ( ((x)->arg == (y)->arg) && \
+ ((x)->op == (y)->op) && \
+ ((x)->datum == (y)->datum) && \
+ ((x)->mask == (y)->mask) )
#define db_chain_gt(x,y) \
- (((x)->arg > (y)->arg) || \
- (((x)->arg == (y)->arg) && \
- (((x)->op > (y)->op) || (((x)->mask & (y)->mask) != (y)->mask))))
+ ( !(db_chain_eq(x,y) || db_chain_lt(x,y)) )
#define db_chain_action(x) \
(((x)->act_t_flg) || ((x)->act_f_flg))
#define db_chain_zombie(x) \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment