r3888 - trunk/birnet



Author: timj
Date: 2006-09-16 09:15:42 -0400 (Sat, 16 Sep 2006)
New Revision: 3888

Modified:
   trunk/birnet/ChangeLog
   trunk/birnet/birnetutils.c
Log:
Sat Sep 16 15:14:32 2006  Tim Janik  <timj gtk org>                                                                                                           
                                                                                                                                                              
        * birnetutils.c (birnet_malloc_aligned): fixed alginment adjustment so                                                                                
        this function *really* returnes aligned memory. added check on whether                                                                                
        malloc already aligned the memory the way we wanted it.                                                                                               
                                                                                                                                                              



Modified: trunk/birnet/ChangeLog
===================================================================
--- trunk/birnet/ChangeLog	2006-09-16 13:03:52 UTC (rev 3887)
+++ trunk/birnet/ChangeLog	2006-09-16 13:15:42 UTC (rev 3888)
@@ -1,3 +1,9 @@
+Sat Sep 16 15:14:32 2006  Tim Janik  <timj gtk org>
+
+	* birnetutils.c (birnet_malloc_aligned): fixed alginment adjustment so
+	this function *really* returnes aligned memory. added check on whether
+	malloc already aligned the memory the way we wanted it.
+
 Sat Sep 16 09:20:49 2006  Stefan Westerfeld  <stefan space twc de>
 
 	* birnetutils.[hc]: Added birnet_malloc_aligned(), which allocates

Modified: trunk/birnet/birnetutils.c
===================================================================
--- trunk/birnet/birnetutils.c	2006-09-16 13:03:52 UTC (rev 3887)
+++ trunk/birnet/birnetutils.c	2006-09-16 13:15:42 UTC (rev 3888)
@@ -288,12 +288,15 @@
 		       gsize	  alignment,
 		       guint8	**free_pointer)
 {
-  *free_pointer = g_malloc (total_size + alignment - 1);
-  
-  uint8 *aligned_mem = *free_pointer;
+  uint8 *aligned_mem = g_malloc (total_size);
+  *free_pointer = aligned_mem;
+  if (!alignment || !(ptrdiff_t) aligned_mem % alignment)
+    return aligned_mem;
+  g_free (aligned_mem);
+  aligned_mem = g_malloc (total_size + alignment - 1);
+  *free_pointer = aligned_mem;
   if ((ptrdiff_t) aligned_mem % alignment)
-    aligned_mem += alignment - (ptrdiff_t) free_pointer % alignment;
-
+    aligned_mem += alignment - (ptrdiff_t) aligned_mem % alignment;
   return aligned_mem;
 }
 




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]