25 RCSIDH(talloc_h,
"$Id: 1d7cc13b2df104e1dda30f82c3a15c5816e72fc9 $")
35 #ifdef HAVE_WDOCUMENTATION
39 #ifdef HAVE_WDOCUMENTATION
43 #include <freeradius-devel/autoconf.h>
44 #include <freeradius-devel/build.h>
45 #include <freeradius-devel/missing.h>
46 #include <freeradius-devel/util/sbuff.h>
48 #undef talloc_autofree_context
51 #define talloc_autofree_context talloc_autofree_context_global
75 #define talloc_foreach(_array, _iter) \
76 for (__typeof__(_array[0]) _iter, *_p = (void *)(_array), *_end = _array ? (void *)((_array) + talloc_array_length(_array)) : NULL; \
77 (_p < _end) && (_iter = *((void **)(uintptr_t)(_p))); \
78 _p = (__typeof__(_p))((__typeof__(_array))_p) + 1)
116 ctx = talloc_new(NULL);
119 talloc_set_name_const(ctx,
name);
141 #if defined(HAVE__TALLOC_POOLED_OBJECT) && defined(talloc_pooled_object)
142 # define HAVE_TALLOC_ZERO_POOLED_OBJECT 1
143 # define HAVE_TALLOC_POOLED_OBJECT 1
145 # define talloc_zero_pooled_object(_ctx, _type, _num_subobjects, _total_subobjects_size) \
146 (_type *)_talloc_zero_pooled_object((_ctx), sizeof(_type), #_type, \
147 (_num_subobjects), (_total_subobjects_size))
149 static inline TALLOC_CTX *_talloc_zero_pooled_object(
const void *ctx,
151 const char *type_name,
152 unsigned num_subobjects,
153 size_t total_subobjects_size)
156 new = _talloc_pooled_object(ctx, type_size, type_name, num_subobjects, total_subobjects_size);
158 memset(
new, 0, type_size);
165 # define talloc_zero_pooled_object(_ctx, _type, _num_subobjects, _total_subobjects_size) \
166 talloc_zero(_ctx, _type)
167 #undef talloc_pooled_object
168 # define talloc_pooled_object(_ctx, _type, _num_subobjects, _total_subobjects_size) \
187 char *
talloc_bstr_append(TALLOC_CTX *ctx,
char *to,
char const *from,
size_t from_len);
223 #define talloc_list_free(_head) _talloc_list_free((void **)_head, offsetof(__typeof__(**(_head)), next))
230 n = *((
void **)(((
uint8_t *)(v)) + offset));
242 #ifndef TALLOC_GET_TYPE_ABORT_NOOP
243 # define talloc_list_get_type_abort(_head, _type) (_type *)_talloc_list_get_type_abort(_head, offsetof(__typeof__(*(_head)), next), #_type, __location__)
248 if (!v) _talloc_get_type_abort(v,
type, location);
251 n = *((
void **)(((
uint8_t *)(v)) + offset));
252 _talloc_get_type_abort(v,
type, location);
259 # define talloc_list_get_type_abort(_head, _type) (_type *)(_head)
267 #ifdef TALLOC_GET_TYPE_ABORT_NOOP
268 # define talloc_get_type_abort_const(ptr, type) (const type *)(ptr)
270 # define talloc_get_type_abort_const talloc_get_type_abort
280 return talloc_array_length(our_s) - 1;
static int const char * fmt
#define UNCONST(_type, _ptr)
Remove const qualification from a pointer.
static size_t array[MY_ARRAY_SIZE]
fr_aka_sim_id_type_t type
Functions which we wish were included in the standard talloc distribution.
TALLOC_CTX * talloc_autofree_context_thread_local(void)
Get a thread-safe autofreed ctx that will be freed when the thread or process exits.
char * talloc_bstrdup(TALLOC_CTX *ctx, char const *in)
Binary safe strdup function.
TALLOC_CHILD_CTX * talloc_child_ctx_init(TALLOC_CTX *ctx)
Allocate and initialize a TALLOC_CHILD_CTX.
#define talloc_get_type_abort_const
TALLOC_CTX * talloc_page_aligned_pool(TALLOC_CTX *ctx, void **start, void **end, size_t size)
Return a page aligned talloc memory pool.
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_typed_strdup(TALLOC_CTX *ctx, char const *p)
Call talloc_strdup, setting the type on the new chunk correctly.
char * talloc_buffer_append_variadic_buffer(TALLOC_CTX *ctx, char *to, int argc,...)
Concatenate to + ...
static int talloc_const_free(void const *ptr)
Free const'd memory.
void * talloc_null_ctx(void)
Retrieve the current talloc NULL ctx.
char * talloc_typed_vasprintf(TALLOC_CTX *ctx, char const *fmt, va_list ap))
Call talloc vasprintf, setting the type on the new chunk correctly.
char * talloc_buffer_append_buffer(TALLOC_CTX *ctx, char *to, char const *from)
Concatenate to + from.
fr_slen_t talloc_array_concat(fr_sbuff_t *out, char const *const *array, char const *sep)
Concat an array of strings (not NULL terminated), with a string separator.
char * talloc_bstrndup(TALLOC_CTX *ctx, char const *in, size_t inlen)
Binary safe strndup function.
int talloc_memcmp_array(uint8_t const *a, uint8_t const *b)
Compares two talloced uint8_t arrays with memcmp.
TALLOC_CHILD_CTX * talloc_child_ctx_alloc(TALLOC_CHILD_CTX *parent)
Allocate a TALLOC_CHILD_CTX from a parent.
TALLOC_CTX * talloc_autofree_context_global(void)
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 void _talloc_list_free(void **head, size_t offset)
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.
char * talloc_bstr_append(TALLOC_CTX *ctx, char *to, char const *from, size_t from_len)
Append a bstr to a bstr.
char * talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt,...))
Call talloc vasprintf, setting the type on the new chunk correctly.
char * talloc_typed_strdup_buffer(TALLOC_CTX *ctx, char const *p)
Call talloc_strndup, setting the type on the new chunk correctly.
void ** talloc_array_null_strip(void **array)
Remove a NULL termination pointer from an array of pointers.
static void * _talloc_list_get_type_abort(void *head, size_t offset, char const *type, char const *location)
TALLOC_CTX * talloc_aligned_array(TALLOC_CTX *ctx, void **start, size_t alignment, size_t size)
Return a page aligned talloc memory array.
void ** talloc_array_null_terminate(void **array)
Add a NULL pointer to an array of pointers.
fr_talloc_destructor_t * d
Destructor to disarm.
static TALLOC_CTX * talloc_init_const(char const *name)
Allocate a top level chunk with a constant name.
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.
void * uctx
uctx to pass to free function.
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)
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.
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.
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
int format(printf, 5, 0))
static size_t char ** out