svn commit: samba r7781 - in branches/SAMBA_4_0/source/lib/talloc: .
tridge at samba.org
tridge at samba.org
Mon Jun 20 06:15:36 GMT 2005
Author: tridge
Date: 2005-06-20 06:15:35 +0000 (Mon, 20 Jun 2005)
New Revision: 7781
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=7781
Log:
finding the parent of a talloc ptr is trickier than it looks due to the two-way
tree nature of the data structure. I think I've finally got it right
also added talloc_show_parents() for debugging
Modified:
branches/SAMBA_4_0/source/lib/talloc/talloc.c
branches/SAMBA_4_0/source/lib/talloc/talloc.h
Changeset:
Modified: branches/SAMBA_4_0/source/lib/talloc/talloc.c
===================================================================
--- branches/SAMBA_4_0/source/lib/talloc/talloc.c 2005-06-20 05:21:11 UTC (rev 7780)
+++ branches/SAMBA_4_0/source/lib/talloc/talloc.c 2005-06-20 06:15:35 UTC (rev 7781)
@@ -1121,14 +1121,33 @@
}
tc = talloc_chunk_from_ptr(context);
- while (tc->prev) {
- tc = tc->prev;
+ while (tc) {
+ if (tc->name && strcmp(tc->name, name) == 0) {
+ return (void*)(tc+1);
+ }
+ while (tc && tc->prev) tc = tc->prev;
+ tc = tc->parent;
}
- while (tc->parent && (!tc->name || strcmp(tc->name, name))) {
+ return NULL;
+}
+
+/*
+ show the parentage of a context
+*/
+void talloc_show_parents(const void *context, FILE *file)
+{
+ struct talloc_chunk *tc;
+
+ if (context == NULL) {
+ fprintf(file, "talloc no parents for NULL\n");
+ return;
+ }
+
+ tc = talloc_chunk_from_ptr(context);
+ fprintf(file, "talloc parents of '%s'\n", talloc_get_name(context));
+ while (tc) {
+ fprintf(file, "\t'%s'\n", talloc_get_name(tc+1));
+ while (tc && tc->prev) tc = tc->prev;
tc = tc->parent;
}
- if (tc == NULL || tc->name == NULL || strcmp(tc->name, name)) {
- return NULL;
- }
- return (void *)(tc+1);
}
Modified: branches/SAMBA_4_0/source/lib/talloc/talloc.h
===================================================================
--- branches/SAMBA_4_0/source/lib/talloc/talloc.h 2005-06-20 05:21:11 UTC (rev 7780)
+++ branches/SAMBA_4_0/source/lib/talloc/talloc.h 2005-06-20 06:15:35 UTC (rev 7781)
@@ -130,6 +130,7 @@
void *talloc_autofree_context(void);
size_t talloc_get_size(const void *ctx);
void *talloc_find_parent_byname(const void *ctx, const char *name);
+void talloc_show_parents(const void *context, FILE *file);
#endif
More information about the samba-cvs
mailing list