diff options
author | Andrew Tridgell <tridge@samba.org> | 2009-07-01 14:53:01 +1000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2009-07-01 15:15:37 +1000 |
commit | 5fe1d8dc1275e43d96da1297f5fb0d0088a1c3ab (patch) | |
tree | ca520776101c3ff64fa76d01d088c565ea265d5a /lib/talloc/talloc.h | |
parent | 6a192020a230ab8e085f32b5559c0fe0d2f5c1a4 (diff) | |
download | samba-5fe1d8dc1275e43d96da1297f5fb0d0088a1c3ab.tar.gz samba-5fe1d8dc1275e43d96da1297f5fb0d0088a1c3ab.tar.bz2 samba-5fe1d8dc1275e43d96da1297f5fb0d0088a1c3ab.zip |
changes to remove the ambiguity in talloc_free() and talloc_steal()
These changes follow from the discussions on samba-technical. The
changes are in several parts, and stem from the inherent ambiguity
that was in talloc_free() and talloc_steal() when the pointer that is
being changes has more than one parent, via references.
The changes are:
1) when you call talloc_free() on a pointer with more than one parent
the free will fail, and talloc will log an error to stderr like this:
ERROR: talloc_free with references at some/foo.c:123
reference at other/bar.c:201
reference at other/foobar.c:641
2) Similarly, when you call talloc_steal() on a pointer with more
than one parent, the steal will fail and talloc will log an error to
stderr like this:
ERROR: talloc_steal with references at some/foo.c:123
reference at other/bar.c:201
3) A new function talloc_reparent() has been added to change a parent
in a controlled fashion. You need to supply both the old parent and
the new parent. It handles the case whether either the old parent was
a normal parent or a reference
The use of stderr in the logging is ugly (and potentially dangerous),
and will be removed in a future patch. We'll need to add a debug
registration function to talloc.
Diffstat (limited to 'lib/talloc/talloc.h')
-rw-r--r-- | lib/talloc/talloc.h | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/talloc/talloc.h b/lib/talloc/talloc.h index a4b33c3ed4..9d1aa0df04 100644 --- a/lib/talloc/talloc.h +++ b/lib/talloc/talloc.h @@ -69,15 +69,15 @@ typedef void TALLOC_CTX; } 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)); __talloc_steal_ret; }) +#define talloc_steal(ctx, ptr) ({ _TALLOC_TYPEOF(ptr) __talloc_steal_ret = (_TALLOC_TYPEOF(ptr))_talloc_steal((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)) +#define talloc_steal(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_steal((ctx),(ptr), __location__) #endif -#define talloc_reference(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_reference((ctx),(ptr)) +#define talloc_reference(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_reference((ctx),(ptr), __location__) #define talloc_move(ctx, ptr) (_TALLOC_TYPEOF(*(ptr)))_talloc_move((ctx),(void *)(ptr)) /* useful macros for creating type checked pointers */ @@ -106,6 +106,8 @@ typedef void TALLOC_CTX; #define talloc_get_type_abort(ptr, type) (type *)_talloc_get_type_abort(ptr, #type, __location__) #define talloc_find_parent_bytype(ptr, type) (type *)talloc_find_parent_byname(ptr, #type) +#define talloc_free(ctx) _talloc_free(ctx, __location__) + #if TALLOC_DEPRECATED #define talloc_zero_p(ctx, type) talloc_zero(ctx, type) @@ -124,7 +126,7 @@ void *talloc_pool(const void *context, size_t size); 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); +void *_talloc_reference(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); @@ -137,10 +139,12 @@ void *_talloc_get_type_abort(const void *ptr, const char *name, const char *loca void *talloc_parent(const void *ptr); const char *talloc_parent_name(const void *ptr); void *talloc_init(const char *fmt, ...) PRINTF_ATTRIBUTE(1,2); -int talloc_free(void *ptr); +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); +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_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); size_t talloc_total_blocks(const void *ptr); |