Re: Re: [COMMITTERS] pgsql: Explicitly bind gettext() to the UTF8 locale when in use. - Mailing list pgsql-hackers
From | Magnus Hagander |
---|---|
Subject | Re: Re: [COMMITTERS] pgsql: Explicitly bind gettext() to the UTF8 locale when in use. |
Date | |
Msg-id | 49772466.4090107@hagander.net Whole thread Raw |
In response to | Re: Re: [COMMITTERS] pgsql: Explicitly bind gettext() to the UTF8 locale when in use. (Peter Eisentraut <peter_e@gmx.net>) |
Responses |
Re: Re: [COMMITTERS] pgsql: Explicitly bind gettext() to
the UTF8 locale when in use.
Re: Re: [COMMITTERS] pgsql: Explicitly bind gettext() to the UTF8 locale when in use. |
List | pgsql-hackers |
Peter Eisentraut wrote: > Magnus Hagander wrote: >> However, one question: The comment currently says it's harmless to do >> this on non-windows platforms. Does this still hold true? > > Yes, the non-WIN32 code path appears to be the same, still. But the > ifdef WIN32 part we don't want, because that presumes something about > the spelling of encoding names in the local iconv library. > >> If we do keep the thing win32 only, I think we should just wrap the >> whole thing in #ifdef WIN32 and no longer do the codeset stuff at all on >> Unix - that'll make for cleaner code. > > Yes, that would be much better. Something like this then? //Magnus *** a/src/backend/utils/mb/mbutils.c --- b/src/backend/utils/mb/mbutils.c *************** *** 849,854 **** cliplen(const char *str, int len, int limit) --- 849,894 ---- return l; } + #if defined(ENABLE_NLS) && defined(WIN32) + static const struct codeset_map { + int encoding; + const char *codeset; + } codeset_map_array[] = { + {PG_UTF8, "UTF-8"}, + {PG_LATIN1, "LATIN1"}, + {PG_LATIN2, "LATIN2"}, + {PG_LATIN3, "LATIN3"}, + {PG_LATIN4, "LATIN4"}, + {PG_ISO_8859_5, "ISO-8859-5"}, + {PG_ISO_8859_6, "ISO_8859-6"}, + {PG_ISO_8859_7, "ISO-8859-7"}, + {PG_ISO_8859_8, "ISO-8859-8"}, + {PG_LATIN5, "LATIN5"}, + {PG_LATIN6, "LATIN6"}, + {PG_LATIN7, "LATIN7"}, + {PG_LATIN8, "LATIN8"}, + {PG_LATIN9, "LATIN-9"}, + {PG_LATIN10, "LATIN10"}, + {PG_KOI8R, "KOI8-R"}, + {PG_WIN1250, "CP1250"}, + {PG_WIN1251, "CP1251"}, + {PG_WIN1252, "CP1252"}, + {PG_WIN1253, "CP1253"}, + {PG_WIN1254, "CP1254"}, + {PG_WIN1255, "CP1255"}, + {PG_WIN1256, "CP1256"}, + {PG_WIN1257, "CP1257"}, + {PG_WIN1258, "CP1258"}, + {PG_WIN866, "CP866"}, + {PG_WIN874, "CP874"}, + {PG_EUC_CN, "EUC-CN"}, + {PG_EUC_JP, "EUC-JP"}, + {PG_EUC_KR, "EUC-KR"}, + {PG_EUC_TW, "EUC-TW"}, + {PG_EUC_JIS_2004, "EUC-JP"} + }; + #endif /* WIN32 */ + void SetDatabaseEncoding(int encoding) { *************** *** 859,880 **** SetDatabaseEncoding(int encoding) Assert(DatabaseEncoding->encoding == encoding); /* ! * On Windows, we allow UTF-8 database encoding to be used with any ! * locale setting, because UTF-8 requires special handling anyway. ! * But this means that gettext() might be misled about what output ! * encoding it should use, so we have to tell it explicitly. ! * ! * In future we might want to call bind_textdomain_codeset ! * unconditionally, but that requires knowing how to spell the codeset ! * name properly for all encodings on all platforms, which might be ! * problematic. ! * ! * This is presently unnecessary, but harmless, on non-Windows platforms. */ ! #ifdef ENABLE_NLS ! if (encoding == PG_UTF8) ! if (bind_textdomain_codeset(textdomain(NULL), "UTF-8") == NULL) ! elog(LOG, "bind_textdomain_codeset failed"); #endif } --- 899,921 ---- Assert(DatabaseEncoding->encoding == encoding); /* ! * On Windows, we need to explicitly bind gettext to the correct ! * encoding, because gettext() tends to get confused. */ ! #if defined(ENABLE_NLS) && defined(WIN32) ! { ! int i; ! ! for (i = 0; i < sizeof(codeset_map_array) / sizeof(codeset_map_array[0]); i++) ! { ! if (codeset_map_array[i].encoding == encoding) ! { ! if (bind_textdomain_codeset(textdomain(NULL), codeset_map_array[i].codeset) == NULL) ! elog(LOG, "bind_textdomain_codeset failed"); ! break; ! } ! } ! } #endif }
pgsql-hackers by date: