25RCSIDH(talloc_h,
"$Id: b65112d6de797b9f25ae4ed371939c0e5c3fca02 $")
33#include <freeradius-devel/autoconf.h>
34#include <freeradius-devel/build.h>
35#include <freeradius-devel/missing.h>
37#ifdef TALLOC_EXTENSIONS
38#include TALLOC_EXTENSIONS
44#ifdef HAVE_WDOCUMENTATION
48#ifdef HAVE_WDOCUMENTATION
52#undef talloc_autofree_context
55#define talloc_autofree_context talloc_autofree_context_global
79#define talloc_foreach(_array, _iter) \
80 for (__typeof__(_array[0]) _iter, *_p = (void *)(_array), *_end = _array ? (void *)((_array) + talloc_array_length(_array)) : NULL; \
81 (_p < _end) && (_iter = *((void **)(uintptr_t)(_p))); \
82 _p = (__typeof__(_p))((__typeof__(_array))_p) + 1)
114#ifdef TALLOC_GET_TYPE_ABORT_NOOP
115# define talloc_get_type_abort_const(ptr, type) (const type *)(ptr)
117# define talloc_get_type_abort_const talloc_get_type_abort
131 ctx = talloc_new(NULL);
134 talloc_set_name_const(ctx,
name);
146 char const *our_s = s;
147 return talloc_array_length(our_s) - 1;
149#define talloc_strdup(_ctx, _str) talloc_typed_strdup((TALLOC_CTX *) (_ctx), _str)
150#define talloc_strndup(_ctx, _str, _len) talloc_typed_strndup((TALLOC_CTX *) (_ctx), _str, _len)
151#define talloc_asprintf talloc_typed_asprintf
163 for (p = str; p < end; p++) *p = tolower((
uint8_t) *p);
178TALLOC_CTX *
talloc_page_aligned_pool(TALLOC_CTX *ctx,
void **start,
size_t *end_len,
unsigned int headers,
size_t size);
184#if defined(HAVE__TALLOC_POOLED_OBJECT) && defined(talloc_pooled_object)
185# define HAVE_TALLOC_ZERO_POOLED_OBJECT 1
186# define HAVE_TALLOC_POOLED_OBJECT 1
188# define talloc_zero_pooled_object(_ctx, _type, _num_subobjects, _total_subobjects_size) \
189 (_type *)_talloc_zero_pooled_object((_ctx), sizeof(_type), #_type, \
190 (_num_subobjects), (_total_subobjects_size))
192static inline TALLOC_CTX *_talloc_zero_pooled_object(
const void *ctx,
194 const char *type_name,
195 unsigned num_subobjects,
196 size_t total_subobjects_size)
199 new = _talloc_pooled_object(ctx, type_size, type_name, num_subobjects, total_subobjects_size);
201 memset(
new, 0, type_size);
208# define talloc_zero_pooled_object(_ctx, _type, _num_subobjects, _total_subobjects_size) \
209 talloc_zero(_ctx, _type)
210#undef talloc_pooled_object
211# define talloc_pooled_object(_ctx, _type, _num_subobjects, _total_subobjects_size) \
217#undef talloc_realloc_zero
218#define talloc_realloc_zero(_ctx, _ptr, _type, _count) \
219 (_type *)_talloc_realloc_zero((_ctx), (_ptr), sizeof(_type), _count, #_type)
238char *
talloc_bstr_append(TALLOC_CTX *ctx,
char *to,
char const *from,
size_t from_len);
static int const char * fmt
#define UNCONST(_type, _ptr)
Remove const qualification from a pointer.
Functions which we wish were included in the standard talloc distribution.
void ** talloc_array_null_terminate(void **array)
Add a NULL pointer to an array of pointers.
char * talloc_bstrdup(TALLOC_CTX *ctx, char const *in)
Binary safe strdup function.
static int talloc_const_free(void const *ptr)
Free const'd memory.
char * talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt,...))
Call talloc vasprintf, setting the type on the new chunk correctly.
fr_talloc_destructor_t * talloc_destructor_add(TALLOC_CTX *fire_ctx, TALLOC_CTX *disarm_ctx, fr_talloc_free_func_t func, void const *uctx)
Add an additional destructor to a talloc chunk.
char * talloc_typed_strdup_buffer(TALLOC_CTX *ctx, char const *p)
Call talloc_strndup, setting the type on the new chunk correctly.
ssize_t talloc_hdr_size(void)
Calculate the size of the talloc chunk header.
TALLOC_CTX * talloc_autofree_context_global(void)
char * talloc_buffer_append_variadic_buffer(TALLOC_CTX *ctx, char *to, int argc,...)
Concatenate to + ...
void * _talloc_realloc_zero(const void *ctx, void *ptr, size_t elem_size, unsigned count, const char *name)
Version of talloc_realloc which zeroes out freshly allocated memory.
char * talloc_bstr_realloc(TALLOC_CTX *ctx, char *in, size_t inlen)
Trim a bstr (char) buffer.
fr_talloc_free_func_t func
Free function.
static TALLOC_CTX * talloc_init_const(char const *name)
Allocate a top level chunk with a constant name.
TALLOC_CTX * talloc_aligned_array(TALLOC_CTX *ctx, void **start, size_t alignment, size_t size)
Return a page aligned talloc memory array.
int talloc_link_ctx(TALLOC_CTX *parent, TALLOC_CTX *child)
Link two different parent and child contexts, so the child is freed before the parent.
uint8_t * talloc_typed_memdup(TALLOC_CTX *ctx, uint8_t const *in, size_t inlen)
Call talloc_memdup, setting the type on the new chunk correctly.
char * talloc_bstrndup(TALLOC_CTX *ctx, char const *in, size_t inlen)
Binary safe strndup function.
void * talloc_null_ctx(void)
Retrieve the current talloc NULL ctx.
fr_talloc_destructor_t * d
Destructor to disarm.
TALLOC_CTX * talloc_page_aligned_pool(TALLOC_CTX *ctx, void **start, size_t *end_len, unsigned int headers, size_t size)
Return a page aligned talloc memory pool.
char * talloc_typed_strdup(TALLOC_CTX *ctx, char const *p)
Call talloc_strdup, setting the type on the new chunk correctly.
void talloc_free_data(void *data)
A wrapper that can be passed to tree or hash alloc functions that take a fr_free_t.
int talloc_decrease_ref_count(void const *ptr)
Decrease the reference count on a ptr.
char * talloc_typed_strndup(TALLOC_CTX *ctx, char const *p, size_t len)
Call talloc_strndup, setting the type on the new chunk correctly.
TALLOC_CTX * talloc_autofree_context_thread_local(void)
Get a thread-safe autofreed ctx that will be freed when the thread or process exits.
void * uctx
uctx to pass to free function.
char * talloc_bstr_append(TALLOC_CTX *ctx, char *to, char const *from, size_t from_len)
Append a bstr to a bstr.
void talloc_destructor_disarm(fr_talloc_destructor_t *d)
Disarm a destructor and free all memory allocated in the trigger ctxs.
int(* fr_talloc_free_func_t)(void *fire_ctx, void *uctx)
static void talloc_bstr_tolower(char *str)
Convert a talloced string to lowercase.
fr_talloc_destructor_disarm_t * ds
Chunk to free.
static size_t talloc_strlen(char const *s)
Returns the length of a talloc array containing a string.
char * talloc_typed_vasprintf(TALLOC_CTX *ctx, char const *fmt, va_list ap))
Call talloc vasprintf, setting the type on the new chunk correctly.
int talloc_memcmp_bstr(char const *a, char const *b)
Compares two talloced char arrays with memcmp.
Structure to record a destructor to disarm if a child talloc chunk is freed.
Structure to record a destructor operation on a specific talloc chunk.
static size_t char fr_sbuff_t size_t inlen