The fix for NetBSD iconv crashes Inkscape on FreeBSD
This problem was first reported on FreeBSD Bugzilla: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=232073. It has been worked around by both FreeBSD Ports and glibmm upstream, but it haven't been properly fixed.
Commit 8abf3a04 introduced in https://bugzilla.gnome.org/show_bug.cgi?id=790698 (and migrated to #1303) changes the behavior of g_convert_with_iconv
to return an error when iconv
returns a positive value. I don't think GLib is wrong to do so, but the fact is that it causes problems when converting from UTF-8
to WCHAR_T
using GNU libiconv on FreeBSD.
FreeBSD libc has its own iconv functions, but we use GNU libiconv (-Diconv=external
) in GLib instead. I forgot the reason of the decision, but it is probably related to the support of //TRANSLIT
. When converting from UTF-8
to WCHAR_T
using GNU libiconv, the return value seems to be always non-zero. For example, if you run
$ printf 123 | iconv -f UTF-8 -t WCHAR_T | xxd
00000000: 3100 0000 3200 0000 3300 0000 1...2...3...
You can see that it prints the expected result. However, if you use GDB to debug iconv
and set a breakpoint on libiconv
function, you will see that it returns 3 instead of 0. Therefore, if you do the same conversion with g_convert
, it returns an error because the return value is positive.
$ python3 -c 'from gi.repository import GLib; print(GLib.convert(b"123", "WCHAR_T", "UTF-8"))'
Traceback (most recent call last):
File "<string>", line 1, in <module>
gi.repository.GLib.Error: g_convert_error: Unrepresentable character in conversion input (1)
The code which wants to convert from UTF-8
to WCHAR_T
comes from function std::wostream& operator<<(std::wostream& os, const ustring& utf8_string)
, file glib/glibmm/ustring.cc
of glibmm. When __STDC_ISO_10646__
isn't defined and the OS isn't Windows, it calls g_convert
to convert a UTF-8
string to a wchar_t
string. The problem is currently worked around by glibmm@e798fa7b in glibmm upstream, but we know it is wrong. FreeBSD wchar_t isn't always UCS-4, so the code only works when the user uses an ASCII or Unicode locale.
Tag the reporter @_wiz_ and the commit author @pwithnall.