From cc55aef7c116d03ba2817625b0ba9edb378525e3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Jan 2005 02:32:43 +0000 Subject: r4547: - added talloc_new(ctx) macro that is a neater form of the common talloc(ctx, 0) call. - cleaned up some talloc usage in various files I'd like to get to the point that we have no calls to talloc(), at which point we will rename talloc_p() to talloc(), to encourage everyone to use the typesafe functions. (This used to be commit e6c81d7c9f8a6938947d3c1c8a971a0d6d50b67a) --- source4/lib/events.c | 2 +- source4/lib/ldb/ldb_ldap/ldb_ldap.c | 2 +- source4/lib/talloc/talloc.h | 1 + source4/lib/talloc/talloc_guide.txt | 9 +++++++++ source4/lib/talloc/testsuite.c | 4 ++-- 5 files changed, 14 insertions(+), 4 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/events.c b/source4/lib/events.c index 0ca6b66598..9f28100a26 100644 --- a/source4/lib/events.c +++ b/source4/lib/events.c @@ -85,7 +85,7 @@ struct event_context *event_context_init(TALLOC_CTX *mem_ctx) /* start off with no events */ ZERO_STRUCTP(ev); - ev->events = talloc(ev, 0); + ev->events = talloc_new(ev); return ev; } diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c index fee02da32f..bab3c86e16 100644 --- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c +++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c @@ -86,7 +86,7 @@ static int lldb_rename(struct ldb_module *module, const char *olddn, const char int ret = 0; char *newrdn, *p; const char *parentdn = ""; - TALLOC_CTX *mem_ctx = talloc(lldb, 0); + TALLOC_CTX *mem_ctx = talloc_new(lldb); /* ignore ltdb specials */ if (olddn[0] == '@' ||newdn[0] == '@') { diff --git a/source4/lib/talloc/talloc.h b/source4/lib/talloc/talloc.h index 9e828f2f0d..ee3e0be8eb 100644 --- a/source4/lib/talloc/talloc.h +++ b/source4/lib/talloc/talloc.h @@ -37,6 +37,7 @@ typedef void TALLOC_CTX; #define talloc_zero(ctx, size) _talloc_zero(ctx, size, __location__) #define talloc_realloc(ctx, ptr, size) _talloc_realloc(ctx, ptr, size, __location__) #define talloc_p(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #type) +#define talloc_new(ctx) talloc_named_const(ctx, 0, "talloc_new: " __location__) #define talloc_zero_p(ctx, type) (type *)_talloc_zero(ctx, sizeof(type), #type) #define talloc_zero_array_p(ctx, type, count) (type *)talloc_zero_array(ctx, sizeof(type), count, __location__) #define talloc_array_p(ctx, type, count) (type *)talloc_array(ctx, sizeof(type), count, __location__) diff --git a/source4/lib/talloc/talloc_guide.txt b/source4/lib/talloc/talloc_guide.txt index ce3c8bde68..aa37c60466 100644 --- a/source4/lib/talloc/talloc_guide.txt +++ b/source4/lib/talloc/talloc_guide.txt @@ -260,6 +260,15 @@ level context. It is equivalent to: talloc_named(NULL, 0, fmt, ...); +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- +void *talloc_new(void *ctx); + +This is a utility macro that creates a new memory context hanging +off an exiting context, automatically naming it "talloc_new: __location__" +where __location__ is the source line it is called from. It is +particularly useful for creating a new temporary working context. + + =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- void *talloc_realloc(const void *context, void *ptr, size_t size); diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 22444b1116..a3a448ef40 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -333,7 +333,7 @@ static BOOL test_misc(void) printf("TESTING MISCELLANEOUS\n"); - root = talloc(NULL, 0); + root = talloc_new(NULL); p1 = talloc(root, 0x7fffffff); if (p1) { @@ -515,7 +515,7 @@ static BOOL test_realloc(void) printf("TESTING REALLOC\n"); - root = talloc(NULL, 0); + root = talloc_new(NULL); p1 = talloc(root, 10); CHECK_SIZE(p1, 10); -- cgit