[SCM] Samba Shared Repository - branch v3-2-test updated - initial-v3-2-unstable-1011-g1e006bc

Volker Lendecke vl at samba.org
Thu Jan 3 09:26:04 GMT 2008


The branch, v3-2-test has been updated
       via  1e006bcfb15d44ecb81b6994c588d30d87b48033 (commit)
       via  6f22f7c13fd08ee772ac3aa593d2f4b37eb2cbee (commit)
      from  9369d6e907a49da1fbf2a5690118412b8d1a0383 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test


- Log -----------------------------------------------------------------
commit 1e006bcfb15d44ecb81b6994c588d30d87b48033
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Jan 3 10:24:45 2008 +0100

    Trivial simplification
    
    ... things you come across when you review code

commit 6f22f7c13fd08ee772ac3aa593d2f4b37eb2cbee
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Jan 3 10:24:11 2008 +0100

    Add comments
    
    Jeremy was able to use this correctly without comments, so the code can't be
    *that* bad :-)

-----------------------------------------------------------------------

Summary of changes:
 source/include/memcache.h |   55 ++++++++++++++++++++++++++++++++++++++++++++-
 source/lib/util_sock.c    |    5 +--
 2 files changed, 56 insertions(+), 4 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/include/memcache.h b/source/include/memcache.h
index 5a0ce63..0a596b9 100644
--- a/source/include/memcache.h
+++ b/source/include/memcache.h
@@ -1,7 +1,7 @@
 /*
    Unix SMB/CIFS implementation.
    In-memory cache
-   Copyright (C) Volker Lendecke 2005-2007
+   Copyright (C) Volker Lendecke 2007-2008
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -24,6 +24,15 @@
 
 struct memcache;
 
+/*
+ * A memcache can store different subkeys with overlapping keys, the
+ * memcache_number becomes part of the key. Feel free to add caches of your
+ * own here.
+ *
+ * If you add talloc type caches, also note this in the switch statement in
+ * memcache_is_talloc().
+ */
+
 enum memcache_number {
 	STAT_CACHE,
 	UID_SID_CACHE,
@@ -38,25 +47,69 @@ enum memcache_number {
 	SINGLETON_CACHE
 };
 
+/*
+ * Create a memcache structure. max_size is in bytes, if you set it 0 it will
+ * not forget anything.
+ */
+
 struct memcache *memcache_init(TALLOC_CTX *mem_ctx, size_t max_size);
 
+/*
+ * If you set this global memcache, use it as the default cache when NULL is
+ * passed to the memcache functions below. This is a workaround for many
+ * situations where passing the cache everywhere would be a big hassle.
+ */
+
 void memcache_set_global(struct memcache *cache);
 
+/*
+ * Add a data blob to the cache
+ */
+
 void memcache_add(struct memcache *cache, enum memcache_number n,
 		  DATA_BLOB key, DATA_BLOB value);
 
+/*
+ * Add a talloc object to the cache. The difference to memcache_add() is that
+ * when the objects is to be discared, talloc_free is called for it. Also
+ * talloc_move() ownership of the object to the cache.
+ *
+ * Please note that the current implementation has a fixed relationship
+ * between what cache subtypes store talloc objects and which ones store plain
+ * blobs. We can fix this, but for now we don't have a mixed use of blobs vs
+ * talloc objects in the cache types.
+ */
+
 void memcache_add_talloc(struct memcache *cache, enum memcache_number n,
 			 DATA_BLOB key, void *ptr);
 
+/*
+ * Delete an object from the cache
+ */
+
 void memcache_delete(struct memcache *cache, enum memcache_number n,
 		     DATA_BLOB key);
 
+/*
+ * Look up an object from the cache. Memory still belongs to the cache, so
+ * make a copy of it if needed.
+ */
+
 bool memcache_lookup(struct memcache *cache, enum memcache_number n,
 		     DATA_BLOB key, DATA_BLOB *value);
 
+/*
+ * Look up an object from the cache. Memory still belongs to the cache, so
+ * make a copy of it if needed.
+ */
+
 void *memcache_lookup_talloc(struct memcache *cache, enum memcache_number n,
 			     DATA_BLOB key);
 
+/*
+ * Flush a complete cache subset.
+ */
+
 void memcache_flush(struct memcache *cache, enum memcache_number n);
 
 #endif
diff --git a/source/lib/util_sock.c b/source/lib/util_sock.c
index 013a5fe..b92cd3d 100644
--- a/source/lib/util_sock.c
+++ b/source/lib/util_sock.c
@@ -1864,8 +1864,7 @@ static void store_nc(const struct name_addr_pair *nc)
 	DATA_BLOB tmp;
 	size_t namelen = strlen(nc->name);
 
-	tmp.length = sizeof(nc->ss) + namelen + 1;
-	tmp.data = (uint8_t *)SMB_MALLOC(tmp.length);
+	tmp = data_blob(NULL, sizeof(nc->ss) + namelen + 1);
 	if (!tmp.data) {
 		return;
 	}
@@ -1875,7 +1874,7 @@ static void store_nc(const struct name_addr_pair *nc)
 	memcache_add(NULL, SINGLETON_CACHE,
 			data_blob_string_const("get_peer_name"),
 			tmp);
-	SAFE_FREE(tmp.data);
+	data_blob_free(&tmp);
 }
 
 /*******************************************************************


-- 
Samba Shared Repository


More information about the samba-cvs mailing list