#define CCAN_TAKE_H
#include "config.h"
#include <stdbool.h>
+#include <ccan/str/str.h>
+
+#ifdef CCAN_TAKE_DEBUG
+#define TAKE_LABEL(p) __FILE__ ":" stringify(__LINE__) ":" stringify(p)
+#else
+#define TAKE_LABEL(p) NULL
+#endif
/**
* take - record a pointer to be consumed by the function its handed to.
* which is extremely useful for chaining functions. It works on
* NULL, for pass-through error handling.
*/
-#define take(p) (take_typeof(p) take_((p)))
+#define take(p) (take_typeof(p) take_((p), TAKE_LABEL(p)))
/**
* taken - check (and un-take) a pointer was passed with take()
/**
* taken_any - are there any taken pointers?
*
- * Mainly useful for debugging take() leaks.
+ * Mainly useful for debugging take() leaks. With CCAN_TAKE_DEBUG, returns
+ * the label where the pointer was passed to take(), otherwise returns
+ * a static char buffer with the pointer value in it. NULL if none are taken.
*
* Example:
* static void cleanup(void)
* assert(!taken_any());
* }
*/
-bool taken_any(void);
+const char *taken_any(void);
/**
* take_cleanup - remove all taken pointers from list.
#define take_typeof(ptr)
#endif
-void *take_(const void *p);
+void *take_(const void *p, const char *label);
#endif /* CCAN_TAKE_H */