25 RCSIDH(talloc_h,
"$Id: 5671361c5430390cfee2378bb658ab56c569b211 $")
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);
132 for (p = str, q = p + (talloc_array_length(str) - 1); p < q; p++) *p = tolower((
uint8_t) *p);
147 TALLOC_CTX *
talloc_page_aligned_pool(TALLOC_CTX *ctx,
void **start,
size_t *end_len,
unsigned int headers,
size_t size);
153 #if defined(HAVE__TALLOC_POOLED_OBJECT) && defined(talloc_pooled_object)
154 # define HAVE_TALLOC_ZERO_POOLED_OBJECT 1
155 # define HAVE_TALLOC_POOLED_OBJECT 1
157 # define talloc_zero_pooled_object(_ctx, _type, _num_subobjects, _total_subobjects_size) \
158 (_type *)_talloc_zero_pooled_object((_ctx), sizeof(_type), #_type, \
159 (_num_subobjects), (_total_subobjects_size))
161 static inline TALLOC_CTX *_talloc_zero_pooled_object(
const void *ctx,
163 const char *type_name,
164 unsigned num_subobjects,
165 size_t total_subobjects_size)
168 new = _talloc_pooled_object(ctx, type_size, type_name, num_subobjects, total_subobjects_size);
170 memset(
new, 0, type_size);
177 # define talloc_zero_pooled_object(_ctx, _type, _num_subobjects, _total_subobjects_size) \
178 talloc_zero(_ctx, _type)
179 #undef talloc_pooled_object
180 # define talloc_pooled_object(_ctx, _type, _num_subobjects, _total_subobjects_size) \
199 char *
talloc_bstr_append(TALLOC_CTX *ctx,
char *to,
char const *from,
size_t from_len);
235 #define talloc_list_free(_head) _talloc_list_free((void **)_head, offsetof(__typeof__(**(_head)), next))
242 n = *((
void **)(((
uint8_t *)(v)) + offset));
254 #ifndef TALLOC_GET_TYPE_ABORT_NOOP
255 # define talloc_list_get_type_abort(_head, _type) (_type *)_talloc_list_get_type_abort(_head, offsetof(__typeof__(*(_head)), next), #_type, __location__)
260 if (!v) _talloc_get_type_abort(v,
type, location);
263 n = *((
void **)(((
uint8_t *)(v)) + offset));
264 _talloc_get_type_abort(v,
type, location);
271 # define talloc_list_get_type_abort(_head, _type) (_type *)(_head)
279 #ifdef TALLOC_GET_TYPE_ABORT_NOOP
280 # define talloc_get_type_abort_const(ptr, type) (const type *)(ptr)
282 # define talloc_get_type_abort_const talloc_get_type_abort
292 return talloc_array_length(our_s) - 1;
static int const char * fmt
#define UNCONST(_type, _ptr)
Remove const qualification from a pointer.
fr_dcursor_eval_t void const * uctx
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
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.
ssize_t talloc_hdr_size(void)
Calculate the size of the talloc chunk header.
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.
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.
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)
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.
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