From 859748eccdedb45e52c6514f21ad33a5147a51fb Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Wed, 10 Jan 2024 14:12:47 -0800 Subject: [PATCH 1/2] gconvert: match GNU iconv behaviour on FreeBSD FreeBSD iconv by default handles input characters that are not representable in the destination character set by emitting a replacement character such as '?'. While this appears to be the POSIX mandated behaviour it does not match GNU behaviour and causes the gconvert test to fail in the `test_one_half` testcase. Fortunately FreeBSD provides a iconvctl flag to request this behaviour to match GNU iconv. See https://github.com/freebsd/freebsd-src/commit/7c5b23111c5fd199204 --- glib/gconvert.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/glib/gconvert.c b/glib/gconvert.c index 4eaabc278..a2c746f3f 100644 --- a/glib/gconvert.c +++ b/glib/gconvert.c @@ -73,8 +73,17 @@ try_conversion (const char *to_codeset, if (*cd == (iconv_t)-1 && errno == EINVAL) return FALSE; - else - return TRUE; + +#if defined(__FreeBSD__) && defined(ICONV_SET_ILSEQ_INVALID) + /* On FreeBSD request GNU iconv compatible handling of characters that cannot + * be repesented in the destination character set. + * See https://github.com/freebsd/freebsd-src/commit/7c5b23111c5fd1992 + */ + int value = 1; + if (iconvctl (*cd, ICONV_SET_ILSEQ_INVALID, &value) != 0) + return FALSE; +#endif + return TRUE; } static gboolean From ec780d0d4a95ee675b5acd7ed6a898fcda5c1fd4 Mon Sep 17 00:00:00 2001 From: Ting-Wei Lan Date: Mon, 22 Jan 2024 15:39:33 +0000 Subject: [PATCH 2/2] Use the FreeBSD cgit URL --- glib/gconvert.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glib/gconvert.c b/glib/gconvert.c index a2c746f3f..e7c222f8d 100644 --- a/glib/gconvert.c +++ b/glib/gconvert.c @@ -77,7 +77,7 @@ try_conversion (const char *to_codeset, #if defined(__FreeBSD__) && defined(ICONV_SET_ILSEQ_INVALID) /* On FreeBSD request GNU iconv compatible handling of characters that cannot * be repesented in the destination character set. - * See https://github.com/freebsd/freebsd-src/commit/7c5b23111c5fd1992 + * See https://cgit.freebsd.org/src/commit/?id=7c5b23111c5fd1992047922d4247c4a1ce1bb6c3 */ int value = 1; if (iconvctl (*cd, ICONV_SET_ILSEQ_INVALID, &value) != 0)