Signed-off-by: Pierre Habouzit <madcoder@debian.org>
}
+#define DO_REFCNT(type, prefix) \
+ static inline type *prefix##_new(void) { \
+ type *res = prefix##_init(p_new(type, 1)); \
+ res->refcnt = 1; \
+ return res; \
+ } \
+ static inline type *prefix##_dup(type *t) { \
+ t->refcnt++; \
+ return t; \
+ } \
+ static inline void prefix##_delete(type **tp) { \
+ if (*tp) { \
+ if (--(*tp)->refcnt > 0) { \
+ *tp = NULL; \
+ } else { \
+ prefix##_wipe(*tp); \
+ p_delete(tp); \
+ } \
+ } \
+ }
+
#define DO_INIT(type, prefix) \
static inline type * prefix##_init(type *var) { \
p_clear(var, 1); \