From 1a5978445199a1d8697a5604761899aa065059fe Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Sep 2006 00:05:07 +0000 Subject: r18435: added a function talloc_move() which is like talloc_steal(), but is meant for moving pointers between structures. The difference is that talloc_move() will zero the source pointer, thus ensuring you don't reference the pointer in the old context. talloc_move() is appropriate in some, but not all cases where we use talloc_steal() now. The interface came out of a discussion with Jeremy. (This used to be commit 200756017e1867faa207703eddc00a75ae4527df) --- source4/lib/talloc/talloc.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source4/lib/talloc/talloc.h') diff --git a/source4/lib/talloc/talloc.h b/source4/lib/talloc/talloc.h index fdc0fd3494..b9ecd8f0b8 100644 --- a/source4/lib/talloc/talloc.h +++ b/source4/lib/talloc/talloc.h @@ -65,15 +65,16 @@ typedef void TALLOC_CTX; /* 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_reference(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_reference((ctx),(ptr)) #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_reference(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_reference((ctx),(ptr)) #endif +#define talloc_reference(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_reference((ctx),(ptr)) +#define talloc_move(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_move((ctx),&(ptr)) + /* useful macros for creating type checked pointers */ #define talloc(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #type) #define talloc_size(ctx, size) talloc_named_const(ctx, size, __location__) @@ -127,6 +128,7 @@ int talloc_free(void *ptr); 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_move(const void *new_ctx, const void **pptr); size_t talloc_total_size(const void *ptr); size_t talloc_total_blocks(const void *ptr); void talloc_report_depth_cb(const void *ptr, int depth, int max_depth, -- cgit