57 #define HANDLE_ENTRY(name, structname) \
58 struct name ## _handle_head_t *handle_head
60 #define HANDLE_DECL(name, structname_t, linkage) \
61 typedef struct name ## _handle_t name ## _handle_t; \
62 linkage name ## _handle_t *name ## _handle_new( \
63 struct structname_t *object); \
64 linkage void name ## _handle_free_(name ## _handle_t *); \
65 linkage struct structname_t *name ## _handle_get(name ## _handle_t *); \
66 linkage void name ## _handles_clear(struct structname_t *object);
90 #define HANDLE_IMPL(name, structname, linkage) \
93 typedef struct name ## _handle_head_t { \
94 struct structname *object; \
95 unsigned int references; \
96 } name ## _handle_head_t; \
98 struct name ## _handle_t { \
99 struct name ## _handle_head_t *head; \
102 linkage struct name ## _handle_t * \
103 name ## _handle_new(struct structname *object) \
105 tor_assert(object); \
106 name ## _handle_head_t *head = object->handle_head; \
107 if (PREDICT_UNLIKELY(head == NULL)) { \
108 head = object->handle_head = tor_malloc_zero(sizeof(*head)); \
109 head->object = object; \
111 name ## _handle_t *new_ref = tor_malloc_zero(sizeof(*new_ref)); \
112 new_ref->head = head; \
113 ++head->references; \
118 name ## _handle_free_(struct name ## _handle_t *ref) \
121 name ## _handle_head_t *head = ref->head; \
123 --head->references; \
125 if (head->object == NULL && head->references == 0) { \
131 linkage struct structname * \
132 name ## _handle_get(struct name ## _handle_t *ref) \
135 name ## _handle_head_t *head = ref->head; \
137 return head->object; \
141 name ## _handles_clear(struct structname *object) \
143 tor_assert(object); \
144 name ## _handle_head_t *head = object->handle_head; \
147 object->handle_head = NULL; \
148 head->object = NULL; \
149 if (head->references == 0) { \
Headers for util_malloc.c.
Macros to manage assertions, fatal and non-fatal.