Skip to content

Commit ea7f964

Browse files
committed
Explicitly bind gettext() to the UTF8 locale when in use.
This is required on Windows due to the special locale handling for UTF8 that doesn't change the full environment. Fixes crash with translated error messages per bugs 4180 and 4196. Tom Lane
1 parent 7b8a63c commit ea7f964

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/backend/utils/mb/mbutils.c

+20-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* (currently mule internal code (mic) is used)
55
* Tatsuo Ishii
66
*
7-
* $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.70 2008/04/12 23:21:04 tgl Exp $
7+
* $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.71 2008/05/27 12:24:42 mha Exp $
88
*/
99
#include "postgres.h"
1010

@@ -697,6 +697,25 @@ SetDatabaseEncoding(int encoding)
697697

698698
DatabaseEncoding = &pg_enc2name_tbl[encoding];
699699
Assert(DatabaseEncoding->encoding == encoding);
700+
701+
/*
702+
* On Windows, we allow UTF-8 database encoding to be used with any
703+
* locale setting, because UTF-8 requires special handling anyway.
704+
* But this means that gettext() might be misled about what output
705+
* encoding it should use, so we have to tell it explicitly.
706+
*
707+
* In future we might want to call bind_textdomain_codeset
708+
* unconditionally, but that requires knowing how to spell the codeset
709+
* name properly for all encodings on all platforms, which might be
710+
* problematic.
711+
*
712+
* This is presently unnecessary, but harmless, on non-Windows platforms.
713+
*/
714+
#ifdef ENABLE_NLS
715+
if (encoding == PG_UTF8)
716+
if (bind_textdomain_codeset("postgres", "UTF-8") == NULL)
717+
elog(LOG, "bind_textdomain_codeset failed");
718+
#endif
700719
}
701720

702721
void

0 commit comments

Comments
 (0)