From fa45ea2ac9ca2e85321c5d34f8f40f7f9b614db1 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 15 Mar 2024 13:56:20 +0000 Subject: [PATCH] girparser: Allow time_t, off_t, etc. to appear in GIR XML g-ir-scanner currently maps these to lower-level types at scan time by assuming that time_t is an alias for long, off_t is an alias for size_t and so on. This is not always accurate: some ILP32 architectures have 64-bit time_t (for Y2038 compatibility) and 64-bit off_t (for large file support), and that mismatch is tracked as GNOME/gobject-introspection#494. One option for resolving this g-ir-scanner bug is to have it pass these types through to the GIR XML, and teach g-ir-compiler and its replacement gi-compile-repository to convert them to the corresponding concrete type tag, as they already do for abstract types such as `long long` and `size_t`. Loosely based on GNOME/gobject-introspection!451 by Shuyu Liu. Co-authored-by: Shuyu Liu Signed-off-by: Simon McVittie --- girepository/girparser.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/girepository/girparser.c b/girepository/girparser.c index b5d8fc710..966790082 100644 --- a/girepository/girparser.c +++ b/girepository/girparser.c @@ -32,6 +32,12 @@ #include #include #include +#include /* For time_t */ +#include /* For off_t on both Unix and Windows */ + +#ifdef G_OS_UNIX +#include /* For socklen_t */ +#endif /* This is a "major" version in the sense that it's only bumped * for incompatible changes. @@ -448,6 +454,19 @@ typedef struct { unsigned int is_signed : 1; } IntegerAliasInfo; +/* Ignore warnings from use of signedness() */ +#if G_GNUC_CHECK_VERSION(4, 6) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtype-limits" +#elif defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wtype-limits" +#endif + +#define signedness(T) (((T) -1) < 0) +G_STATIC_ASSERT (signedness (int) == 1); +G_STATIC_ASSERT (signedness (unsigned int) == 0); + static IntegerAliasInfo integer_aliases[] = { { "gchar", SIZEOF_CHAR, 1 }, { "guchar", SIZEOF_CHAR, 0 }, @@ -461,8 +480,25 @@ static IntegerAliasInfo integer_aliases[] = { { "gsize", GLIB_SIZEOF_SIZE_T, 0 }, { "gintptr", sizeof (gintptr), 1 }, { "guintptr", sizeof (guintptr), 0 }, +#define INTEGER_ALIAS(T) { #T, sizeof (T), signedness (T) } + INTEGER_ALIAS (off_t), + INTEGER_ALIAS (time_t), +#ifdef G_OS_UNIX + INTEGER_ALIAS (dev_t), + INTEGER_ALIAS (gid_t), + INTEGER_ALIAS (pid_t), + INTEGER_ALIAS (socklen_t), + INTEGER_ALIAS (uid_t), +#endif +#undef INTEGER_ALIAS }; +#if G_GNUC_CHECK_VERSION(4, 6) +#pragma GCC diagnostic pop +#elif defined(__clang__) +#pragma clang diagnostic pop +#endif + typedef struct { const char *str; int tag;