36#if (SAMBA_VERSION_MAJOR<4)
58#if !defined(__BEOS__) && __GNUC__ > 2
69#define ALWAYS_REALLOC 0
72#define MAX_TALLOC_SIZE 0x10000000
73#define TALLOC_MAGIC 0xe814ec70
74#define TALLOC_FLAG_FREE 0x01
75#define TALLOC_FLAG_LOOP 0x02
76#define TALLOC_MAGIC_REFERENCE ((const char *)1)
81#define TALLOC_ABORT(reason) abort()
84#ifndef discard_const_p
85#if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T)
86# define discard_const_p(type, ptr) ((type *)((intptr_t)(ptr)))
88# define discard_const_p(type, ptr) ((type *)(ptr))
96#define likely(x) __builtin_expect(!!(x), 1)
97#define unlikely(x) __builtin_expect(!!(x), 0)
128#define TC_HDR_SIZE ((sizeof(struct talloc_chunk)+15)&~15)
129#define TC_PTR_FROM_CHUNK(tc) ((void *)(TC_HDR_SIZE + (char*)tc))
134 const void *pp = ((
const char *)ptr) -
TC_HDR_SIZE;
147#define _TLIST_ADD(list, p) \
151 (p)->next = (p)->prev = NULL; \
153 (list)->prev = (p); \
154 (p)->next = (list); \
161#define _TLIST_REMOVE(list, p) \
163 if ((p) == (list)) { \
164 (list) = (p)->next; \
165 if (list) (list)->prev = NULL; \
167 if ((p)->prev) (p)->prev->next = (p)->next; \
168 if ((p)->next) (p)->next->prev = (p)->prev; \
170 if ((p) && ((p) != (list))) (p)->next = (p)->prev = NULL; \
203 return tc? tc->
name : NULL;
222 if (
unlikely(tc == NULL))
return NULL;
235 parent->child->parent = NULL;
332 if (
unlikely(handle == NULL))
return NULL;
506 if (context == NULL)
break;
531 if (context == NULL) {
539 if (context == NULL) {
551 if (tc_p->
refs == NULL) {
612 if (
unlikely(ptr == NULL))
return NULL;
649 if (
unlikely(ptr == NULL))
return NULL;
675 if (
unlikely(ptr == NULL))
return NULL;
811 tc->
flags &= ~TALLOC_FLAG_FREE;
816 tc->
flags &= ~TALLOC_FLAG_FREE;
877 tc->
flags &= ~TALLOC_FLAG_LOOP;
901 tc->
flags &= ~TALLOC_FLAG_LOOP;
925 void (*callback)(
const void *
ptr,
926 int depth,
int max_depth,
936 if (ptr == NULL)
return;
944 callback(ptr, depth, max_depth, 0, private_data);
946 if (max_depth >= 0 && depth >= max_depth) {
954 callback(h->
ptr, depth + 1, max_depth, 1, private_data);
959 tc->
flags &= ~TALLOC_FLAG_LOOP;
965 FILE *f = (FILE *)_f;
968 fprintf(f,
"%*sreference to: %s\n", depth*4,
"", name);
973 fprintf(f,
"%stalloc report on '%s' (total %6lu bytes in %3lu blocks)\n",
974 (max_depth < 0 ?
"full " :
""), name,
980 fprintf(f,
"%*s%-30s contains %6lu bytes in %3lu blocks (ref %d) %p\n",
988 fprintf(f,
"content: ");
993 for (i = 0; i < tot; i++) {
994 if ((((
char *)
ptr)[i] > 31) && (((
char *)
ptr)[i] < 126)) {
995 fprintf(f,
"%c", ((
char *)
ptr)[i]);
997 fprintf(f,
"~%02x", ((
char *)
ptr)[i]);
1095 memset(p,
'\0', size);
1109 memcpy(newp, p, size);
1137 size_t olen = strlen(orig);
1143 alenz = strlen(append) + 1;
1150 memcpy(&ret[olen], append, alenz);
1165 for (len=0; len<n && p[len]; len++) ;
1167 ret = (
char *)
__talloc(t, len + 1);
1168 if (!ret) {
return NULL; }
1169 memcpy(ret, p, len);
1176#ifdef HAVE___VA_COPY
1177#define va_copy(dest, src) __va_copy(dest, src)
1179#define va_copy(dest, src) (dest) = (src)
1192 len = vsnprintf(&c, 1, fmt, ap2);
1201 vsnprintf(ret, len+1, fmt, ap2);
1244 s_len = tc->
size - 1;
1247 len = vsnprintf(&c, 1, fmt, ap2);
1261 if (!s)
return NULL;
1264 vsnprintf(s+s_len, len+1, fmt, ap2);
1359 if (context == NULL)
1374 if (context == NULL) {
1383 while (tc && tc->
prev) tc = tc->
prev;
1398 if (context == NULL) {
1399 fprintf(file,
"talloc no parents for NULL\n");
1407 while (tc && tc->
prev) tc = tc->
prev;
1422 if (context == NULL) {
1429 while (tc && tc->
prev) tc = tc->
prev;
static uint32_t count(const http_directive *list, lwc_string *key)
Interface to utility string handling.
struct talloc_reference_handle * refs
struct talloc_chunk * prev
struct talloc_chunk * next
talloc_destructor_t destructor
struct talloc_chunk * child
struct talloc_chunk * parent
struct talloc_reference_handle * prev
struct talloc_reference_handle * next
void * _talloc_move(const void *new_ctx, const void *_pptr)
void * talloc_named_const(const void *context, size_t size, const char *name)
#define TALLOC_MAGIC_REFERENCE
char * talloc_asprintf(const void *t, const char *fmt,...)
void * _talloc_realloc_array(const void *ctx, void *ptr, size_t el_size, unsigned count, const char *name)
void * _talloc_zero(const void *ctx, size_t size, const char *name)
void talloc_report_depth_file(const void *ptr, int depth, int max_depth, FILE *f)
#define va_copy(dest, src)
int talloc_increase_ref_count(const void *ptr)
const char * talloc_parent_name(const void *ptr)
void talloc_set_name_const(const void *ptr, const char *name)
char * talloc_asprintf_append(char *s, const char *fmt,...)
void talloc_disable_null_tracking(void)
static int talloc_unreference(const void *context, const void *ptr)
void * _talloc_reference(const void *context, const void *ptr)
int talloc_free(void *ptr)
char * talloc_strndup(const void *t, const char *p, size_t n)
void * talloc_find_parent_byname(const void *context, const char *name)
#define _TLIST_REMOVE(list, p)
void * _talloc_memdup(const void *t, const void *p, size_t size, const char *name)
void * _talloc_steal(const void *new_ctx, const void *ptr)
void * _talloc_realloc(const void *context, void *ptr, size_t size, const char *name)
void * talloc_realloc_fn(const void *context, void *ptr, size_t size)
static void talloc_report_null(void)
void * talloc_init(const char *fmt,...)
char * talloc_vasprintf_append(char *s, const char *fmt, va_list ap)
Realloc s to append the formatted result of fmt and ap, and return s, which may have moved.
static int _talloc_free(void *ptr)
char * talloc_append_string(const void *t, char *orig, const char *append)
void talloc_report(const void *ptr, FILE *f)
static struct talloc_chunk * talloc_parent_chunk(const void *ptr)
#define TALLOC_ABORT(reason)
void * talloc_autofree_context(void)
void talloc_report_depth_cb(const void *ptr, int depth, int max_depth, void(*callback)(const void *ptr, int depth, int max_depth, int is_ref, void *private_data), void *private_data)
void talloc_report_full(const void *ptr, FILE *f)
void * _talloc(const void *context, size_t size)
static int talloc_reference_destructor(struct talloc_reference_handle *handle)
void * _talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const char *name)
const char * talloc_set_name(const void *ptr, const char *fmt,...)
void * talloc_parent(const void *ptr)
int talloc_is_parent(const void *context, const void *ptr)
size_t talloc_total_size(const void *ptr)
int talloc_unlink(const void *context, void *ptr)
const char * talloc_get_name(const void *ptr)
static void talloc_report_depth_FILE_helper(const void *ptr, int depth, int max_depth, int is_ref, void *_f)
char * talloc_vasprintf(const void *t, const char *fmt, va_list ap)
void * talloc_named(const void *context, size_t size, const char *fmt,...)
void talloc_free_children(void *ptr)
void * _talloc_array(const void *ctx, size_t el_size, unsigned count, const char *name)
void talloc_enable_leak_report_full(void)
static int talloc_autofree_destructor(void *ptr)
#define discard_const_p(type, ptr)
static void * _talloc_named_const(const void *context, size_t size, const char *name)
void talloc_show_parents(const void *context, FILE *file)
size_t talloc_total_blocks(const void *ptr)
#define _TLIST_ADD(list, p)
static void * null_context
static void _talloc_set_name_const(const void *ptr, const char *name)
static void * __talloc(const void *context, size_t size)
void talloc_enable_leak_report(void)
size_t talloc_reference_count(const void *ptr)
static void * autofree_context
int(* talloc_destructor_t)(void *)
void talloc_enable_null_tracking(void)
void _talloc_set_destructor(const void *ptr, int(*destructor)(void *))
static void talloc_report_null_full(void)
size_t talloc_get_size(const void *context)
#define TC_PTR_FROM_CHUNK(tc)
static struct talloc_chunk * talloc_chunk_from_ptr(const void *ptr)
static const char * talloc_set_name_v(const void *ptr, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2
char * talloc_strdup(const void *t, const char *p)
static void talloc_autofree(void)
void * talloc_check_name(const void *ptr, const char *name)
#define talloc_realloc(ctx, p, type, count)
#define talloc_steal(ctx, ptr)
#define talloc_memdup(t, p, size)
#define talloc_reference(ctx, ptr)
#define talloc_set_destructor(ptr, function)
#define PRINTF_ATTRIBUTE(a1, a2)
Version information interface.