[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Thu Apr 18 14:51:03 MDT 2013


The branch, master has been updated
       via  79fe138 talloc: Simplify _talloc_free_poolmem a bit
       via  a796e48 talloc: Do an early return
       via  ccf33dd talloc: Avoid some "else" by doing early returns
       via  d3928b0 talloc: Fix nonblank line endings
      from  33c6907 selftest: S3 does not do leases yet

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 79fe1381a3a78ad2316343fc8c1c27360b46ebbf
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Apr 15 22:19:25 2013 +0200

    talloc: Simplify _talloc_free_poolmem a bit
    
    Early returns are easier to understand than "else if"
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Thu Apr 18 22:50:42 CEST 2013 on sn-devel-104

commit a796e48b1dfe96b194f3a3a0d70e25c3ab92690d
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Apr 15 22:12:50 2013 +0200

    talloc: Do an early return
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit ccf33dd0547f32104041c8611626f3e02e22cbe9
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Apr 15 22:11:44 2013 +0200

    talloc: Avoid some "else" by doing early returns
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit d3928b0c8af01f7751191b81a72590ca35751a8c
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Apr 15 21:44:38 2013 +0200

    talloc: Fix nonblank line endings
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

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

Summary of changes:
 lib/talloc/talloc.c |  103 ++++++++++++++++++++++++++++++---------------------
 1 files changed, 61 insertions(+), 42 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c
index 3e33fc0..885d700 100644
--- a/lib/talloc/talloc.c
+++ b/lib/talloc/talloc.c
@@ -1,4 +1,4 @@
-/* 
+/*
    Samba Unix SMB/CIFS implementation.
 
    Samba trivial allocation library - new interface
@@ -7,11 +7,11 @@
 
    Copyright (C) Andrew Tridgell 2004
    Copyright (C) Stefan Metzmacher 2006
-   
+
      ** NOTE! The following LGPL license applies to the talloc
      ** library. This does NOT imply that all of Samba is released
      ** under the LGPL
-   
+
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
@@ -74,7 +74,7 @@
 
 #define TALLOC_MAGIC_REFERENCE ((const char *)1)
 
-/* by default we abort when given a bad pointer (such as when talloc_free() is called 
+/* by default we abort when given a bad pointer (such as when talloc_free() is called
    on a pointer that came from malloc() */
 #ifndef TALLOC_ABORT
 #define TALLOC_ABORT(reason) abort()
@@ -367,7 +367,7 @@ static inline struct talloc_chunk *talloc_chunk_from_ptr(const void *ptr)
 {
 	const char *pp = (const char *)ptr;
 	struct talloc_chunk *tc = discard_const_p(struct talloc_chunk, pp - TC_HDR_SIZE);
-	if (unlikely((tc->flags & (TALLOC_FLAG_FREE | ~0xF)) != TALLOC_MAGIC)) { 
+	if (unlikely((tc->flags & (TALLOC_FLAG_FREE | ~0xF)) != TALLOC_MAGIC)) {
 		if ((tc->flags & (~0xFFF)) == TALLOC_MAGIC_BASE) {
 			talloc_abort_magic(tc->flags & (~0xF));
 			return NULL;
@@ -558,7 +558,7 @@ static struct talloc_chunk *talloc_alloc_pool(struct talloc_chunk *parent,
 	return result;
 }
 
-/* 
+/*
    Allocate a bit of memory as a child of an existing pointer
 */
 static inline void *__talloc(const void *context, size_t size)
@@ -675,7 +675,7 @@ _PUBLIC_ void _talloc_set_destructor(const void *ptr, int (*destructor)(void *))
 }
 
 /*
-  increase the reference count on a piece of memory. 
+  increase the reference count on a piece of memory.
 */
 _PUBLIC_ int talloc_increase_ref_count(const void *ptr)
 {
@@ -698,7 +698,7 @@ static int talloc_reference_destructor(struct talloc_reference_handle *handle)
 }
 
 /*
-   more efficient way to add a name to a pointer - the name must point to a 
+   more efficient way to add a name to a pointer - the name must point to a
    true string constant
 */
 static inline void _talloc_set_name_const(const void *ptr, const char *name)
@@ -728,8 +728,8 @@ static inline void *_talloc_named_const(const void *context, size_t size, const
   make a secondary reference to a pointer, hanging off the given context.
   the pointer remains valid until both the original caller and this given
   context are freed.
-  
-  the major use for this is when two different structures need to reference the 
+
+  the major use for this is when two different structures need to reference the
   same underlying data, and you want to be able to free the two instances separately,
   and in either order
 */
@@ -794,7 +794,10 @@ static inline void _talloc_free_poolmem(struct talloc_chunk *tc,
 		 */
 		pool->hdr.c.pool = tc_pool_first_chunk(pool);
 		tc_invalidate_pool(pool);
-	} else if (unlikely(pool->hdr.object_count == 0)) {
+		return;
+	}
+
+	if (unlikely(pool->hdr.object_count == 0)) {
 		/*
 		 * we mark the freed memory with where we called the free
 		 * from. This means on a double free error we can report where
@@ -804,21 +807,30 @@ static inline void _talloc_free_poolmem(struct talloc_chunk *tc,
 
 		TC_INVALIDATE_FULL_CHUNK(&pool->hdr.c);
 		free(pool);
-	} else if (pool->hdr.c.pool == next_tc) {
+		return;
+	}
+
+	if (pool->hdr.c.pool == next_tc) {
 		/*
 		 * if pool->pool still points to end of
 		 * 'tc' (which is stored in the 'next_tc' variable),
 		 * we can reclaim the memory of 'tc'.
 		 */
 		pool->hdr.c.pool = tc;
+		return;
 	}
+
+	/*
+	 * Do nothing. The memory is just "wasted", waiting for the pool
+	 * itself to be freed.
+	 */
 }
 
 static inline void _talloc_free_children_internal(struct talloc_chunk *tc,
 						  void *ptr,
 						  const char *location);
 
-/* 
+/*
    internal talloc_free call
 */
 static inline int _talloc_free_internal(void *ptr, const char *location)
@@ -918,8 +930,8 @@ static inline int _talloc_free_internal(void *ptr, const char *location)
 
 	/* we mark the freed memory with where we called the free
 	 * from. This means on a double free error we can report where
-	 * the first free came from 
-	 */	 
+	 * the first free came from
+	 */
 	tc->name = location;
 
 	if (tc->flags & TALLOC_FLAG_POOL) {
@@ -931,16 +943,23 @@ static inline int _talloc_free_internal(void *ptr, const char *location)
 		}
 
 		pool->hdr.object_count--;
-		if (unlikely(pool->hdr.object_count == 0)) {
-			TC_INVALIDATE_FULL_CHUNK(tc);
-			free(tc);
+
+		if (likely(pool->hdr.object_count != 0)) {
+			return 0;
 		}
-	} else if (tc->flags & TALLOC_FLAG_POOLMEM) {
-		_talloc_free_poolmem(tc, location);
-	} else {
+
 		TC_INVALIDATE_FULL_CHUNK(tc);
 		free(tc);
+		return 0;
+	}
+
+	if (tc->flags & TALLOC_FLAG_POOLMEM) {
+		_talloc_free_poolmem(tc, location);
+		return 0;
 	}
+
+	TC_INVALIDATE_FULL_CHUNK(tc);
+	free(tc);
 	return 0;
 }
 
@@ -948,7 +967,7 @@ static size_t _talloc_total_limit_size(const void *ptr,
 					struct talloc_memlimit *old_limit,
 					struct talloc_memlimit *new_limit);
 
-/* 
+/*
    move a lump of memory from one talloc context to another return the
    ptr on success, or NULL if it could not be transferred.
    passing NULL as ptr will always return NULL with no side effects.
@@ -1037,7 +1056,7 @@ static void *_talloc_steal_internal(const void *new_ctx, const void *ptr)
 	return discard_const_p(void, ptr);
 }
 
-/* 
+/*
    move a lump of memory from one talloc context to another return the
    ptr on success, or NULL if it could not be transferred.
    passing NULL as ptr will always return NULL with no side effects.
@@ -1049,9 +1068,9 @@ _PUBLIC_ void *_talloc_steal_loc(const void *new_ctx, const void *ptr, const cha
 	if (unlikely(ptr == NULL)) {
 		return NULL;
 	}
-	
+
 	tc = talloc_chunk_from_ptr(ptr);
-	
+
 	if (unlikely(tc->refs != NULL) && talloc_parent(ptr) != new_ctx) {
 		struct talloc_reference_handle *h;
 
@@ -1071,11 +1090,11 @@ _PUBLIC_ void *_talloc_steal_loc(const void *new_ctx, const void *ptr, const cha
 		talloc_log("WARNING: stealing into talloc child at %s\n", location);
 	}
 #endif
-	
+
 	return _talloc_steal_internal(new_ctx, ptr);
 }
 
-/* 
+/*
    this is like a talloc_steal(), but you must supply the old
    parent. This resolves the ambiguity in a talloc_steal() which is
    called on a context that has more than one parent (via references)
@@ -1103,7 +1122,7 @@ _PUBLIC_ void *talloc_reparent(const void *old_parent, const void *new_parent, c
 			}
 			return discard_const_p(void, ptr);
 		}
-	}	
+	}
 
 	/* it wasn't a parent */
 	return NULL;
@@ -1403,7 +1422,7 @@ _PUBLIC_ void talloc_free_children(void *ptr)
 	}
 }
 
-/* 
+/*
    Allocate a bit of memory as a child of an existing pointer
 */
 _PUBLIC_ void *_talloc(const void *context, size_t size)
@@ -1429,8 +1448,8 @@ _PUBLIC_ void *talloc_named_const(const void *context, size_t size, const char *
 	return _talloc_named_const(context, size, name);
 }
 
-/* 
-   free a talloc pointer. This also frees all child pointers of this 
+/*
+   free a talloc pointer. This also frees all child pointers of this
    pointer recursively
 
    return 0 if the memory is actually freed, otherwise -1. The memory
@@ -1444,9 +1463,9 @@ _PUBLIC_ int _talloc_free(void *ptr, const char *location)
 	if (unlikely(ptr == NULL)) {
 		return -1;
 	}
-	
+
 	tc = talloc_chunk_from_ptr(ptr);
-	
+
 	if (unlikely(tc->refs != NULL)) {
 		struct talloc_reference_handle *h;
 
@@ -1466,7 +1485,7 @@ _PUBLIC_ int _talloc_free(void *ptr, const char *location)
 		}
 		return -1;
 	}
-	
+
 	return _talloc_free_internal(ptr, location);
 }
 
@@ -1686,9 +1705,9 @@ _PUBLIC_ void *_talloc_realloc(const void *context, void *ptr, size_t size, cons
 	}
 got_new_ptr:
 #endif
-	if (unlikely(!new_ptr)) {	
-		tc->flags &= ~TALLOC_FLAG_FREE; 
-		return NULL; 
+	if (unlikely(!new_ptr)) {
+		tc->flags &= ~TALLOC_FLAG_FREE;
+		return NULL;
 	}
 
 	tc = (struct talloc_chunk *)new_ptr;
@@ -1901,14 +1920,14 @@ static void talloc_report_depth_FILE_helper(const void *ptr, int depth, int max_
 	}
 
 	if (depth == 0) {
-		fprintf(f,"%stalloc report on '%s' (total %6lu bytes in %3lu blocks)\n", 
+		fprintf(f,"%stalloc report on '%s' (total %6lu bytes in %3lu blocks)\n",
 			(max_depth < 0 ? "full " :""), name,
 			(unsigned long)talloc_total_size(ptr),
 			(unsigned long)talloc_total_blocks(ptr));
 		return;
 	}
 
-	fprintf(f, "%*s%-30s contains %6lu bytes in %3lu blocks (ref %d) %p\n", 
+	fprintf(f, "%*s%-30s contains %6lu bytes in %3lu blocks (ref %d) %p\n",
 		depth*4, "",
 		name,
 		(unsigned long)talloc_total_size(ptr),
@@ -2047,8 +2066,8 @@ _PUBLIC_ void talloc_enable_leak_report_full(void)
 	atexit(talloc_report_null_full);
 }
 
-/* 
-   talloc and zero memory. 
+/*
+   talloc and zero memory.
 */
 _PUBLIC_ void *_talloc_zero(const void *ctx, size_t size, const char *name)
 {
@@ -2062,7 +2081,7 @@ _PUBLIC_ void *_talloc_zero(const void *ctx, size_t size, const char *name)
 }
 
 /*
-  memdup with a talloc. 
+  memdup with a talloc.
 */
 _PUBLIC_ void *_talloc_memdup(const void *t, const void *p, size_t size, const char *name)
 {


-- 
Samba Shared Repository


More information about the samba-cvs mailing list