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

tridge at samba.org tridge at samba.org
Tue May 17 05:48:30 GMT 2005


Author: tridge
Date: 2005-05-17 05:48:30 +0000 (Tue, 17 May 2005)
New Revision: 6845

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

Log:
make the talloc header align to 40 bytes, which costs us an extra 4
bytes per allocation, but makes it much more portable


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


Changeset:
Modified: branches/SAMBA_4_0/source/lib/talloc/talloc.c
===================================================================
--- branches/SAMBA_4_0/source/lib/talloc/talloc.c	2005-05-17 02:37:57 UTC (rev 6844)
+++ branches/SAMBA_4_0/source/lib/talloc/talloc.c	2005-05-17 05:48:30 UTC (rev 6845)
@@ -97,17 +97,20 @@
 	struct talloc_chunk *parent, *child;
 	struct talloc_reference_handle *refs;
 	size_t size;
-	unsigned magic;
 	talloc_destructor_t destructor;
 	const char *name;
+	union {
+		unsigned magic;
+		double align_dummy;
+	} u;
 };
 
 /* panic if we get a bad magic value */
 static struct talloc_chunk *talloc_chunk_from_ptr(const void *ptr)
 {
 	struct talloc_chunk *tc = discard_const_p(struct talloc_chunk, ptr)-1;
-	if (tc->magic != TALLOC_MAGIC) { 
-		if (tc->magic == TALLOC_MAGIC_FREE) {
+	if (tc->u.magic != TALLOC_MAGIC) { 
+		if (tc->u.magic == TALLOC_MAGIC_FREE) {
 			TALLOC_ABORT("Bad talloc magic value - double free"); 
 		} else {
 			TALLOC_ABORT("Bad talloc magic value - unknown value"); 
@@ -180,7 +183,7 @@
 	if (tc == NULL) return NULL;
 
 	tc->size = size;
-	tc->magic = TALLOC_MAGIC;
+	tc->u.magic = TALLOC_MAGIC;
 	tc->destructor = NULL;
 	tc->child = NULL;
 	tc->name = NULL;
@@ -559,7 +562,7 @@
 		if (tc->next) tc->next->prev = tc->prev;
 	}
 
-	tc->magic = TALLOC_MAGIC_FREE;
+	tc->u.magic = TALLOC_MAGIC_FREE;
 
 	free(tc);
 	return 0;
@@ -599,7 +602,7 @@
 	}
 
 	/* by resetting magic we catch users of the old memory */
-	tc->magic = TALLOC_MAGIC_FREE;
+	tc->u.magic = TALLOC_MAGIC_FREE;
 
 #if ALWAYS_REALLOC
 	new_ptr = malloc(size + sizeof(*tc));
@@ -611,12 +614,12 @@
 	new_ptr = realloc(tc, size + sizeof(*tc));
 #endif
 	if (!new_ptr) {	
-		tc->magic = TALLOC_MAGIC; 
+		tc->u.magic = TALLOC_MAGIC; 
 		return NULL; 
 	}
 
 	tc = new_ptr;
-	tc->magic = TALLOC_MAGIC;
+	tc->u.magic = TALLOC_MAGIC;
 	if (tc->parent) {
 		tc->parent->child = new_ptr;
 	}



More information about the samba-cvs mailing list