libnl/python/netlink/utils.h
Arend van Spriel 86207d47ab python: rework netlink callback handling
The initial commit adding netlink callback handling also introduced
memory leak issue. The python callback info was stored in an allocated
structure, but that was never freed.

Only exposing nl_cb_alloc() as is. nl_cb_get() is removed as it is
not very useful to use reference counting mechanism. Python uses
that itself internally. To deal properly with Python callback info
the function nl_cb_put() and nl_cb_clone() have a custom wrapper
taking care of Python reference counting.

This commit also adds a Callback python class using the netlink
callback functions.

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-09-05 17:46:00 +02:00

41 lines
961 B
C

struct list_head {
struct list_head *next;
};
#define LIST_HEAD(name) \
struct list_head name = { &(name) }
static inline int list_empty(const struct list_head *head)
{
return head->next == head;
}
static inline void list_add(struct list_head *new, struct list_head *head)
{
new->next = head->next;
head->next = new;
}
static inline void list_del(struct list_head *entry, struct list_head *prev)
{
prev->next = entry->next;
entry->next = entry;
}
#define list_for_each_safe(pos, n, head) \
for (n = (head), pos = (head)->next; pos != (head); \
n = pos, pos = n->next)
#undef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#ifdef DEBUG
#define pynl_dbg(fmt, ...) \
fprintf(stderr, "%s: " fmt, __func__, __VA_ARGS__)
#else
#define pynl_dbg(fmt, ...)
#endif