svn commit: samba r3366 - in branches/SAMBA_4_0: . source/lib

tridge at samba.org tridge at samba.org
Fri Oct 29 11:39:08 GMT 2004


Author: tridge
Date: 2004-10-29 11:39:08 +0000 (Fri, 29 Oct 2004)
New Revision: 3366

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=3366

Log:
updates from the junkcode version of talloc. 

The main change is to get rid of talloc_parent_chunk() from all
commonly used code paths, so talloc_free() is now O(1) again. It was
originally O(1), but the last round of changes broke that.

Also some documentation updates


Modified:
   branches/SAMBA_4_0/source/lib/talloc.c
   branches/SAMBA_4_0/talloc_guide.txt


Changeset:
Modified: branches/SAMBA_4_0/source/lib/talloc.c
===================================================================
--- branches/SAMBA_4_0/source/lib/talloc.c	2004-10-29 09:58:23 UTC (rev 3365)
+++ branches/SAMBA_4_0/source/lib/talloc.c	2004-10-29 11:39:08 UTC (rev 3366)
@@ -441,7 +441,7 @@
 
 	if (tc->refs) {
 		talloc_reference_destructor(tc->refs);
-		return 0;
+		return -1;
 	}
 
 	if (tc->destructor) {
@@ -469,11 +469,13 @@
 			struct talloc_chunk *p = talloc_parent_chunk(tc->child->refs);
 			if (p) new_parent = p+1;
 		}
-		if (new_parent == null_context) {
-			struct talloc_chunk *p = talloc_parent_chunk(ptr);
-			if (p) new_parent = p+1;
+		if (talloc_free(child) == -1) {
+			if (new_parent == null_context) {
+				struct talloc_chunk *p = talloc_parent_chunk(ptr);
+				if (p) new_parent = p+1;
+			}
+			talloc_steal(new_parent, child);
 		}
-		talloc_free(talloc_steal(new_parent, child));
 	}
 
 	if (tc->parent) {

Modified: branches/SAMBA_4_0/talloc_guide.txt
===================================================================
--- branches/SAMBA_4_0/talloc_guide.txt	2004-10-29 09:58:23 UTC (rev 3365)
+++ branches/SAMBA_4_0/talloc_guide.txt	2004-10-29 11:39:08 UTC (rev 3366)
@@ -101,10 +101,10 @@
 destructor returned -1. See talloc_set_destructor() for details on
 destructors.
 
-If this pointer has an additional reference when talloc_free() is
-called then the memory is not actually released, but instead the most
-recently established reference is destroyed. See talloc_reference()
-for details on establishing additional references.
+If this pointer has an additional parent when talloc_free() is called
+then the memory is not actually released, but instead the most
+recently established parent is destroyed. See talloc_reference() for
+details on establishing additional parents.
 
 For more control on which parent is removed, see talloc_unlink()
 
@@ -114,8 +114,8 @@
 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 void *talloc_reference(const void *context, const void *ptr);
 
-The talloc_reference() function returns an additional reference to
-"ptr", and makes this additional reference a child of "context".
+The talloc_reference() function makes "context" an additional parent
+of "ptr".
 
 The return value of talloc_reference() is always the original pointer
 "ptr", unless talloc ran out of memory in creating the reference in
@@ -125,19 +125,14 @@
 After creating a reference you can free it in one of the following
 ways:
 
-  - you can talloc_free() a parent of the original pointer. That will
-    destroy the reference and make the pointer a child of the
-    "context" argument from the most recently called
-    talloc_reference() on the pointer.
+  - you can talloc_free() any parent of the original pointer. That
+    will reduce the number of parents of this pointer by 1, and will
+    cause this pointer to be freed if it runs out of parents.
 
   - you can talloc_free() the pointer itself. That will destroy the
-    most recently established reference to the pointer and leave the
+    most recently established parent to the pointer and leave the
     pointer as a child of its current parent.
 
-  - you can talloc_free() the context where you placed the
-    reference. That will destroy the reference, and leave the pointer
-    where it is.
-
 For more control on which parent to remove, see talloc_unlink()
 
 
@@ -205,7 +200,15 @@
 talloc_report() and talloc_report_full() for details. Also see
 talloc_enable_leak_report() and talloc_enable_leak_report_full().
 
+The talloc_set_name() function allocates memory as a child of the
+pointer. It is logically equivalent to:
+  talloc_set_name_const(ptr, talloc_asprintf(ptr, fmt, ...));
 
+Note that multiple calls to talloc_set_name() will allocate more
+memory without releasing the name. All of the memory is released when
+the ptr is freed using talloc_free().
+
+
 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 void talloc_set_name_const(const void *ptr, const char *name);
 
@@ -213,7 +216,12 @@
 but it takes a string constant, and is much faster. It is extensively
 used by the "auto naming" macros, such as talloc_p().
 
+This function does not allocate any memory. It just copies the
+supplied pointer into the internal representation of the talloc
+ptr. This means you must not pass a name pointer to memory that will
+disappear before the ptr is freed with talloc_free().
 
+
 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 void *talloc_named(const void *context, size_t size, const char *fmt, ...);
 
@@ -263,7 +271,7 @@
 
 talloc_realloc() returns the new pointer, or NULL on failure. The call
 will fail either due to a lack of memory, or because the pointer has
-an reference (see talloc_reference()).
+more than one parent (see talloc_reference()).
 
 
 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
@@ -408,6 +416,9 @@
   ptr = talloc(ctx, strlen(p)+1);
   if (ptr) memcpy(ptr, p, strlen(p)+1);
 
+This functions sets the name of the new pointer to the passed
+string. This is equivalent to:
+   talloc_set_name_const(ptr, ptr)
 
 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 char *talloc_strndup(const void *t, const char *p, size_t n);
@@ -415,7 +426,11 @@
 The talloc_strndup() function is the talloc equivalent of the C
 library function strndup()
 
+This functions sets the name of the new pointer to the passed
+string. This is equivalent to:
+   talloc_set_name_const(ptr, ptr)
 
+
 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 char *talloc_vasprintf(const void *t, const char *fmt, va_list ap);
 
@@ -429,7 +444,11 @@
 The talloc_asprintf() function is the talloc equivalent of the C
 library function asprintf()
 
+This functions sets the name of the new pointer to the passed
+string. This is equivalent to:
+   talloc_set_name_const(ptr, ptr)
 
+
 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 char *talloc_asprintf_append(char *s, const char *fmt, ...);
 



More information about the samba-cvs mailing list