GRand *rand;
gint i;
- g_assert_cmpint ((gsize) buffer & ALIGN_BITS & instance->alignment, ==, 0);
+ g_assert_cmpint ((gsize) buffer & instance->alignment, ==, 0);
rand = g_rand_new_with_seed (instance->seed);
for (i = 0; i < instance->size; i++)
GRand *rand;
gint i;
- g_assert_cmpint ((gsize) buffer & ALIGN_BITS & instance->alignment, ==, 0);
+ g_assert_cmpint ((gsize) buffer & instance->alignment, ==, 0);
g_assert_cmpint (size, ==, instance->size);
rand = g_rand_new_with_seed (instance->seed);
GRand *rand;
gint i;
- g_assert_cmpint ((gsize) buffer & ALIGN_BITS & instance->alignment, ==, 0);
+ g_assert_cmpint ((gsize) buffer & instance->alignment, ==, 0);
if (size != instance->size)
return FALSE;
g_free (((gchar *) data) - flavour);
}
+static gpointer
+align_malloc (gsize size)
+{
+ gpointer mem;
+
+#ifdef HAVE_POSIX_MEMALIGN
+ if (posix_memalign (&mem, 8, size))
+ g_error ("posix_memalign failed");
+#else
+ /* NOTE: there may be platforms that lack posix_memalign() and also
+ * have malloc() that returns non-8-aligned. if so, we need to try
+ * harder here.
+ */
+ mem = malloc (size);
+#endif
+
+ return mem;
+}
+
+static void
+align_free (gpointer mem)
+{
+ free (mem);
+}
+
static void
append_offset (guchar **offset_ptr,
gsize offset,
{
guchar *ptr;
- ptr = data = g_malloc (needed_size);
+ ptr = data = align_malloc (needed_size);
append_instance_data (instance, &ptr);
if (!instance->is_fixed_sized)
g_variant_type_info_unref (type_info);
random_instance_free (instance);
- g_free (data);
+ align_free (data);
}
static void
guchar *offset_ptr, *body_ptr;
guint i;
- body_ptr = data = g_malloc (needed_size);
+ body_ptr = data = align_malloc (needed_size);
offset_ptr = body_ptr + needed_size - offset_size * n_children;
for (i = 0; i < n_children; i++)
g_variant_type_info_unref (element_info);
g_variant_type_info_unref (array_info);
- g_free (data);
+ align_free (data);
}
static void
guchar *ofs_ptr;
guint i;
- body_ptr = data = g_malloc (needed_size);
+ body_ptr = data = align_malloc (needed_size);
ofs_ptr = body_ptr + needed_size;
for (i = 0; i < n_children; i++)
}
g_variant_type_info_unref (type_info);
- g_free (data);
+ align_free (data);
}
static void
{
guchar *ptr;
- ptr = data = g_malloc (needed_size);
+ ptr = data = align_malloc (needed_size);
append_instance_data (instance, &ptr);
*ptr++ = '\0';
memcpy (ptr, type_string, len);
g_variant_type_info_unref (type_info);
random_instance_free (instance);
- g_free (data);
+ align_free (data);
}
static void