diff options
Diffstat (limited to 'glib/glib-init.c')
-rw-r--r-- | glib/glib-init.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/glib/glib-init.c b/glib/glib-init.c index 00f6c3c66..c513f5190 100644 --- a/glib/glib-init.c +++ b/glib/glib-init.c @@ -89,7 +89,24 @@ G_STATIC_ASSERT (sizeof (void *) == GLIB_SIZEOF_VOID_P); G_STATIC_ASSERT (sizeof (gintptr) == sizeof (void *)); G_STATIC_ASSERT (sizeof (guintptr) == sizeof (void *)); +G_STATIC_ASSERT (sizeof (short) == sizeof (gshort)); +G_STATIC_ASSERT (G_MINSHORT == SHRT_MIN); +G_STATIC_ASSERT (G_MAXSHORT == SHRT_MAX); +G_STATIC_ASSERT (sizeof (unsigned short) == sizeof (gushort)); +G_STATIC_ASSERT (G_MAXUSHORT == USHRT_MAX); + +G_STATIC_ASSERT (sizeof (int) == sizeof (gint)); +G_STATIC_ASSERT (G_MININT == INT_MIN); +G_STATIC_ASSERT (G_MAXINT == INT_MAX); +G_STATIC_ASSERT (sizeof (unsigned int) == sizeof (guint)); +G_STATIC_ASSERT (G_MAXUINT == UINT_MAX); + G_STATIC_ASSERT (sizeof (long) == GLIB_SIZEOF_LONG); +G_STATIC_ASSERT (sizeof (long) == sizeof (glong)); +G_STATIC_ASSERT (G_MINLONG == LONG_MIN); +G_STATIC_ASSERT (G_MAXLONG == LONG_MAX); +G_STATIC_ASSERT (sizeof (unsigned long) == sizeof (gulong)); +G_STATIC_ASSERT (G_MAXULONG == ULONG_MAX); G_STATIC_ASSERT (G_HAVE_GINT64 == 1); @@ -99,11 +116,28 @@ G_STATIC_ASSERT (sizeof (size_t) == GLIB_SIZEOF_SIZE_T); G_STATIC_ASSERT (sizeof (size_t) == GLIB_SIZEOF_SSIZE_T); G_STATIC_ASSERT (sizeof (gsize) == GLIB_SIZEOF_SSIZE_T); G_STATIC_ASSERT (sizeof (gsize) == sizeof (size_t)); +G_STATIC_ASSERT (G_MAXSIZE == SIZE_MAX); /* Again this is size_t not ssize_t, because ssize_t is POSIX, not C99 */ G_STATIC_ASSERT (sizeof (gssize) == sizeof (size_t)); G_STATIC_ASSERT (G_ALIGNOF (gsize) == G_ALIGNOF (size_t)); G_STATIC_ASSERT (G_ALIGNOF (gssize) == G_ALIGNOF (size_t)); - +/* We assume that GSIZE_TO_POINTER is reversible by GPOINTER_TO_SIZE + * without losing information. + * However, we do not assume that GPOINTER_TO_SIZE can store an arbitrary + * pointer in a gsize (known to be false on CHERI). */ +G_STATIC_ASSERT (sizeof (size_t) <= sizeof (void *)); +/* Standard C does not guarantee that size_t is the same as uintptr_t, + * but GLib currently assumes they are the same: see + * <https://gitlab.gnome.org/GNOME/glib/-/issues/2842>. + * + * To enable working on bringup for new architectures these assertions + * can be disabled with -DG_ENABLE_EXPERIMENTAL_ABI_COMPILATION. + * + * FIXME: remove these assertions once the API/ABI has stabilized. */ +#ifndef G_ENABLE_EXPERIMENTAL_ABI_COMPILATION +G_STATIC_ASSERT (sizeof (size_t) == sizeof (uintptr_t)); +G_STATIC_ASSERT (G_ALIGNOF (size_t) == G_ALIGNOF (uintptr_t)); +#endif /* goffset is always 64-bit, even if off_t is only 32-bit * (compiling without large-file-support on 32-bit) */ G_STATIC_ASSERT (sizeof (goffset) == sizeof (gint64)); |