From 6de98cc25567a7f64fb9625640d238fa99a6185a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 15 Jan 2024 14:18:40 +0000 Subject: [PATCH] gdatetime: Ignore %E modifier on 64-bit big-endian for the moment This doesn't appear to work reliably on s390x and ppc64, returning the results that were expected without %E or intermittently crashing. It seems that on little-endian 64-bit, the intptr_t returned by the undocumented _NL_TIME_ERA_NUM_ENTRIES correctly has the number of entries in its low-order half (at the time of writing, 0x0000'0000'0000'000b for Japan), but on big-endian 64-bit, it has the number of entries in its high-order half instead (for example 0x0000'000b'0000'0000 for Japan), with the low-order half being all-zero or possibly uninitialized. Making this reliable will require some sort of defined API from glibc. Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/3225 Bug-Debian: https://bugs.debian.org/1060735 Signed-off-by: Simon McVittie --- glib/gdatetime.c | 5 ++++- glib/tests/gdatetime.c | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/glib/gdatetime.c b/glib/gdatetime.c index 136bdb015..b5372d834 100644 --- a/glib/gdatetime.c +++ b/glib/gdatetime.c @@ -558,7 +558,10 @@ get_month_name_abbr_with_day (gint month) #endif /* HAVE_LANGINFO_ABALTMON */ -#ifdef HAVE_LANGINFO_ERA +/* FIXME: It doesn’t seem to be possible to use ERA on 64-bit big-endian platforms with glibc + * in a POSIX-compliant way right now. + * See https://gitlab.gnome.org/GNOME/glib/-/issues/3225 */ +#if defined(HAVE_LANGINFO_ERA) && (G_BYTE_ORDER == G_LITTLE_ENDIAN || GLIB_SIZEOF_VOID_P == 4) #define PREFERRED_ERA_DATE_TIME_FMT nl_langinfo (ERA_D_T_FMT) #define PREFERRED_ERA_DATE_FMT nl_langinfo (ERA_D_FMT) diff --git a/glib/tests/gdatetime.c b/glib/tests/gdatetime.c index f60368d14..c6a6fed3c 100644 --- a/glib/tests/gdatetime.c +++ b/glib/tests/gdatetime.c @@ -1725,7 +1725,7 @@ test_non_utf8_printf (void) TEST_PRINTF ("%%", "%"); TEST_PRINTF ("%", ""); TEST_PRINTF ("%9", NULL); -#ifdef HAVE_LANGINFO_ERA +#if defined(HAVE_LANGINFO_ERA) && (G_BYTE_ORDER == G_LITTLE_ENDIAN || GLIB_SIZEOF_VOID_P == 4) TEST_PRINTF ("%Ec", "平成21年10月24日 00時00分00秒"); TEST_PRINTF ("%EC", "平成"); TEST_PRINTF ("%Ex", "平成21年10月24日"); @@ -2272,7 +2272,7 @@ test_all_dates (void) static void test_date_time_eras_japan (void) { -#ifdef HAVE_LANGINFO_ERA +#if defined(HAVE_LANGINFO_ERA) && (G_BYTE_ORDER == G_LITTLE_ENDIAN || GLIB_SIZEOF_VOID_P == 4) gchar *oldlocale; oldlocale = g_strdup (setlocale (LC_ALL, NULL)); @@ -2319,7 +2319,7 @@ test_date_time_eras_japan (void) static void test_date_time_eras_thailand (void) { -#ifdef HAVE_LANGINFO_ERA +#if defined(HAVE_LANGINFO_ERA) && (G_BYTE_ORDER == G_LITTLE_ENDIAN || GLIB_SIZEOF_VOID_P == 4) gchar *oldlocale; oldlocale = g_strdup (setlocale (LC_ALL, NULL));