Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1fe5020

Browse files
committed
Tell gettext which codeset to use by calling bind_textdomain_codeset(). We
already did that on Windows, but it's needed on other platforms too whenLC_CTYPE=C. With other locales, we enforce (or trust) that the codeset ofthe locale matches the server encoding so we don't need to bind itexplicitly. It should do no harm in that case either, but I don't havefull faith in the PG encoding -> OS codeset mapping table yet. Per recentdiscussion on pgsql-hackers.
1 parentbaf048d commit1fe5020

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

‎src/backend/utils/init/miscinit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.173 2009/03/0816:07:12 alvherre Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.174 2009/04/0809:50:48 heikki Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1242,7 +1242,7 @@ pg_bindtextdomain(const char *domain)
12421242

12431243
get_locale_path(my_exec_path,locale_path);
12441244
bindtextdomain(domain,locale_path);
1245-
pg_bind_textdomain_codeset(domain,GetDatabaseEncoding());
1245+
pg_bind_textdomain_codeset(domain);
12461246
}
12471247
#endif
12481248
}

‎src/backend/utils/init/postinit.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.188 2009/02/18 15:58:41 heikki Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.189 2009/04/08 09:50:48 heikki Exp $
1212
*
1313
*
1414
*-------------------------------------------------------------------------
@@ -265,6 +265,9 @@ CheckMyDatabase(const char *name, bool am_superuser)
265265
SetConfigOption("lc_collate",collate,PGC_INTERNAL,PGC_S_OVERRIDE);
266266
SetConfigOption("lc_ctype",ctype,PGC_INTERNAL,PGC_S_OVERRIDE);
267267

268+
/* Use the right encoding in translated messages */
269+
pg_bind_textdomain_codeset(textdomain(NULL));
270+
268271
/*
269272
* Lastly, set up any database-specific configuration variables.
270273
*/

‎src/backend/utils/mb/mbutils.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Tatsuo Ishii
66
*
7-
* $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.84 2009/04/06 19:34:52 petere Exp $
7+
* $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.85 2009/04/08 09:50:48 heikki Exp $
88
*/
99
#include"postgres.h"
1010

@@ -890,7 +890,7 @@ cliplen(const char *str, int len, int limit)
890890
returnl;
891891
}
892892

893-
#if defined(ENABLE_NLS)&& defined(WIN32)
893+
#if defined(ENABLE_NLS)
894894
staticconststructcodeset_map {
895895
intencoding;
896896
constchar*codeset;
@@ -929,7 +929,7 @@ static const struct codeset_map {
929929
{PG_EUC_TW,"EUC-TW"},
930930
{PG_EUC_JIS_2004,"EUC-JP"}
931931
};
932-
#endif/*WIN32 */
932+
#endif/*ENABLE_NLS */
933933

934934
void
935935
SetDatabaseEncoding(intencoding)
@@ -939,22 +939,36 @@ SetDatabaseEncoding(int encoding)
939939

940940
DatabaseEncoding=&pg_enc2name_tbl[encoding];
941941
Assert(DatabaseEncoding->encoding==encoding);
942-
943-
#ifdefENABLE_NLS
944-
pg_bind_textdomain_codeset(textdomain(NULL),encoding);
945-
#endif
946942
}
947943

948944
/*
949-
* On Windows, we need to explicitly bind gettext to the correct
950-
* encoding, because gettext() tends to get confused.
945+
* Bind gettext to the codeset equivalent with the database encoding.
951946
*/
952947
void
953-
pg_bind_textdomain_codeset(constchar*domainname,intencoding)
948+
pg_bind_textdomain_codeset(constchar*domainname)
954949
{
955-
#if defined(ENABLE_NLS)&& defined(WIN32)
950+
#if defined(ENABLE_NLS)
951+
intencoding=GetDatabaseEncoding();
956952
inti;
957953

954+
/*
955+
* gettext() uses the codeset specified by LC_CTYPE by default,
956+
* so if that matches the database encoding we don't need to do
957+
* anything. In CREATE DATABASE, we enforce or trust that the
958+
* locale's codeset matches database encoding, except for the C
959+
* locale. In C locale, we bind gettext() explicitly to the right
960+
* codeset.
961+
*
962+
* On Windows, though, gettext() tends to get confused so we always
963+
* bind it.
964+
*/
965+
#ifndefWIN32
966+
constchar*ctype=setlocale(LC_CTYPE,NULL);
967+
968+
if (pg_strcasecmp(ctype,"C")!=0&&pg_strcasecmp(ctype,"POSIX")!=0)
969+
return;
970+
#endif
971+
958972
for (i=0;i<lengthof(codeset_map_array);i++)
959973
{
960974
if (codeset_map_array[i].encoding==encoding)

‎src/include/mb/pg_wchar.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/mb/pg_wchar.h,v 1.88 2009/04/02 17:30:53 tgl Exp $
9+
* $PostgreSQL: pgsql/src/include/mb/pg_wchar.h,v 1.89 2009/04/08 09:50:48 heikki Exp $
1010
*
1111
*NOTES
1212
*This is used both by the backend and by libpq, but should not be
@@ -391,7 +391,7 @@ extern const char *pg_get_client_encoding_name(void);
391391
externvoidSetDatabaseEncoding(intencoding);
392392
externintGetDatabaseEncoding(void);
393393
externconstchar*GetDatabaseEncodingName(void);
394-
externvoidpg_bind_textdomain_codeset(constchar*domainname,intencoding);
394+
externvoidpg_bind_textdomain_codeset(constchar*domainname);
395395

396396
externintpg_valid_client_encoding(constchar*name);
397397
externintpg_valid_server_encoding(constchar*name);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp