X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-lib%2Fmem.h;h=d981a805b9420af0608b37243c6fd045ea8b6bf3;hp=8d904b3d7b607abaab41092a10c1bfce59742d96;hb=6d838d9aef36d95fa439b3f7cc06d4e81c8581bd;hpb=a72bbb26973d73ce98c1dde62f3a114e2bb6589c diff --git a/lib-lib/mem.h b/lib-lib/mem.h index 8d904b3..d981a80 100644 --- a/lib-lib/mem.h +++ b/lib-lib/mem.h @@ -100,6 +100,27 @@ static inline void *xmemdupstr(const void *src, ssize_t len) { } +#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); \