[dovecot-cvs] dovecot/src/lib mempool-system-clean.c,1.2,1.3

tss at dovecot.org tss at dovecot.org
Thu Mar 22 00:40:18 EET 2007


Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv24775

Modified Files:
	mempool-system-clean.c 
Log Message:
Use 64bit alignment always



Index: mempool-system-clean.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/mempool-system-clean.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- mempool-system-clean.c	21 Mar 2007 22:34:12 -0000	1.2
+++ mempool-system-clean.c	21 Mar 2007 22:40:15 -0000	1.3
@@ -17,6 +17,10 @@
 #  include <gc.h>
 #endif
 
+/* Always give 64 bits to the size so returned memory is always 64bit aligned */
+#define EXTRA_SIZE_SPACE 8
+
+#undef HAVE_MALLOC_USABLE_SIZE
 static const char *pool_system_clean_get_name(pool_t pool);
 static void pool_system_clean_ref(pool_t pool);
 static void pool_system_clean_unref(pool_t *pool);
@@ -71,7 +75,7 @@
 #elif defined(HAVE_MALLOC_USABLE_SIZE)
 	return malloc_usable_size(mem);
 #else
-	return ((size_t *)mem)[-1];
+	return *((size_t *)PTR_OFFSET(mem, -EXTRA_SIZE_SPACE));
 #endif
 }
 
@@ -86,7 +90,7 @@
 	mem = GC_malloc(size);
 #else
 #ifndef HAVE_MALLOC_USABLE_SIZE
-	size += sizeof(size_t);
+	size += EXTRA_SIZE_SPACE;
 #endif
 	mem = calloc(size, 1);
 #endif
@@ -98,8 +102,8 @@
 	{
 		size_t *saved_size = mem;
 
-		*saved_size = size - sizeof(size_t);
-		mem = saved_size + 1;
+		*saved_size = size - EXTRA_SIZE_SPACE;
+		mem = PTR_OFFSET(mem, EXTRA_SIZE_SPACE);
 	}
 #endif
 	return mem;
@@ -111,7 +115,7 @@
 		safe_memset(mem, 0, mem_get_size(mem));
 #ifndef USE_GC
 #ifndef HAVE_MALLOC_USABLE_SIZE
-		mem = (size_t *)mem - 1;
+		mem = PTR_OFFSET(mem, -EXTRA_SIZE_SPACE);
 #endif
 		free(mem);
 #endif



More information about the dovecot-cvs mailing list