gobject: denote GObject as 8-byte aligned
We already ensure that alignments happen to an 8-byte boundary so that
you can store any type within the structures. This lets the compiler know
about that requirement so that we can squash a number of warnings on
various compiler and architecture configurations.
We also ensure this for private instance data as that is a reasonable
expectation given the standalone nature of Private typedef's.
Fixes #1231
diff --git a/gobject/gobject.c b/gobject/gobject.c
index d8a31a3..48b1c8b 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -169,6 +169,7 @@
#define HAVE_OPTIONAL_FLAGS
#endif
+G_GNUC_BEGIN_ALIGNED(8)
typedef struct
{
GTypeInstance g_type_instance;
@@ -179,7 +180,8 @@
volatile guint optional_flags;
#endif
GData *qdata;
-} GObjectReal;
+} GObjectReal
+G_GNUC_BEGIN_ALIGNED(8);
G_STATIC_ASSERT(sizeof(GObject) == sizeof(GObjectReal));
G_STATIC_ASSERT(G_STRUCT_OFFSET(GObject, ref_count) == G_STRUCT_OFFSET(GObjectReal, ref_count));
diff --git a/gobject/gobject.h b/gobject/gobject.h
index bf5496c..3802a64 100644
--- a/gobject/gobject.h
+++ b/gobject/gobject.h
@@ -242,6 +242,7 @@
* All the fields in the GObject structure are private
* to the #GObject implementation and should never be accessed directly.
*/
+G_GNUC_BEGIN_ALIGNED(8)
struct _GObject
{
GTypeInstance g_type_instance;
@@ -249,7 +250,8 @@
/*< private >*/
volatile guint ref_count;
GData *qdata;
-};
+}
+G_GNUC_END_ALIGNED(8);
/**
* GObjectClass:
* @g_type_class: the parent class
diff --git a/gobject/gtype.c b/gobject/gtype.c
index 12ad8be..c8e3d66 100644
--- a/gobject/gtype.c
+++ b/gobject/gtype.c
@@ -1878,6 +1878,9 @@
private_size = node->data->instance.private_size;
ivar_size = node->data->instance.instance_size;
+ g_assert ((private_size & 0x7) == 0);
+ g_assert ((ivar_size & 0x7) == 0);
+
#ifdef ENABLE_VALGRIND
if (private_size && RUNNING_ON_VALGRIND)
{
@@ -1923,6 +1926,8 @@
TRACE(GOBJECT_OBJECT_NEW(instance, type));
+ g_assert ((GPOINTER_TO_SIZE (instance) & 0x7) == 0);
+
return instance;
}
@@ -4777,6 +4782,9 @@
return NULL;
}
+ /* Ensure we maintain alignment requirements */
+ g_assert ((node->data->instance.private_size & 0x7) == 0);
+
return ((gchar *) instance) - node->data->instance.private_size;
}
@@ -4825,6 +4833,8 @@
g_error ("g_type_class_get_instance_private_offset() called on class %s but it has no private data",
g_type_name (instance_type));
+ g_assert ((node->data->instance.private_size & 0x7) == 0);
+
return -(gint) node->data->instance.private_size;
}