From 0f917d93bf1a6664b65e1b62d97c9b46189a6c90 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 18 Aug 2023 18:57:25 -0700 Subject: [PATCH] util/rb-tree: Work around C++'s dislike of offsetof This is the same technique used in src/compiler/glsl/list.h. Reviewed-by: Kenneth Graunke Part-of: --- src/util/rb_tree.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/util/rb_tree.h b/src/util/rb_tree.h index 2ccc102..9d78987 100644 --- a/src/util/rb_tree.h +++ b/src/util/rb_tree.h @@ -93,6 +93,14 @@ struct rb_node *rb_node_next(struct rb_node *node); /** Get the next previous (to the left) in the tree or NULL */ struct rb_node *rb_node_prev(struct rb_node *node); +#ifdef __cplusplus +/* This macro will not work correctly if `t' uses virtual inheritance. */ +#define rb_tree_offsetof(t, f, p) \ + (((char *) &((t *) p)->f) - ((char *) p)) +#else +#define rb_tree_offsetof(t, f, p) offsetof(t, f) +#endif + /** Retrieve the data structure containing a node * * \param type The type of the containing data structure @@ -102,7 +110,7 @@ struct rb_node *rb_node_prev(struct rb_node *node); * \param field The rb_node field in the containing data structure */ #define rb_node_data(type, node, field) \ - ((type *)(((char *)(node)) - offsetof(type, field))) + ((type *)(((char *)(node)) - rb_tree_offsetof(type, field, node))) /** Insert a node into a tree at a particular location * -- 2.7.4