svn commit: samba r1984 - in branches/SAMBA_4_0/source: include libcli/raw

tridge at samba.org tridge at samba.org
Sat Aug 21 02:07:13 GMT 2004


Author: tridge
Date: 2004-08-21 02:07:12 +0000 (Sat, 21 Aug 2004)
New Revision: 1984

WebSVN: http://websvn.samba.org/websvn/changeset.php?rep=samba&path=/branches/SAMBA_4_0/source&rev=1984&nolog=1

Log:
this change is what you should read to understand the new talloc()

It simplifies our structure handling a lot, making the code shorter
and easier to understand. Look at the diff carefully and see if you
can understand it. If you're still confused then please ask.


Modified:
   branches/SAMBA_4_0/source/include/cli_context.h
   branches/SAMBA_4_0/source/libcli/raw/clitransport.c
   branches/SAMBA_4_0/source/libcli/raw/rawrequest.c


Changeset:
Modified: branches/SAMBA_4_0/source/include/cli_context.h
===================================================================
--- branches/SAMBA_4_0/source/include/cli_context.h	2004-08-21 01:54:46 UTC (rev 1983)
+++ branches/SAMBA_4_0/source/include/cli_context.h	2004-08-21 02:07:12 UTC (rev 1984)
@@ -244,9 +244,6 @@
 	/* allow a request to be part of a list of requests */
 	struct smbcli_request *next, *prev;
 
-	/* a talloc context for the lifetime of this request */
-	TALLOC_CTX *mem_ctx;
-	
 	/* each request is in one of 4 possible states */
 	enum smbcli_request_state state;
 	

Modified: branches/SAMBA_4_0/source/libcli/raw/clitransport.c
===================================================================
--- branches/SAMBA_4_0/source/libcli/raw/clitransport.c	2004-08-21 01:54:46 UTC (rev 1983)
+++ branches/SAMBA_4_0/source/libcli/raw/clitransport.c	2004-08-21 02:07:12 UTC (rev 1984)
@@ -325,7 +325,7 @@
 		if (!req) goto error;
 
 		req->in.buffer = buffer;
-		talloc_steal(req->mem_ctx, buffer);
+		talloc_steal(req, buffer);
 		req->in.size = len;
 		req->in.allocated = req->in.size;
 		goto async;
@@ -349,7 +349,7 @@
 
 	/* fill in the 'in' portion of the matching request */
 	req->in.buffer = buffer;
-	talloc_steal(req->mem_ctx, buffer);
+	talloc_steal(req, buffer);
 	req->in.size = len;
 	req->in.allocated = req->in.size;
 

Modified: branches/SAMBA_4_0/source/libcli/raw/rawrequest.c
===================================================================
--- branches/SAMBA_4_0/source/libcli/raw/rawrequest.c	2004-08-21 01:54:46 UTC (rev 1983)
+++ branches/SAMBA_4_0/source/libcli/raw/rawrequest.c	2004-08-21 02:07:12 UTC (rev 1984)
@@ -49,7 +49,7 @@
 	/* ahh, its so nice to destroy a complex structure in such a
 	   simple way! */
 	status = req->status;
-	talloc_destroy(req->mem_ctx);
+	talloc_free(req);
 	return status;
 }
 
@@ -61,18 +61,8 @@
 struct smbcli_request *smbcli_request_setup_nonsmb(struct smbcli_transport *transport, uint_t size)
 {
 	struct smbcli_request *req;
-	TALLOC_CTX *mem_ctx;
-	
-	/* each request gets its own talloc context. The request
-	   structure itself is also allocated inside this context,
-	   so we need to allocate it before we construct the request
-	*/
-	mem_ctx = talloc_init("smbcli_request");
-	if (!mem_ctx) {
-		return NULL;
-	}
 
-	req = talloc(mem_ctx, sizeof(struct smbcli_request));
+	req = talloc_named(NULL, sizeof(struct smbcli_request), "smcli_request");
 	if (!req) {
 		return NULL;
 	}
@@ -80,7 +70,6 @@
 
 	/* setup the request context */
 	req->state = SMBCLI_REQUEST_INIT;
-	req->mem_ctx = mem_ctx;
 	req->transport = transport;
 	req->session = NULL;
 	req->tree = NULL;
@@ -89,7 +78,7 @@
 	/* over allocate by a small amount */
 	req->out.allocated = req->out.size + REQ_OVER_ALLOCATION; 
 
-	req->out.buffer = talloc(req->mem_ctx, req->out.allocated);
+	req->out.buffer = talloc(req, req->out.allocated);
 	if (!req->out.buffer) {
 		return NULL;
 	}



More information about the samba-cvs mailing list