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 commit 1250fcc2b1)
This commit is contained in:
David Rheinsberg 2020-10-21 10:08:12 +02:00 committed by Thomas Haller
parent 72dd79e817
commit eac2b67052
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -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 {}