Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5db55c6

Browse files
committed
Remove wchar.c Asserts that were stricter than the main code
Assert errors were thrown for functions being passed invalid encodings, while the main code handled it just fine. Also document that libpq's PQclientEncoding() returns -1 for an encoding lookup failure. Per report from Peter Geoghegan
1 parent 0b5c0f3 commit 5db55c6

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

doc/src/sgml/libpq.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5377,7 +5377,8 @@ int PQclientEncoding(const PGconn *<replaceable>conn</replaceable>);
53775377
</synopsis>
53785378

53795379
Note that it returns the encoding ID, not a symbolic string
5380-
such as <literal>EUC_JP</literal>. To convert an encoding ID to an encoding name, you
5380+
such as <literal>EUC_JP</literal>. If unsuccessful, it returns -1.
5381+
To convert an encoding ID to an encoding name, you
53815382
can use:
53825383

53835384
<synopsis>

src/backend/utils/mb/wchar.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,10 +1778,7 @@ pg_mic_mblen(const unsigned char *mbstr)
17781778
int
17791779
pg_encoding_mblen(int encoding, const char *mbstr)
17801780
{
1781-
Assert(PG_VALID_ENCODING(encoding));
1782-
1783-
return ((encoding >= 0 &&
1784-
encoding < sizeof(pg_wchar_table) / sizeof(pg_wchar_tbl)) ?
1781+
return (PG_VALID_ENCODING(encoding) ?
17851782
((*pg_wchar_table[encoding].mblen) ((const unsigned char *) mbstr)) :
17861783
((*pg_wchar_table[PG_SQL_ASCII].mblen) ((const unsigned char *) mbstr)));
17871784
}
@@ -1792,10 +1789,7 @@ pg_encoding_mblen(int encoding, const char *mbstr)
17921789
int
17931790
pg_encoding_dsplen(int encoding, const char *mbstr)
17941791
{
1795-
Assert(PG_VALID_ENCODING(encoding));
1796-
1797-
return ((encoding >= 0 &&
1798-
encoding < sizeof(pg_wchar_table) / sizeof(pg_wchar_tbl)) ?
1792+
return (PG_VALID_ENCODING(encoding) ?
17991793
((*pg_wchar_table[encoding].dsplen) ((const unsigned char *) mbstr)) :
18001794
((*pg_wchar_table[PG_SQL_ASCII].dsplen) ((const unsigned char *) mbstr)));
18011795
}
@@ -1808,12 +1802,9 @@ pg_encoding_dsplen(int encoding, const char *mbstr)
18081802
int
18091803
pg_encoding_verifymb(int encoding, const char *mbstr, int len)
18101804
{
1811-
Assert(PG_VALID_ENCODING(encoding));
1812-
1813-
return ((encoding >= 0 &&
1814-
encoding < sizeof(pg_wchar_table) / sizeof(pg_wchar_tbl)) ?
1815-
((*pg_wchar_table[encoding].mbverify) ((const unsigned char *) mbstr, len)) :
1816-
((*pg_wchar_table[PG_SQL_ASCII].mbverify) ((const unsigned char *) mbstr, len)));
1805+
return (PG_VALID_ENCODING(encoding) ?
1806+
((*pg_wchar_table[encoding].mbverify) ((const unsigned char *) mbstr, len)) :
1807+
((*pg_wchar_table[PG_SQL_ASCII].mbverify) ((const unsigned char *) mbstr, len)));
18171808
}
18181809

18191810
/*

0 commit comments

Comments
 (0)