https://git.reactos.org/?p=reactos.git;a=commitdiff;h=3c18f2a7c7b0e6037b83b…
commit 3c18f2a7c7b0e6037b83bf8a9216925006726ab8
Author: Amine Khaldi <amine.khaldi(a)reactos.org>
AuthorDate: Mon Jun 4 03:54:55 2018 +0100
Commit: Amine Khaldi <amine.khaldi(a)reactos.org>
CommitDate: Mon Jun 4 03:54:55 2018 +0100
[INCLUDE/WINE] Update rbtree.h. CORE-14656
---
sdk/include/reactos/wine/rbtree.h | 36 +++++++++++++++++++++++++++++-------
1 file changed, 29 insertions(+), 7 deletions(-)
diff --git a/sdk/include/reactos/wine/rbtree.h b/sdk/include/reactos/wine/rbtree.h
index 441e039395..8130deb5d3 100644
--- a/sdk/include/reactos/wine/rbtree.h
+++ b/sdk/include/reactos/wine/rbtree.h
@@ -107,6 +107,13 @@ static inline struct wine_rb_entry *wine_rb_head(struct wine_rb_entry
*iter)
return iter;
}
+static inline struct wine_rb_entry *wine_rb_tail(struct wine_rb_entry *iter)
+{
+ if (!iter) return NULL;
+ while (iter->right) iter = iter->right;
+ return iter;
+}
+
static inline struct wine_rb_entry *wine_rb_next(struct wine_rb_entry *iter)
{
if (iter->right) return wine_rb_head(iter->right);
@@ -114,6 +121,13 @@ static inline struct wine_rb_entry *wine_rb_next(struct wine_rb_entry
*iter)
return iter->parent;
}
+static inline struct wine_rb_entry *wine_rb_prev(struct wine_rb_entry *iter)
+{
+ if (iter->left) return wine_rb_tail(iter->left);
+ while (iter->parent && iter->parent->left == iter) iter =
iter->parent;
+ return iter->parent;
+}
+
static inline struct wine_rb_entry *wine_rb_postorder_head(struct wine_rb_entry *iter)
{
if (!iter) return NULL;
@@ -139,19 +153,27 @@ static inline struct wine_rb_entry *wine_rb_postorder_next(struct
wine_rb_entry
/* iterate through the tree using a tree entry */
#define WINE_RB_FOR_EACH_ENTRY(elem, tree, type, field) \
for ((elem) = WINE_RB_ENTRY_VALUE(wine_rb_head((tree)->root), type, field); \
- &(elem)->field; \
+ (elem) != WINE_RB_ENTRY_VALUE(0, type, field); \
(elem) = WINE_RB_ENTRY_VALUE(wine_rb_next(&elem->field), type, field))
+/* iterate through the tree using using postorder, making it safe to free the entry */
+#define WINE_RB_FOR_EACH_DESTRUCTOR(cursor, cursor2, tree) \
+ for ((cursor) = wine_rb_postorder_head((tree)->root); \
+ (cursor) && (((cursor2) = wine_rb_postorder_next(cursor)) || 1); \
+ (cursor) = (cursor2))
+
+/* iterate through the tree using a tree entry and postorder, making it safe to free the
entry */
+#define WINE_RB_FOR_EACH_ENTRY_DESTRUCTOR(elem, elem2, tree, type, field) \
+ for ((elem) = WINE_RB_ENTRY_VALUE(wine_rb_postorder_head((tree)->root), type,
field); \
+ (elem) != WINE_RB_ENTRY_VALUE(0, type, field) \
+ && (((elem2) =
WINE_RB_ENTRY_VALUE(wine_rb_postorder_next(&(elem)->field), type, field)) || 1); \
+ (elem) = (elem2))
+
static inline void wine_rb_postorder(struct wine_rb_tree *tree, wine_rb_traverse_func_t
*callback, void *context)
{
struct wine_rb_entry *iter, *next;
-
- for (iter = wine_rb_postorder_head(tree->root); iter; iter = next)
- {
- next = wine_rb_postorder_next(iter);
- callback(iter, context);
- }
+ WINE_RB_FOR_EACH_DESTRUCTOR(iter, next, tree) callback(iter, context);
}
static inline void wine_rb_init(struct wine_rb_tree *tree, wine_rb_compare_func_t
compare)