same underlying data, and you want to be able to free the two instances separately,
and in either order
*/
-void *_talloc_reference(const void *context, const void *ptr, const char *location)
+void *_talloc_reference_loc(const void *context, const void *ptr, const char *location)
{
struct talloc_chunk *tc;
struct talloc_reference_handle *handle;
return handle->ptr;
}
+static void *_talloc_steal_internal(const void *new_ctx, const void *ptr);
/*
internal talloc_free call
ptr on success, or NULL if it could not be transferred.
passing NULL as ptr will always return NULL with no side effects.
*/
-void *_talloc_steal_internal(const void *new_ctx, const void *ptr)
+static void *_talloc_steal_internal(const void *new_ctx, const void *ptr)
{
struct talloc_chunk *tc, *new_tc;
return discard_const_p(void, ptr);
}
-
/*
move a lump of memory from one talloc context to another return the
ptr on success, or NULL if it could not be transferred.
passing NULL as ptr will always return NULL with no side effects.
*/
-void *_talloc_steal(const void *new_ctx, const void *ptr, const char *location)
+void *_talloc_steal_loc(const void *new_ctx, const void *ptr, const char *location)
{
struct talloc_chunk *tc;
if (unlikely(tc->refs != NULL) && talloc_parent(ptr) != new_ctx) {
struct talloc_reference_handle *h;
+#if DEVELOPER
fprintf(stderr, "ERROR: talloc_steal with references at %s\n", location);
+#endif
for (h=tc->refs; h; h=h->next) {
+#if DEVELOPER
fprintf(stderr, "\treference at %s\n", h->location);
+#endif
}
return NULL;
}
if (unlikely(tc->refs != NULL)) {
struct talloc_reference_handle *h;
+#if DEVELOPER
fprintf(stderr, "ERROR: talloc_free with references at %s\n", location);
+#endif
for (h=tc->refs; h; h=h->next) {
+#if DEVELOPER
fprintf(stderr, "\treference at %s\n", h->location);
+#endif
}
return -1;
}
}
return 0;
}
+
+
+
+
+/* ABI compat functions (do NOT append anything beyond thess functions,
+ * keep them as the last ones in the file) */
+
+static const char *talloc_ABI_compat_location = "Called from compatibility function";
+
+/* ABI compat function (don't use) */
+void *_talloc_reference(const void *context, const void *ptr) {
+ return _talloc_reference_loc(context, ptr, talloc_ABI_compat_location);
+}
+
+/* ABI compat function (don't use) */
+void *_talloc_steal(const void *new_ctx, const void *ptr)
+{
+ return _talloc_steal_internal(new_ctx, ptr);
+}
+
+#undef talloc_free
+int talloc_free(void *ptr)
+{
+ return _talloc_free_internal(ptr);
+}
+
+/* DO NOT APPEND ANYTHING BEYOND THIS POINT */
} while(0)
/* this extremely strange macro is to avoid some braindamaged warning
stupidity in gcc 4.1.x */
-#define talloc_steal(ctx, ptr) ({ _TALLOC_TYPEOF(ptr) __talloc_steal_ret = (_TALLOC_TYPEOF(ptr))_talloc_steal((ctx),(ptr), __location__); __talloc_steal_ret; })
+#define talloc_steal(ctx, ptr) ({ _TALLOC_TYPEOF(ptr) __talloc_steal_ret = (_TALLOC_TYPEOF(ptr))_talloc_steal_loc((ctx),(ptr), __location__); __talloc_steal_ret; })
#else
#define talloc_set_destructor(ptr, function) \
_talloc_set_destructor((ptr), (int (*)(void *))(function))
#define _TALLOC_TYPEOF(ptr) void *
-#define talloc_steal(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_steal((ctx),(ptr), __location__)
+#define talloc_steal(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_steal_loc((ctx),(ptr), __location__)
#endif
-#define talloc_reference(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_reference((ctx),(ptr), __location__)
+#define talloc_reference(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_reference_loc((ctx),(ptr), __location__)
#define talloc_move(ctx, ptr) (_TALLOC_TYPEOF(*(ptr)))_talloc_move((ctx),(void *)(ptr))
/* useful macros for creating type checked pointers */
void _talloc_set_destructor(const void *ptr, int (*_destructor)(void *));
int talloc_increase_ref_count(const void *ptr);
size_t talloc_reference_count(const void *ptr);
-void *_talloc_reference(const void *context, const void *ptr, const char *location);
+void *_talloc_reference_loc(const void *context, const void *ptr, const char *location);
int talloc_unlink(const void *context, void *ptr);
const char *talloc_set_name(const void *ptr, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
void talloc_set_name_const(const void *ptr, const char *name);
int _talloc_free(void *ptr, const char *location);
void talloc_free_children(void *ptr);
void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *name);
-void *_talloc_steal(const void *new_ctx, const void *ptr, const char *location);
-void *_talloc_steal_internal(const void *new_ctx, const void *ptr);
+void *_talloc_steal_loc(const void *new_ctx, const void *ptr, const char *location);
void *talloc_reparent(const void *old_parent, const void *new_parent, const void *ptr);
void *_talloc_move(const void *new_ctx, const void *pptr);
size_t talloc_total_size(const void *ptr);
void talloc_set_abort_fn(void (*abort_fn)(const char *reason));
+/* for ABI compatibility, never use in new code */
+void *_talloc_reference(const void *context, const void *ptr);
+void *_talloc_steal(const void *new_ctx, const void *ptr);
#endif
-void *_talloc (const void *, size_t);
-void *talloc_pool (const void *, size_t);
-void _talloc_set_destructor (const void *, int (*) (void *));
+char *talloc_asprintf_append_buffer (char *, const char *, ...);
+char *talloc_asprintf_append (char *, const char *, ...);
+char *talloc_asprintf (const void *, const char *, ...);
+char *talloc_strdup_append_buffer (char *, const char *);
+char *talloc_strdup_append (char *, const char *);
+char *talloc_strdup (const void *, const char *);
+char *talloc_strndup_append_buffer (char *, const char *, size_t);
+char *talloc_strndup_append (char *, const char *, size_t);
+char *talloc_strndup (const void *, const char *, size_t);
+char *talloc_vasprintf_append_buffer (char *, const char *, va_list);
+char *talloc_vasprintf_append (char *, const char *, va_list);
+char *talloc_vasprintf (const void *, const char *, va_list);
+const char *talloc_get_name (const void *);
+const char *talloc_parent_name (const void *);
+const char *talloc_set_name (const void *, const char *, ...);
+int _talloc_free (void *, const char *);
int talloc_increase_ref_count (const void *);
-size_t talloc_reference_count (const void *);
-void *_talloc_reference (const void *, const void *);
+int talloc_is_parent (const void *, const void *);
int talloc_unlink (const void *, void *);
-const char *talloc_set_name (const void *, const char *, ...);
-void talloc_set_name_const (const void *, const char *);
-void *talloc_named (const void *, size_t, const char *, ...);
-void *talloc_named_const (const void *, size_t, const char *);
-const char *talloc_get_name (const void *);
+size_t talloc_get_size (const void *);
+size_t talloc_reference_count (const void *);
+size_t talloc_total_blocks (const void *);
+size_t talloc_total_size (const void *);
+void *_talloc_array (const void *, size_t, unsigned int, const char *);
+void *talloc_autofree_context (void);
void *talloc_check_name (const void *, const char *);
+void *_talloc (const void *, size_t);
+void talloc_disable_null_tracking (void);
+void talloc_enable_leak_report_full (void);
+void talloc_enable_leak_report (void);
+void talloc_enable_null_tracking (void);
+void *talloc_find_parent_byname (const void *, const char *);
+void talloc_free_children (void *);
void *_talloc_get_type_abort (const void *, const char *, const char *);
-void *talloc_parent (const void *);
-const char *talloc_parent_name (const void *);
void *talloc_init (const char *, ...);
-int talloc_free (void *);
-void talloc_free_children (void *);
-void *_talloc_realloc (const void *, void *, size_t, const char *);
-void *_talloc_steal (const void *, const void *);
+void *_talloc_memdup (const void *, const void *, size_t, const char *);
void *_talloc_move (const void *, const void *);
-size_t talloc_total_size (const void *);
-size_t talloc_total_blocks (const void *);
+void *talloc_named_const (const void *, size_t, const char *);
+void *talloc_named (const void *, size_t, const char *, ...);
+void *talloc_parent (const void *);
+void *talloc_pool (const void *, size_t);
+void *_talloc_realloc_array (const void *, void *, size_t, unsigned int, const char *);
+void *_talloc_realloc (const void *, void *, size_t, const char *);
+void *talloc_realloc_fn (const void *, void *, size_t);
+void *_talloc_reference (const void *, const void *);
+void *_talloc_reference_loc (const void *, const void *, const char *);
+void *talloc_reparent (const void *, const void *, const void *);
+void talloc_report (const void *, FILE *);
void talloc_report_depth_cb (const void *, int, int, void (*) (const void *, int, int, int, void *), void *);
void talloc_report_depth_file (const void *, int, int, FILE *);
void talloc_report_full (const void *, FILE *);
-void talloc_report (const void *, FILE *);
-void talloc_enable_null_tracking (void);
-void talloc_disable_null_tracking (void);
-void talloc_enable_leak_report (void);
-void talloc_enable_leak_report_full (void);
-void *_talloc_zero (const void *, size_t, const char *);
-void *_talloc_memdup (const void *, const void *, size_t, const char *);
-void *_talloc_array (const void *, size_t, unsigned int, const char *);
-void *_talloc_zero_array (const void *, size_t, unsigned int, const char *);
-void *_talloc_realloc_array (const void *, void *, size_t, unsigned int, const char *);
-void *talloc_realloc_fn (const void *, void *, size_t);
-void *talloc_autofree_context (void);
-size_t talloc_get_size (const void *);
-void *talloc_find_parent_byname (const void *, const char *);
-void talloc_show_parents (const void *, FILE *);
-int talloc_is_parent (const void *, const void *);
-char *talloc_strdup (const void *, const char *);
-char *talloc_strdup_append (char *, const char *);
-char *talloc_strdup_append_buffer (char *, const char *);
-char *talloc_strndup (const void *, const char *, size_t);
-char *talloc_strndup_append (char *, const char *, size_t);
-char *talloc_strndup_append_buffer (char *, const char *, size_t);
-char *talloc_vasprintf (const void *, const char *, __va_list_tag *);
-char *talloc_vasprintf_append (char *, const char *, __va_list_tag *);
-char *talloc_vasprintf_append_buffer (char *, const char *, __va_list_tag *);
-char *talloc_asprintf (const void *, const char *, ...);
-char *talloc_asprintf_append (char *, const char *, ...);
-char *talloc_asprintf_append_buffer (char *, const char *, ...);
void talloc_set_abort_fn (void (*) (const char *));
+void _talloc_set_destructor (const void *, int (*) (void *));
+void talloc_set_name_const (const void *, const char *);
+void talloc_show_parents (const void *, FILE *);
+void *_talloc_steal (const void *, const void *);
+void *_talloc_steal_loc (const void *, const void *, const char *);
+void *_talloc_zero_array (const void *, size_t, unsigned int, const char *);
+void *_talloc_zero (const void *, size_t, const char *);