From a97f378d64d7f9650133fa861974a7463be8c8ca Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 28 Jul 2024 14:30:39 +0100 Subject: [PATCH] gdk: Codify the requirement that gsize is pointer-sized This is widely assumed, but is not guaranteed by Standard C, and is known to be false on CHERI architectures (which have 64-bit sizes and 128-bit tagged pointers). Add a static assertion to ensure that GTK will not build on platforms where this assumption does not hold. As discussed on GNOME/gtk!7510, if GTK switches from gsize to uintptr_t as its representation of the underlying bits in a pointer, GTK maintainers would prefer that to be done project-wide so that it's done consistently, after which this static assertion could be removed. At the time of writing, GLib makes the same assumption (GNOME/glib#2842), but GLib contributors are gradually removing it (mostly by replacing gsize with uintptr_t where a pointer-sized quantity is needed). Finishing that work in GLib would be a prerequisite for being able to make GTK work on the affected platforms. Signed-off-by: Simon McVittie --- gdk/gdk.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gdk/gdk.c b/gdk/gdk.c index a818ed95b9..5f99d6c551 100644 --- a/gdk/gdk.c +++ b/gdk/gdk.c @@ -43,6 +43,14 @@ #include +/* GTK has a general architectural assumption that gsize is pointer-sized + * (equivalent to uintptr_t), making it non-portable to architectures like + * CHERI where that isn't true. If a future release relaxes that + * assumption, changes will be needed in numerous places. + * See also https://gitlab.gnome.org/GNOME/glib/-/issues/2842 for the + * equivalent in GLib, which would be a prerequisite. */ +G_STATIC_ASSERT (sizeof (gsize) == sizeof (void *)); +G_STATIC_ASSERT (G_ALIGNOF (gsize) == G_ALIGNOF (void *)); /** * GDK_WINDOWING_X11: