mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-29 20:50:11 +01:00
c-rbtree: align CRBTree with CRBNode
We sometimes store pointers to `CRBTree` in `CRBNode*` variables, so we must make sure CRBTree has matching alignment guarantees. We already check for that with static-assertions. This commit aligns CRBTree with CRBNode for 2-byte aligned machines. While at it, add a short comment explaining what the unions are for. Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>c795b7657f(cherry picked from commit1250fcc2b1)
This commit is contained in:
parent
72dd79e817
commit
eac2b67052
1 changed files with 7 additions and 2 deletions
|
|
@ -61,7 +61,8 @@ typedef struct CRBTree CRBTree;
|
|||
struct CRBNode {
|
||||
union {
|
||||
unsigned long __parent_and_flags;
|
||||
alignas(4) char __dmmy_for_struct_alignment;
|
||||
/* enforce >=4-byte alignment for @__parent_and_flags */
|
||||
alignas(4) unsigned char __align_dummy;
|
||||
};
|
||||
CRBNode *left;
|
||||
CRBNode *right;
|
||||
|
|
@ -92,7 +93,11 @@ void c_rbnode_unlink_stale(CRBNode *n);
|
|||
* To initialize an RB-Tree, set it to NULL / all zero.
|
||||
*/
|
||||
struct CRBTree {
|
||||
CRBNode *root;
|
||||
union {
|
||||
CRBNode *root;
|
||||
/* enforce >=4-byte alignment for @root */
|
||||
alignas(4) unsigned char __align_dummy;
|
||||
};
|
||||
};
|
||||
|
||||
#define C_RBTREE_INIT {}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue