mirror of
https://github.com/albfan/miraclecast.git
synced 2025-02-15 04:42:06 +00:00
shl: remove custom offsetof helpers
Use the generic shl_container_of() instead of all the custom helpers. Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
This commit is contained in:
parent
12bf5e026e
commit
4f55a01dc3
3 changed files with 7 additions and 14 deletions
|
@ -20,13 +20,7 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "shl_macro.h"
|
||||||
/* miscellaneous */
|
|
||||||
|
|
||||||
#define shl_dlist_offsetof(pointer, type, member) ({ \
|
|
||||||
const typeof(((type*)0)->member) *__ptr = (pointer); \
|
|
||||||
(type*)(((char*)__ptr) - offsetof(type, member)); \
|
|
||||||
})
|
|
||||||
|
|
||||||
/* double linked list */
|
/* double linked list */
|
||||||
|
|
||||||
|
@ -102,7 +96,7 @@ static inline struct shl_dlist *shl_dlist_last(struct shl_dlist *head)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define shl_dlist_entry(ptr, type, member) \
|
#define shl_dlist_entry(ptr, type, member) \
|
||||||
shl_dlist_offsetof((ptr), type, member)
|
shl_container_of((ptr), type, member)
|
||||||
|
|
||||||
#define shl_dlist_first_entry(head, type, member) \
|
#define shl_dlist_first_entry(head, type, member) \
|
||||||
shl_dlist_entry(shl_dlist_first(head), type, member)
|
shl_dlist_entry(shl_dlist_first(head), type, member)
|
||||||
|
|
|
@ -24,13 +24,12 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "shl_macro.h"
|
||||||
|
|
||||||
/* miscellaneous */
|
/* miscellaneous */
|
||||||
|
|
||||||
#define shl_htable_offsetof(pointer, type, member) ({ \
|
#define shl_htable_entry(pointer, type, member) \
|
||||||
const typeof(((type*)0)->member) *__ptr = (pointer); \
|
shl_container_of((pointer), type, member)
|
||||||
(type*)(((char*)__ptr) - offsetof(type, member)); \
|
|
||||||
})
|
|
||||||
|
|
||||||
/* htable */
|
/* htable */
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ struct peer {
|
||||||
};
|
};
|
||||||
|
|
||||||
#define peer_from_htable(_p) \
|
#define peer_from_htable(_p) \
|
||||||
shl_htable_offsetof((_p), struct peer, p2p_mac)
|
shl_htable_entry((_p), struct peer, p2p_mac)
|
||||||
|
|
||||||
int peer_new(struct link *l,
|
int peer_new(struct link *l,
|
||||||
const char *p2p_mac,
|
const char *p2p_mac,
|
||||||
|
@ -125,7 +125,7 @@ struct link {
|
||||||
};
|
};
|
||||||
|
|
||||||
#define link_from_htable(_l) \
|
#define link_from_htable(_l) \
|
||||||
shl_htable_offsetof((_l), struct link, ifindex)
|
shl_htable_entry((_l), struct link, ifindex)
|
||||||
#define LINK_FIRST_PEER(_l) \
|
#define LINK_FIRST_PEER(_l) \
|
||||||
SHL_HTABLE_FIRST_MACRO(&(_l)->peers, peer_from_htable)
|
SHL_HTABLE_FIRST_MACRO(&(_l)->peers, peer_from_htable)
|
||||||
#define LINK_FOREACH_PEER(_i, _l) \
|
#define LINK_FOREACH_PEER(_i, _l) \
|
||||||
|
|
Loading…
Reference in a new issue