[glib] glib-init: make static assertions about platform assumptions



commit 84f3147f434eab1124276ea2fdbee9a1e9a02c45
Author: Simon McVittie <simon mcvittie collabora co uk>
Date:   Fri Nov 16 12:53:39 2012 +0000

    glib-init: make static assertions about platform assumptions
    
    GLib has a pervasive assumption that function and data pointers are
    basically interchangeable, which is true in all modern ABIs,
    but not actually guaranteed by ISO C. If someone tries to use GLib on a
    platform where function and data pointers are different sizes, fail early.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688406

 glib/glib-init.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
---
diff --git a/glib/glib-init.c b/glib/glib-init.c
index ceb9395..02b66c0 100644
--- a/glib/glib-init.c
+++ b/glib/glib-init.c
@@ -23,6 +23,8 @@
 
 #include "glib-init.h"
 
+#include "glib-private.h"
+#include "gtypes.h"
 #include "gutils.h"     /* for GDebugKey */
 #include "gconstructor.h"
 #include "gmem.h"       /* for g_mem_gc_friendly */
@@ -32,6 +34,16 @@
 #include <stdio.h>
 #include <ctype.h>
 
+/* This seems as good a place as any to make static assertions about platform
+ * assumptions we make throughout GLib. */
+
+/* We assume that data pointers are the same size as function pointers... */
+G_STATIC_ASSERT (sizeof (gpointer) == sizeof (GFunc));
+G_STATIC_ASSERT (_g_alignof (gpointer) == _g_alignof (GFunc));
+/* ... and that all function pointers are the same size. */
+G_STATIC_ASSERT (sizeof (GFunc) == sizeof (GCompareDataFunc));
+G_STATIC_ASSERT (_g_alignof (GFunc) == _g_alignof (GCompareDataFunc));
+
 /**
  * g_mem_gc_friendly:
  *


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