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
This commit is contained in:
Simon McVittie 2012-11-16 12:53:39 +00:00 committed by Matthias Clasen
parent a4480d5f71
commit 84f3147f43

View File

@ -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:
*