Tom Lane wrote: > Alvaro Herrera <alvhe...@commandprompt.com> writes: > > Understood. In fact, after having a look at this patch and giving it a > > little refactoring I think it's pretty obvious; right now we're calling > > bind_textdomain_codeset only for the main domain, and with this patch we > > also set it for all other domains we use.
> More generally, should we push the bindtextdomain calls themselves into > the new function (and perhaps call it something else than > SetDomainCodeSet)? Seems like logically this should be thought of as > all one operation, ie, it's not clear to me that it ever makes sense to > call bindtextdomain without also worrying about encoding. I'm not sure that can be made to work easily. On the backend itself we call bindtextdomain in set_pglocale_pgservice() which is also used by programs in src/bin/. Shuffling things in there would be more involved than seems worth. As for names, how about pg_bind_textdomain_codeset? -- Alvaro Herrera http://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc.
Index: src/backend/utils/init/miscinit.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/utils/init/miscinit.c,v retrieving revision 1.172 diff -c -p -r1.172 miscinit.c *** src/backend/utils/init/miscinit.c 5 Jan 2009 13:57:12 -0000 1.172 --- src/backend/utils/init/miscinit.c 7 Mar 2009 23:39:00 -0000 *************** *** 30,35 **** --- 30,36 ---- #endif #include "catalog/pg_authid.h" + #include "mb/pg_wchar.h" #include "miscadmin.h" #include "postmaster/autovacuum.h" #include "storage/fd.h" *************** pg_bindtextdomain(const char *domain) *** 1241,1246 **** --- 1242,1248 ---- get_locale_path(my_exec_path, locale_path); bindtextdomain(domain, locale_path); + pg_bind_textdomain_codeset(domain, GetDatabaseEncoding()); } #endif } Index: src/backend/utils/mb/mbutils.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/utils/mb/mbutils.c,v retrieving revision 1.79 diff -c -p -r1.79 mbutils.c *** src/backend/utils/mb/mbutils.c 2 Mar 2009 15:10:09 -0000 1.79 --- src/backend/utils/mb/mbutils.c 7 Mar 2009 23:37:22 -0000 *************** SetDatabaseEncoding(int encoding) *** 891,912 **** DatabaseEncoding = &pg_enc2name_tbl[encoding]; 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 --- 891,917 ---- DatabaseEncoding = &pg_enc2name_tbl[encoding]; Assert(DatabaseEncoding->encoding == encoding); ! pg_bind_textdomain_codeset(textdomain(NULL), encoding); ! } ! ! /* ! * On Windows, we need to explicitly bind gettext to the correct ! * encoding, because gettext() tends to get confused. ! */ ! void ! pg_bind_textdomain_codeset(const char *domainname, int encoding) ! { #if defined(ENABLE_NLS) && defined(WIN32) ! int i; ! for (i = 0; i < lengthof(codeset_map_array); i++) ! { ! if (codeset_map_array[i].encoding == encoding) { ! if (bind_textdomain_codeset(domainname, ! codeset_map_array[i].codeset) == NULL) ! elog(LOG, "bind_textdomain_codeset failed"); ! break; } } #endif Index: src/include/mb/pg_wchar.h =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/include/mb/pg_wchar.h,v retrieving revision 1.84 diff -c -p -r1.84 pg_wchar.h *** src/include/mb/pg_wchar.h 10 Feb 2009 19:29:39 -0000 1.84 --- src/include/mb/pg_wchar.h 7 Mar 2009 23:37:42 -0000 *************** extern const char *pg_get_client_encodin *** 392,397 **** --- 392,398 ---- extern void SetDatabaseEncoding(int encoding); extern int GetDatabaseEncoding(void); extern const char *GetDatabaseEncodingName(void); + extern void pg_bind_textdomain_codeset(const char *domainname, int encoding); extern int pg_valid_client_encoding(const char *name); extern int pg_valid_server_encoding(const char *name);
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers