* The returned string will have tal_count() == strlen() + 1.
*/
#define tal_strdup(ctx, p) tal_strdup_(ctx, p, TAL_LABEL(char, "[]"))
-char *tal_strdup_(const tal_t *ctx, const char *p TAKES, const char *label);
+char *tal_strdup_(const tal_t *ctx, const char *p TAKES, const char *label)
+ TAL_RETURN_PTR;
/**
* tal_strndup - duplicate a limited amount of a string.
*/
#define tal_strndup(ctx, p, n) tal_strndup_(ctx, p, n, TAL_LABEL(char, "[]"))
char *tal_strndup_(const tal_t *ctx, const char *p TAKES, size_t n,
- const char *label);
+ const char *label)
+ TAL_RETURN_PTR;
/**
* tal_fmt - allocate a formatted string
#define tal_fmt(ctx, ...) \
tal_fmt_(ctx, TAL_LABEL(char, "[]"), __VA_ARGS__)
char *tal_fmt_(const tal_t *ctx, const char *label, const char *fmt TAKES,
- ...) PRINTF_FMT(3,4);
+ ...) PRINTF_FMT(3,4) TAL_RETURN_PTR;
/**
* tal_vfmt - allocate a formatted string (va_list version)
tal_vfmt_(ctx, fmt, va, TAL_LABEL(char, "[]"))
char *tal_vfmt_(const tal_t *ctx, const char *fmt TAKES, va_list ap,
const char *label)
- PRINTF_FMT(2,0);
+ PRINTF_FMT(2,0) TAL_RETURN_PTR;
/**
* tal_append_fmt - append a formatted string to a talloc string.
*/
#define tal_strcat(ctx, s1, s2) tal_strcat_(ctx, s1, s2, TAL_LABEL(char, "[]"))
char *tal_strcat_(const tal_t *ctx, const char *s1 TAKES, const char *s2 TAKES,
- const char *label);
+ const char *label) TAL_RETURN_PTR;
enum strsplit {
STR_EMPTY_OK,
const char *string TAKES,
const char *delims TAKES,
enum strsplit flag,
- const char *label);
+ const char *label)
+ TAL_RETURN_PTR;
enum strjoin {
STR_TRAIL,
char *strings[] TAKES,
const char *delim TAKES,
enum strjoin flags,
- const char *label);
+ const char *label)
+ TAL_RETURN_PTR;
/**
* tal_strreg - match/extract from a string via (extended) regular expressions.
#include <stdbool.h>
#include <stdarg.h>
+/* Define this for better optimization if you never override errfn
+ * to something tat returns */
+#ifdef CCAN_TAL_NEVER_RETURN_NULL
+#define TAL_RETURN_PTR RETURNS_NONNULL
+#else
+#define TAL_RETURN_PTR
+#endif /* CCAN_TAL_NEVER_RETURN_NULL */
+
/**
* tal_t - convenient alias for void to mark tal pointers.
*
* @error_fn: called on errors or NULL (default is abort)
*
* The defaults are set up so tal functions never return NULL, but you
- * can override erorr_fn to change that. error_fn can return, and is
+ * can override error_fn to change that. error_fn can return (only if
+ * you haven't defined CCAN_TAL_NEVER_RETURN_NULL!), and is
* called if alloc_fn or resize_fn fail.
*
* If any parameter is NULL, that function is unchanged.
#define tal_typechk_(ptr, ptype) (ptr)
#endif
-void *tal_alloc_(const tal_t *ctx, size_t bytes, bool clear, const char *label);
+void *tal_alloc_(const tal_t *ctx, size_t bytes, bool clear, const char *label)
+ TAL_RETURN_PTR;
void *tal_alloc_arr_(const tal_t *ctx, size_t bytes, size_t count, bool clear,
- const char *label);
+ const char *label)
+ TAL_RETURN_PTR;
void *tal_dup_(const tal_t *ctx, const void *p TAKES, size_t size,
size_t n, size_t extra, bool nullok, const char *label);