diff options
author | Andrew Tridgell <tridge@samba.org> | 2006-09-13 00:05:07 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:18:29 -0500 |
commit | 1a5978445199a1d8697a5604761899aa065059fe (patch) | |
tree | 7d6dd6ac85243bc6b20d8bed7455f1d02a54cbf6 /source4/lib/talloc/testsuite.c | |
parent | d21cb7e2d29a8c496bb139b5f8086949305e76a2 (diff) | |
download | samba-1a5978445199a1d8697a5604761899aa065059fe.tar.gz samba-1a5978445199a1d8697a5604761899aa065059fe.tar.bz2 samba-1a5978445199a1d8697a5604761899aa065059fe.zip |
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)
Diffstat (limited to 'source4/lib/talloc/testsuite.c')
-rw-r--r-- | source4/lib/talloc/testsuite.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 2faa6d64c4..38039c11bf 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -731,6 +731,40 @@ static bool test_steal(void) } /* + test move +*/ +static bool test_move(void) +{ + void *root; + struct t_move { + char *p; + int *x; + } *t1, *t2; + printf("TESTING MOVE\n"); + + root = talloc_new(NULL); + + t1 = talloc(root, struct t_move); + t2 = talloc(root, struct t_move); + t1->p = talloc_strdup(t1, "foo"); + t1->x = talloc(t1, int); + *t1->x = 42; + + t2->p = talloc_move(t2, t1->p); + t2->x = talloc_move(t2, t1->x); + if (t1->p != NULL || t1->x != NULL || + strcmp(t2->p, "foo") || + *t2->x != 42) { + printf("talloc move failed\n"); + return false; + } + + talloc_free(root); + + return true; +} + +/* test talloc_realloc_fn */ static bool test_realloc_fn(void) @@ -1022,6 +1056,7 @@ bool torture_local_talloc(struct torture_context *torture) ret &= test_realloc(); ret &= test_realloc_child(); ret &= test_steal(); + ret &= test_move(); ret &= test_unref_reparent(); ret &= test_realloc_fn(); ret &= test_type(); |