Skip to content

Commit f988da9

Browse files
committed
Restore old pgwin32_message_to_UTF16() behavior outside transactions.
Commit 49c817e replaced with a hard error the dubious pg_do_encoding_conversion() behavior when outside a transaction. Reintroduce the historic soft failure locally within pgwin32_message_to_UTF16(). This fixes errors when writing messages in less-common encodings to the Windows event log or console. Back-patch to 9.4, where the aforementioned commit first appeared. Per bug #13427 from Dmitri Bourlatchkov.
1 parent 3bfd401 commit f988da9

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/backend/utils/mb/mbutils.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,8 @@ pgwin32_message_to_UTF16(const char *str, int len, int *utf16len)
10631063

10641064
/*
10651065
* Use MultiByteToWideChar directly if there is a corresponding codepage,
1066-
* or double conversion through UTF8 if not.
1066+
* or double conversion through UTF8 if not. Double conversion is needed,
1067+
* for example, in an ENCODING=LATIN8, LC_CTYPE=C database.
10671068
*/
10681069
if (codepage != 0)
10691070
{
@@ -1075,12 +1076,21 @@ pgwin32_message_to_UTF16(const char *str, int len, int *utf16len)
10751076
{
10761077
char *utf8;
10771078

1078-
utf8 = (char *) pg_do_encoding_conversion((unsigned char *) str,
1079-
len,
1080-
GetMessageEncoding(),
1081-
PG_UTF8);
1082-
if (utf8 != str)
1083-
len = strlen(utf8);
1079+
/*
1080+
* XXX pg_do_encoding_conversion() requires a transaction. In the
1081+
* absence of one, hope for the input to be valid UTF8.
1082+
*/
1083+
if (IsTransactionState())
1084+
{
1085+
utf8 = (char *) pg_do_encoding_conversion((unsigned char *) str,
1086+
len,
1087+
GetMessageEncoding(),
1088+
PG_UTF8);
1089+
if (utf8 != str)
1090+
len = strlen(utf8);
1091+
}
1092+
else
1093+
utf8 = (char *) str;
10841094

10851095
utf16 = (WCHAR *) palloc(sizeof(WCHAR) * (len + 1));
10861096
dstlen = MultiByteToWideChar(CP_UTF8, 0, utf8, len, utf16, len);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy