]> granicus.if.org Git - postgresql/commitdiff
Replace argument-checking Asserts with regular test-and-elog checks in all
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 29 Jan 2009 19:24:37 +0000 (19:24 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 29 Jan 2009 19:24:37 +0000 (19:24 +0000)
encoding conversion functions.  These are not can't-happen cases because
it's possible to create a conversion with the wrong conversion function
for the specified encoding pair.  That would lead to an Assert crash in
an Assert-enabled build, or incorrect conversion otherwise, neither of
which is desirable.  This would be a DOS issue if production databases
were customarily built with asserts enabled, but fortunately that's not so.
Per an observation by Heikki.

Back-patch to all supported branches.

29 files changed:
src/backend/utils/mb/conversion_procs/ascii_and_mic/ascii_and_mic.c
src/backend/utils/mb/conversion_procs/cyrillic_and_mic/cyrillic_and_mic.c
src/backend/utils/mb/conversion_procs/euc_cn_and_mic/euc_cn_and_mic.c
src/backend/utils/mb/conversion_procs/euc_jp_and_sjis/euc_jp_and_sjis.c
src/backend/utils/mb/conversion_procs/euc_kr_and_mic/euc_kr_and_mic.c
src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c
src/backend/utils/mb/conversion_procs/latin2_and_win1250/latin2_and_win1250.c
src/backend/utils/mb/conversion_procs/latin_and_mic/latin_and_mic.c
src/backend/utils/mb/conversion_procs/utf8_and_ascii/utf8_and_ascii.c
src/backend/utils/mb/conversion_procs/utf8_and_big5/utf8_and_big5.c
src/backend/utils/mb/conversion_procs/utf8_and_cyrillic/utf8_and_cyrillic.c
src/backend/utils/mb/conversion_procs/utf8_and_euc_cn/utf8_and_euc_cn.c
src/backend/utils/mb/conversion_procs/utf8_and_euc_jp/utf8_and_euc_jp.c
src/backend/utils/mb/conversion_procs/utf8_and_euc_kr/utf8_and_euc_kr.c
src/backend/utils/mb/conversion_procs/utf8_and_euc_tw/utf8_and_euc_tw.c
src/backend/utils/mb/conversion_procs/utf8_and_gb18030/utf8_and_gb18030.c
src/backend/utils/mb/conversion_procs/utf8_and_gbk/utf8_and_gbk.c
src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c
src/backend/utils/mb/conversion_procs/utf8_and_iso8859_1/utf8_and_iso8859_1.c
src/backend/utils/mb/conversion_procs/utf8_and_johab/utf8_and_johab.c
src/backend/utils/mb/conversion_procs/utf8_and_sjis/utf8_and_sjis.c
src/backend/utils/mb/conversion_procs/utf8_and_uhc/utf8_and_uhc.c
src/backend/utils/mb/conversion_procs/utf8_and_win1250/utf8_and_win1250.c
src/backend/utils/mb/conversion_procs/utf8_and_win1252/utf8_and_win1252.c
src/backend/utils/mb/conversion_procs/utf8_and_win1256/utf8_and_win1256.c
src/backend/utils/mb/conversion_procs/utf8_and_win1258/utf8_and_win1258.c
src/backend/utils/mb/conversion_procs/utf8_and_win874/utf8_and_win874.c
src/backend/utils/mb/wchar.c
src/include/mb/pg_wchar.h

index 390780f318e2123695fdfe92461278ba4b2939f8..11995a44aa390444cc2c88719f35059547e2a1f5 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/ascii_and_mic/ascii_and_mic.c,v 1.10 2005/09/24 17:53:17 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/ascii_and_mic/ascii_and_mic.c,v 1.10.2.1 2009/01/29 19:24:36 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -39,9 +39,7 @@ ascii_to_mic(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_SQL_ASCII);
-       Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_SQL_ASCII, PG_MULE_INTERNAL);
 
        pg_ascii2mic(src, dest, len);
 
@@ -55,9 +53,7 @@ mic_to_ascii(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
-       Assert(PG_GETARG_INT32(1) == PG_SQL_ASCII);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_SQL_ASCII);
 
        pg_mic2ascii(src, dest, len);
 
index e7a5f15a36dfc8d40153e5318ab7928bc447720b..140fb45fde676cb39d5405006845b7bd9c4d84d8 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/cyrillic_and_mic/cyrillic_and_mic.c,v 1.11.2.2 2008/03/20 10:38:34 heikki Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/cyrillic_and_mic/cyrillic_and_mic.c,v 1.11.2.3 2009/01/29 19:24:36 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -86,9 +86,7 @@ koi8r_to_mic(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_KOI8R);
-       Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_MULE_INTERNAL);
 
        koi8r2mic(src, dest, len);
 
@@ -102,9 +100,7 @@ mic_to_koi8r(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
-       Assert(PG_GETARG_INT32(1) == PG_KOI8R);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_KOI8R);
 
        mic2koi8r(src, dest, len);
 
@@ -118,9 +114,7 @@ iso_to_mic(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_ISO_8859_5);
-       Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5, PG_MULE_INTERNAL);
 
        iso2mic(src, dest, len);
 
@@ -134,9 +128,7 @@ mic_to_iso(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
-       Assert(PG_GETARG_INT32(1) == PG_ISO_8859_5);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_ISO_8859_5);
 
        mic2iso(src, dest, len);
 
@@ -150,9 +142,7 @@ win1251_to_mic(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_WIN1251);
-       Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_MULE_INTERNAL);
 
        win12512mic(src, dest, len);
 
@@ -166,9 +156,7 @@ mic_to_win1251(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
-       Assert(PG_GETARG_INT32(1) == PG_WIN1251);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_WIN1251);
 
        mic2win1251(src, dest, len);
 
@@ -182,9 +170,7 @@ win866_to_mic(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_WIN866);
-       Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_WIN866, PG_MULE_INTERNAL);
 
        win8662mic(src, dest, len);
 
@@ -198,9 +184,7 @@ mic_to_win866(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
-       Assert(PG_GETARG_INT32(1) == PG_WIN866);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_WIN866);
 
        mic2win866(src, dest, len);
 
@@ -215,9 +199,7 @@ koi8r_to_win1251(PG_FUNCTION_ARGS)
        int                     len = PG_GETARG_INT32(4);
        unsigned char *buf;
 
-       Assert(PG_GETARG_INT32(0) == PG_KOI8R);
-       Assert(PG_GETARG_INT32(1) == PG_WIN1251);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_WIN1251);
 
        buf = palloc(len * ENCODING_GROWTH_RATE);
        koi8r2mic(src, buf, len);
@@ -235,9 +217,7 @@ win1251_to_koi8r(PG_FUNCTION_ARGS)
        int                     len = PG_GETARG_INT32(4);
        unsigned char *buf;
 
-       Assert(PG_GETARG_INT32(0) == PG_WIN1251);
-       Assert(PG_GETARG_INT32(1) == PG_KOI8R);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_KOI8R);
 
        buf = palloc(len * ENCODING_GROWTH_RATE);
        win12512mic(src, buf, len);
@@ -255,9 +235,7 @@ koi8r_to_win866(PG_FUNCTION_ARGS)
        int                     len = PG_GETARG_INT32(4);
        unsigned char *buf;
 
-       Assert(PG_GETARG_INT32(0) == PG_KOI8R);
-       Assert(PG_GETARG_INT32(1) == PG_WIN866);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_WIN866);
 
        buf = palloc(len * ENCODING_GROWTH_RATE);
        koi8r2mic(src, buf, len);
@@ -275,9 +253,7 @@ win866_to_koi8r(PG_FUNCTION_ARGS)
        int                     len = PG_GETARG_INT32(4);
        unsigned char *buf;
 
-       Assert(PG_GETARG_INT32(0) == PG_WIN866);
-       Assert(PG_GETARG_INT32(1) == PG_KOI8R);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_WIN866, PG_KOI8R);
 
        buf = palloc(len * ENCODING_GROWTH_RATE);
        win8662mic(src, buf, len);
@@ -295,9 +271,7 @@ win866_to_win1251(PG_FUNCTION_ARGS)
        int                     len = PG_GETARG_INT32(4);
        unsigned char *buf;
 
-       Assert(PG_GETARG_INT32(0) == PG_WIN866);
-       Assert(PG_GETARG_INT32(1) == PG_WIN1251);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_WIN866, PG_WIN1251);
 
        /*
         * Note: There are a few characters like the "Numero" sign that exist in
@@ -321,9 +295,7 @@ win1251_to_win866(PG_FUNCTION_ARGS)
        int                     len = PG_GETARG_INT32(4);
        unsigned char *buf;
 
-       Assert(PG_GETARG_INT32(0) == PG_WIN1251);
-       Assert(PG_GETARG_INT32(1) == PG_WIN866);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_WIN866);
 
        /* Use mic/KOI8R as intermediary, see comment in win866_to_win1251() */
        buf = palloc(len * ENCODING_GROWTH_RATE);
@@ -342,9 +314,7 @@ iso_to_koi8r(PG_FUNCTION_ARGS)
        int                     len = PG_GETARG_INT32(4);
        unsigned char *buf;
 
-       Assert(PG_GETARG_INT32(0) == PG_ISO_8859_5);
-       Assert(PG_GETARG_INT32(1) == PG_KOI8R);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5, PG_KOI8R);
 
        buf = palloc(len * ENCODING_GROWTH_RATE);
        iso2mic(src, buf, len);
@@ -362,9 +332,7 @@ koi8r_to_iso(PG_FUNCTION_ARGS)
        int                     len = PG_GETARG_INT32(4);
        unsigned char *buf;
 
-       Assert(PG_GETARG_INT32(0) == PG_KOI8R);
-       Assert(PG_GETARG_INT32(1) == PG_ISO_8859_5);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_ISO_8859_5);
 
        buf = palloc(len * ENCODING_GROWTH_RATE);
        koi8r2mic(src, buf, len);
@@ -382,9 +350,7 @@ iso_to_win1251(PG_FUNCTION_ARGS)
        int                     len = PG_GETARG_INT32(4);
        unsigned char *buf;
 
-       Assert(PG_GETARG_INT32(0) == PG_ISO_8859_5);
-       Assert(PG_GETARG_INT32(1) == PG_WIN1251);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5, PG_WIN1251);
 
        /* Use mic/KOI8R as intermediary, see comment in win866_to_win1251() */
        buf = palloc(len * ENCODING_GROWTH_RATE);
@@ -403,9 +369,7 @@ win1251_to_iso(PG_FUNCTION_ARGS)
        int                     len = PG_GETARG_INT32(4);
        unsigned char *buf;
 
-       Assert(PG_GETARG_INT32(0) == PG_WIN1251);
-       Assert(PG_GETARG_INT32(1) == PG_ISO_8859_5);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_ISO_8859_5);
 
        /* Use mic/KOI8R as intermediary, see comment in win866_to_win1251() */
        buf = palloc(len * ENCODING_GROWTH_RATE);
@@ -424,9 +388,7 @@ iso_to_win866(PG_FUNCTION_ARGS)
        int                     len = PG_GETARG_INT32(4);
        unsigned char *buf;
 
-       Assert(PG_GETARG_INT32(0) == PG_ISO_8859_5);
-       Assert(PG_GETARG_INT32(1) == PG_WIN866);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5, PG_WIN866);
 
        /* Use mic/KOI8R as intermediary, see comment in win866_to_win1251() */
        buf = palloc(len * ENCODING_GROWTH_RATE);
@@ -445,9 +407,7 @@ win866_to_iso(PG_FUNCTION_ARGS)
        int                     len = PG_GETARG_INT32(4);
        unsigned char *buf;
 
-       Assert(PG_GETARG_INT32(0) == PG_WIN866);
-       Assert(PG_GETARG_INT32(1) == PG_ISO_8859_5);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_WIN866, PG_ISO_8859_5);
 
        /* Use mic/KOI8R as intermediary, see comment in win866_to_win1251() */
        buf = palloc(len * ENCODING_GROWTH_RATE);
index b81165e7c018196c655d7ba7822869657ea496f7..c6376276b54ea8e6671e15d3f806a8d47cbfa3b6 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_cn_and_mic/euc_cn_and_mic.c,v 1.10.2.1 2006/05/21 20:05:48 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_cn_and_mic/euc_cn_and_mic.c,v 1.10.2.2 2009/01/29 19:24:36 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -42,9 +42,7 @@ euc_cn_to_mic(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_EUC_CN);
-       Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_CN, PG_MULE_INTERNAL);
 
        euc_cn2mic(src, dest, len);
 
@@ -58,9 +56,7 @@ mic_to_euc_cn(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
-       Assert(PG_GETARG_INT32(1) == PG_EUC_CN);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_EUC_CN);
 
        mic2euc_cn(src, dest, len);
 
index ac6b716695cbd389bd608de804c577745df74bb5..fab4db86f5f375b7b8e7bf48585362fb1af4b358 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_jp_and_sjis/euc_jp_and_sjis.c,v 1.13.2.2 2006/05/21 20:05:48 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_jp_and_sjis/euc_jp_and_sjis.c,v 1.13.2.3 2009/01/29 19:24:36 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -68,9 +68,7 @@ euc_jp_to_sjis(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_EUC_JP);
-       Assert(PG_GETARG_INT32(1) == PG_SJIS);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_JP, PG_SJIS);
 
        euc_jp2sjis(src, dest, len);
 
@@ -84,9 +82,7 @@ sjis_to_euc_jp(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_SJIS);
-       Assert(PG_GETARG_INT32(1) == PG_EUC_JP);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_SJIS, PG_EUC_JP);
 
        sjis2euc_jp(src, dest, len);
 
@@ -100,9 +96,7 @@ euc_jp_to_mic(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_EUC_JP);
-       Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_JP, PG_MULE_INTERNAL);
 
        euc_jp2mic(src, dest, len);
 
@@ -116,9 +110,7 @@ mic_to_euc_jp(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
-       Assert(PG_GETARG_INT32(1) == PG_EUC_JP);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_EUC_JP);
 
        mic2euc_jp(src, dest, len);
 
@@ -132,9 +124,7 @@ sjis_to_mic(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_SJIS);
-       Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_SJIS, PG_MULE_INTERNAL);
 
        sjis2mic(src, dest, len);
 
@@ -148,9 +138,7 @@ mic_to_sjis(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
-       Assert(PG_GETARG_INT32(1) == PG_SJIS);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_SJIS);
 
        mic2sjis(src, dest, len);
 
index b6262e04d23f198c448f10d8d5ea3ecbc822f8be..62b40229188158193a01c6c2f51581e3e7cec0dc 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_kr_and_mic/euc_kr_and_mic.c,v 1.10.2.1 2006/05/21 20:05:48 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_kr_and_mic/euc_kr_and_mic.c,v 1.10.2.2 2009/01/29 19:24:36 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -42,9 +42,7 @@ euc_kr_to_mic(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_EUC_KR);
-       Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_KR, PG_MULE_INTERNAL);
 
        euc_kr2mic(src, dest, len);
 
@@ -58,9 +56,7 @@ mic_to_euc_kr(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
-       Assert(PG_GETARG_INT32(1) == PG_EUC_KR);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_EUC_KR);
 
        mic2euc_kr(src, dest, len);
 
index 789684e3ad3a2816a9b540833610f6cf95fe9e17..7e4612f5ada49c3c5ee3ad6cafb5291d54004758 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c,v 1.10.2.1 2006/05/21 20:05:48 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c,v 1.10.2.2 2009/01/29 19:24:36 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -55,9 +55,7 @@ euc_tw_to_big5(PG_FUNCTION_ARGS)
        int                     len = PG_GETARG_INT32(4);
        unsigned char *buf;
 
-       Assert(PG_GETARG_INT32(0) == PG_EUC_TW);
-       Assert(PG_GETARG_INT32(1) == PG_BIG5);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_TW, PG_BIG5);
 
        buf = palloc(len * ENCODING_GROWTH_RATE);
        euc_tw2mic(src, buf, len);
@@ -75,9 +73,7 @@ big5_to_euc_tw(PG_FUNCTION_ARGS)
        int                     len = PG_GETARG_INT32(4);
        unsigned char *buf;
 
-       Assert(PG_GETARG_INT32(0) == PG_BIG5);
-       Assert(PG_GETARG_INT32(1) == PG_EUC_TW);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_BIG5, PG_EUC_TW);
 
        buf = palloc(len * ENCODING_GROWTH_RATE);
        big52mic(src, buf, len);
@@ -94,9 +90,7 @@ euc_tw_to_mic(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_EUC_TW);
-       Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_TW, PG_MULE_INTERNAL);
 
        euc_tw2mic(src, dest, len);
 
@@ -110,9 +104,7 @@ mic_to_euc_tw(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
-       Assert(PG_GETARG_INT32(1) == PG_EUC_TW);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_EUC_TW);
 
        mic2euc_tw(src, dest, len);
 
@@ -126,9 +118,7 @@ big5_to_mic(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_BIG5);
-       Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_BIG5, PG_MULE_INTERNAL);
 
        big52mic(src, dest, len);
 
@@ -142,9 +132,7 @@ mic_to_big5(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
-       Assert(PG_GETARG_INT32(1) == PG_BIG5);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_BIG5);
 
        mic2big5(src, dest, len);
 
index 4d75924a5a8099911bb56af3caac92938f5c6cc7..e5acb94a584885fe5f79dc69faeab9c9e745fe4f 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/latin2_and_win1250/latin2_and_win1250.c,v 1.10.2.1 2006/05/21 20:05:48 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/latin2_and_win1250/latin2_and_win1250.c,v 1.10.2.2 2009/01/29 19:24:36 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -54,9 +54,7 @@ latin2_to_mic(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_LATIN2);
-       Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN2, PG_MULE_INTERNAL);
 
        latin22mic(src, dest, len);
 
@@ -70,9 +68,7 @@ mic_to_latin2(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
-       Assert(PG_GETARG_INT32(1) == PG_LATIN2);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN2);
 
        mic2latin2(src, dest, len);
 
@@ -86,9 +82,7 @@ win1250_to_mic(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_WIN1250);
-       Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1250, PG_MULE_INTERNAL);
 
        win12502mic(src, dest, len);
 
@@ -102,9 +96,7 @@ mic_to_win1250(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
-       Assert(PG_GETARG_INT32(1) == PG_WIN1250);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_WIN1250);
 
        mic2win1250(src, dest, len);
 
@@ -119,9 +111,7 @@ latin2_to_win1250(PG_FUNCTION_ARGS)
        int                     len = PG_GETARG_INT32(4);
        unsigned char *buf;
 
-       Assert(PG_GETARG_INT32(0) == PG_LATIN2);
-       Assert(PG_GETARG_INT32(1) == PG_WIN1250);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN2, PG_WIN1250);
 
        buf = palloc(len * ENCODING_GROWTH_RATE);
        latin22mic(src, buf, len);
@@ -139,9 +129,7 @@ win1250_to_latin2(PG_FUNCTION_ARGS)
        int                     len = PG_GETARG_INT32(4);
        unsigned char *buf;
 
-       Assert(PG_GETARG_INT32(0) == PG_WIN1250);
-       Assert(PG_GETARG_INT32(1) == PG_LATIN2);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1250, PG_LATIN2);
 
        buf = palloc(len * ENCODING_GROWTH_RATE);
        win12502mic(src, buf, len);
index 807c19cde7ef4e8febb5e44172e200e60f0f67c6..8699e84260649a565cb64ddfa6324d4700bcee37 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/latin_and_mic/latin_and_mic.c,v 1.10.2.1 2006/05/21 20:05:48 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/latin_and_mic/latin_and_mic.c,v 1.10.2.2 2009/01/29 19:24:36 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -54,9 +54,7 @@ latin1_to_mic(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_LATIN1);
-       Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN1, PG_MULE_INTERNAL);
 
        latin12mic(src, dest, len);
 
@@ -70,9 +68,7 @@ mic_to_latin1(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
-       Assert(PG_GETARG_INT32(1) == PG_LATIN1);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN1);
 
        mic2latin1(src, dest, len);
 
@@ -86,9 +82,7 @@ latin3_to_mic(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_LATIN3);
-       Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN3, PG_MULE_INTERNAL);
 
        latin32mic(src, dest, len);
 
@@ -102,9 +96,7 @@ mic_to_latin3(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
-       Assert(PG_GETARG_INT32(1) == PG_LATIN3);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN3);
 
        mic2latin3(src, dest, len);
 
@@ -118,9 +110,7 @@ latin4_to_mic(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_LATIN4);
-       Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN4, PG_MULE_INTERNAL);
 
        latin42mic(src, dest, len);
 
@@ -134,9 +124,7 @@ mic_to_latin4(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL);
-       Assert(PG_GETARG_INT32(1) == PG_LATIN4);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN4);
 
        mic2latin4(src, dest, len);
 
index 2bba7506de26ddf84649e78aa1a69fada7172a5d..1bba3803e1eb291bd37fd0483808711ae53ecc13 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_ascii/utf8_and_ascii.c,v 1.11.2.1 2006/05/21 20:05:49 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_ascii/utf8_and_ascii.c,v 1.11.2.2 2009/01/29 19:24:36 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -39,9 +39,7 @@ ascii_to_utf8(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_SQL_ASCII);
-       Assert(PG_GETARG_INT32(1) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_SQL_ASCII, PG_UTF8);
 
        /* this looks wrong, but basically we're just rejecting high-bit-set */
        pg_ascii2mic(src, dest, len);
@@ -56,9 +54,7 @@ utf8_to_ascii(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_UTF8);
-       Assert(PG_GETARG_INT32(1) == PG_SQL_ASCII);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_SQL_ASCII);
 
        /* this looks wrong, but basically we're just rejecting high-bit-set */
        pg_mic2ascii(src, dest, len);
index 2539511204816bbf154db70849f968217015360e..734749ab4d589a50fb2869c24e274960d7ddc770 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_big5/utf8_and_big5.c,v 1.11.2.1 2006/05/21 20:05:49 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_big5/utf8_and_big5.c,v 1.11.2.2 2009/01/29 19:24:36 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -40,9 +40,7 @@ big5_to_utf8(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_BIG5);
-       Assert(PG_GETARG_INT32(1) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_BIG5, PG_UTF8);
 
        LocalToUtf(src, dest, LUmapBIG5,
                           sizeof(LUmapBIG5) / sizeof(pg_local_to_utf), PG_BIG5, len);
@@ -57,9 +55,7 @@ utf8_to_big5(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_UTF8);
-       Assert(PG_GETARG_INT32(1) == PG_BIG5);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_BIG5);
 
        UtfToLocal(src, dest, ULmapBIG5,
                           sizeof(ULmapBIG5) / sizeof(pg_utf_to_local), PG_BIG5, len);
index 36dd970be788bc4d36c5c6c020c02a2f42482a11..57cc1ce3aec154fe921e03c658725d8c6d54e835 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_cyrillic/utf8_and_cyrillic.c,v 1.12.2.1 2006/05/21 20:05:49 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_cyrillic/utf8_and_cyrillic.c,v 1.12.2.2 2009/01/29 19:24:36 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -53,9 +53,7 @@ utf8_to_koi8r(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_UTF8);
-       Assert(PG_GETARG_INT32(1) == PG_KOI8R);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_KOI8R);
 
        UtfToLocal(src, dest, ULmap_KOI8R,
                           sizeof(ULmap_KOI8R) / sizeof(pg_utf_to_local), PG_KOI8R, len);
@@ -70,9 +68,7 @@ koi8r_to_utf8(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_KOI8R);
-       Assert(PG_GETARG_INT32(1) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_UTF8);
 
        LocalToUtf(src, dest, LUmapKOI8R,
                           sizeof(LUmapKOI8R) / sizeof(pg_local_to_utf), PG_KOI8R, len);
@@ -87,9 +83,7 @@ utf8_to_win1251(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_UTF8);
-       Assert(PG_GETARG_INT32(1) == PG_WIN1251);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_WIN1251);
 
        UtfToLocal(src, dest, ULmap_WIN1251,
                           sizeof(ULmap_WIN1251) / sizeof(pg_utf_to_local), PG_WIN1251, len);
@@ -104,9 +98,7 @@ win1251_to_utf8(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_WIN1251);
-       Assert(PG_GETARG_INT32(1) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_UTF8);
 
        LocalToUtf(src, dest, LUmapWIN1251,
                        sizeof(LUmapWIN1251) / sizeof(pg_local_to_utf), PG_WIN1251, len);
@@ -121,9 +113,7 @@ utf8_to_win866(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_UTF8);
-       Assert(PG_GETARG_INT32(1) == PG_WIN866);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_WIN866);
 
        UtfToLocal(src, dest, ULmap_WIN866,
                           sizeof(ULmap_WIN866) / sizeof(pg_utf_to_local), PG_WIN866, len);
@@ -138,9 +128,7 @@ win866_to_utf8(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_WIN866);
-       Assert(PG_GETARG_INT32(1) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_WIN866, PG_UTF8);
 
        LocalToUtf(src, dest, LUmapWIN866,
                           sizeof(LUmapWIN866) / sizeof(pg_local_to_utf), PG_WIN866, len);
index af49ad156b79a8c13628f34b24136278f6e7234f..2991357315b2213735f00aee46e574a81380b539 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_cn/utf8_and_euc_cn.c,v 1.12.2.1 2006/05/21 20:05:49 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_cn/utf8_and_euc_cn.c,v 1.12.2.2 2009/01/29 19:24:36 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -40,9 +40,7 @@ euc_cn_to_utf8(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_EUC_CN);
-       Assert(PG_GETARG_INT32(1) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_CN, PG_UTF8);
 
        LocalToUtf(src, dest, LUmapEUC_CN,
                           sizeof(LUmapEUC_CN) / sizeof(pg_local_to_utf), PG_EUC_CN, len);
@@ -57,9 +55,7 @@ utf8_to_euc_cn(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_UTF8);
-       Assert(PG_GETARG_INT32(1) == PG_EUC_CN);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_EUC_CN);
 
        UtfToLocal(src, dest, ULmapEUC_CN,
                           sizeof(ULmapEUC_CN) / sizeof(pg_utf_to_local), PG_EUC_CN, len);
index 9d8a4b3f33bf3b54aa804a10e3ac41d2f7d81ca3..0186a2e1d757d720b316d688456f3514bbe2d632 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_jp/utf8_and_euc_jp.c,v 1.12.2.1 2006/05/21 20:05:49 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_jp/utf8_and_euc_jp.c,v 1.12.2.2 2009/01/29 19:24:37 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -40,9 +40,7 @@ euc_jp_to_utf8(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_EUC_JP);
-       Assert(PG_GETARG_INT32(1) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_JP, PG_UTF8);
 
        LocalToUtf(src, dest, LUmapEUC_JP,
                           sizeof(LUmapEUC_JP) / sizeof(pg_local_to_utf), PG_EUC_JP, len);
@@ -57,9 +55,7 @@ utf8_to_euc_jp(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_UTF8);
-       Assert(PG_GETARG_INT32(1) == PG_EUC_JP);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_EUC_JP);
 
        UtfToLocal(src, dest, ULmapEUC_JP,
                           sizeof(ULmapEUC_JP) / sizeof(pg_utf_to_local), PG_EUC_JP, len);
index 5b8bee5cca07ae3d2c5d106a0e0cdd6afc13dc09..b113dafd5d0cc889fe1c7d4fde6e46587cbab62d 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_kr/utf8_and_euc_kr.c,v 1.12.2.1 2006/05/21 20:05:49 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_kr/utf8_and_euc_kr.c,v 1.12.2.2 2009/01/29 19:24:37 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -40,9 +40,7 @@ euc_kr_to_utf8(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_EUC_KR);
-       Assert(PG_GETARG_INT32(1) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_KR, PG_UTF8);
 
        LocalToUtf(src, dest, LUmapEUC_KR,
                           sizeof(LUmapEUC_KR) / sizeof(pg_local_to_utf), PG_EUC_KR, len);
@@ -57,9 +55,7 @@ utf8_to_euc_kr(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_UTF8);
-       Assert(PG_GETARG_INT32(1) == PG_EUC_KR);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_EUC_KR);
 
        UtfToLocal(src, dest, ULmapEUC_KR,
                           sizeof(ULmapEUC_KR) / sizeof(pg_utf_to_local), PG_EUC_KR, len);
index f094fba44db183657cad5e0882fa2189761e9528..5213d3763b68bacc298899ac963efaad25776748 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_tw/utf8_and_euc_tw.c,v 1.12.2.1 2006/05/21 20:05:49 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_tw/utf8_and_euc_tw.c,v 1.12.2.2 2009/01/29 19:24:37 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -40,9 +40,7 @@ euc_tw_to_utf8(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_EUC_TW);
-       Assert(PG_GETARG_INT32(1) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_TW, PG_UTF8);
 
        LocalToUtf(src, dest, LUmapEUC_TW,
                           sizeof(LUmapEUC_TW) / sizeof(pg_local_to_utf), PG_EUC_TW, len);
@@ -57,9 +55,7 @@ utf8_to_euc_tw(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_UTF8);
-       Assert(PG_GETARG_INT32(1) == PG_EUC_TW);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_EUC_TW);
 
        UtfToLocal(src, dest, ULmapEUC_TW,
                           sizeof(ULmapEUC_TW) / sizeof(pg_utf_to_local), PG_EUC_TW, len);
index 0cbab9a1e5ebe393cc1e764fe6b5a5fa2f1c2254..0f9c3cd8f673dc8211dda9120d4e3ee81763f2b6 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_gb18030/utf8_and_gb18030.c,v 1.12.2.1 2006/05/21 20:05:49 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_gb18030/utf8_and_gb18030.c,v 1.12.2.2 2009/01/29 19:24:37 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -40,9 +40,7 @@ gb18030_to_utf8(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_GB18030);
-       Assert(PG_GETARG_INT32(1) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_GB18030, PG_UTF8);
 
        LocalToUtf(src, dest, LUmapGB18030,
                        sizeof(LUmapGB18030) / sizeof(pg_local_to_utf), PG_GB18030, len);
@@ -57,9 +55,7 @@ utf8_to_gb18030(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_UTF8);
-       Assert(PG_GETARG_INT32(1) == PG_GB18030);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_GB18030);
 
        UtfToLocal(src, dest, ULmapGB18030,
                           sizeof(ULmapGB18030) / sizeof(pg_utf_to_local), PG_GB18030, len);
index 5d2fb853f06f9e553fc5a954041a512c61bbf48c..68d3bf14900693926614e82033c0403d9536eba7 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_gbk/utf8_and_gbk.c,v 1.11.2.1 2006/05/21 20:05:49 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_gbk/utf8_and_gbk.c,v 1.11.2.2 2009/01/29 19:24:37 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -40,9 +40,7 @@ gbk_to_utf8(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_GBK);
-       Assert(PG_GETARG_INT32(1) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_GBK, PG_UTF8);
 
        LocalToUtf(src, dest, LUmapGBK,
                           sizeof(LUmapGBK) / sizeof(pg_local_to_utf), PG_GBK, len);
@@ -57,9 +55,7 @@ utf8_to_gbk(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_UTF8);
-       Assert(PG_GETARG_INT32(1) == PG_GBK);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_GBK);
 
        UtfToLocal(src, dest, ULmapGBK,
                           sizeof(ULmapGBK) / sizeof(pg_utf_to_local), PG_GBK, len);
index 3269cf477c60d964714c756faa28b110b65a9ada..0c259577120a427bbd326f55a823e780522fa3d7 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c,v 1.15.2.3 2006/05/21 20:05:49 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c,v 1.15.2.4 2009/01/29 19:24:37 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -118,8 +118,7 @@ iso8859_to_utf8(PG_FUNCTION_ARGS)
        int                     len = PG_GETARG_INT32(4);
        int     i;
 
-       Assert(PG_GETARG_INT32(1) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(-1, PG_UTF8);
 
        for (i=0;i<sizeof(maps)/sizeof(pg_conv_map);i++)
        {
@@ -146,8 +145,7 @@ utf8_to_iso8859(PG_FUNCTION_ARGS)
        int                     len = PG_GETARG_INT32(4);
        int     i;
 
-       Assert(PG_GETARG_INT32(0) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, -1);
 
        for (i=0;i<sizeof(maps)/sizeof(pg_conv_map);i++)
        {
index f92d9237e7b185a5d28f4d44618e4851ccd0e73f..990991500ce60e6588a5f3691975a0aa9389ee3d 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_iso8859_1/utf8_and_iso8859_1.c,v 1.12.2.1 2006/05/21 20:05:49 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_iso8859_1/utf8_and_iso8859_1.c,v 1.12.2.2 2009/01/29 19:24:37 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -40,9 +40,7 @@ iso8859_1_to_utf8(PG_FUNCTION_ARGS)
        int                     len = PG_GETARG_INT32(4);
        unsigned short c;
 
-       Assert(PG_GETARG_INT32(0) == PG_LATIN1);
-       Assert(PG_GETARG_INT32(1) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN1, PG_UTF8);
 
        while (len > 0)
        {
@@ -73,9 +71,7 @@ utf8_to_iso8859_1(PG_FUNCTION_ARGS)
        unsigned short c,
                                c1;
 
-       Assert(PG_GETARG_INT32(0) == PG_UTF8);
-       Assert(PG_GETARG_INT32(1) == PG_LATIN1);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_LATIN1);
 
        while (len > 0)
        {
index 7492ca1a4a5d31f34ed10670d73ce9b086516bd7..4913841195e25371de8789260953fa6776dbedf5 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_johab/utf8_and_johab.c,v 1.12.2.1 2006/05/21 20:05:49 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_johab/utf8_and_johab.c,v 1.12.2.2 2009/01/29 19:24:37 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -40,9 +40,7 @@ johab_to_utf8(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_JOHAB);
-       Assert(PG_GETARG_INT32(1) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_JOHAB, PG_UTF8);
 
        LocalToUtf(src, dest, LUmapJOHAB,
                           sizeof(LUmapJOHAB) / sizeof(pg_local_to_utf), PG_JOHAB, len);
@@ -57,9 +55,7 @@ utf8_to_johab(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_UTF8);
-       Assert(PG_GETARG_INT32(1) == PG_JOHAB);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_JOHAB);
 
        UtfToLocal(src, dest, ULmapJOHAB,
                           sizeof(ULmapJOHAB) / sizeof(pg_utf_to_local), PG_JOHAB, len);
index 753d6bce38f326fe277094898b73ab6c2d130630..0b0a0dd7997495d6ff683c0da91a77f123634e91 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_sjis/utf8_and_sjis.c,v 1.11.2.1 2006/05/21 20:05:50 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_sjis/utf8_and_sjis.c,v 1.11.2.2 2009/01/29 19:24:37 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -40,9 +40,7 @@ sjis_to_utf8(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_SJIS);
-       Assert(PG_GETARG_INT32(1) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_SJIS, PG_UTF8);
 
        LocalToUtf(src, dest, LUmapSJIS,
                           sizeof(LUmapSJIS) / sizeof(pg_local_to_utf), PG_SJIS, len);
@@ -57,9 +55,7 @@ utf8_to_sjis(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_UTF8);
-       Assert(PG_GETARG_INT32(1) == PG_SJIS);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_SJIS);
 
        UtfToLocal(src, dest, ULmapSJIS,
                           sizeof(ULmapSJIS) / sizeof(pg_utf_to_local), PG_SJIS, len);
index b632e880e6995a0584edb3f247750bc15fc44f66..8954b0d0eb8688a7f9ad58f7b5a4613bf0fa90b1 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_uhc/utf8_and_uhc.c,v 1.11.2.1 2006/05/21 20:05:50 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_uhc/utf8_and_uhc.c,v 1.11.2.2 2009/01/29 19:24:37 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -40,9 +40,7 @@ uhc_to_utf8(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_UHC);
-       Assert(PG_GETARG_INT32(1) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UHC, PG_UTF8);
 
        LocalToUtf(src, dest, LUmapUHC,
                           sizeof(LUmapUHC) / sizeof(pg_local_to_utf), PG_UHC, len);
@@ -57,9 +55,7 @@ utf8_to_uhc(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_UTF8);
-       Assert(PG_GETARG_INT32(1) == PG_UHC);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_UHC);
 
        UtfToLocal(src, dest, ULmapUHC,
                           sizeof(ULmapUHC) / sizeof(pg_utf_to_local), PG_UHC, len);
index 8d0af7773d3e3a7b034526a1fc30ffa04f9afc3c..33779f99cd2c3e5eb993e33527518824c4ef1b57 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win1250/utf8_and_win1250.c,v 1.13.2.1 2006/05/21 20:05:50 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win1250/utf8_and_win1250.c,v 1.13.2.2 2009/01/29 19:24:37 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -41,9 +41,7 @@ utf8_to_win1250(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_UTF8);
-       Assert(PG_GETARG_INT32(1) == PG_WIN1250);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_WIN1250);
 
        UtfToLocal(src, dest, ULmapWIN1250,
                           sizeof(ULmapWIN1250) / sizeof(pg_utf_to_local), PG_WIN1250, len);
@@ -58,9 +56,7 @@ win1250_to_utf8(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_WIN1250);
-       Assert(PG_GETARG_INT32(1) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1250, PG_UTF8);
 
        LocalToUtf(src, dest, LUmapWIN1250,
                        sizeof(LUmapWIN1250) / sizeof(pg_local_to_utf), PG_WIN1250, len);
index c53aa69c58787f901a916d801b2e06b39b4c996a..53c82b1800da267773a89ae41c17e2cc88e8d25e 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win1252/utf8_and_win1252.c,v 1.5.2.1 2006/05/21 20:05:50 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win1252/utf8_and_win1252.c,v 1.5.2.2 2009/01/29 19:24:37 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -41,9 +41,7 @@ utf8_to_win1252(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_UTF8);
-       Assert(PG_GETARG_INT32(1) == PG_WIN1252);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_WIN1252);
 
        UtfToLocal(src, dest, ULmapWIN1252,
                           sizeof(ULmapWIN1252) / sizeof(pg_utf_to_local), PG_WIN1252, len);
@@ -58,9 +56,7 @@ win1252_to_utf8(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_WIN1252);
-       Assert(PG_GETARG_INT32(1) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1252, PG_UTF8);
 
        LocalToUtf(src, dest, LUmapWIN1252,
                        sizeof(LUmapWIN1252) / sizeof(pg_local_to_utf), PG_WIN1252, len);
index df9d083b10a45da496071643d4e0fa6757077c5e..0e6ead6cb5608f2957a89c06fb121fb2bdfe6c41 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win1256/utf8_and_win1256.c,v 1.13.2.1 2006/05/21 20:05:50 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win1256/utf8_and_win1256.c,v 1.13.2.2 2009/01/29 19:24:37 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -41,9 +41,7 @@ utf8_to_win1256(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_UTF8);
-       Assert(PG_GETARG_INT32(1) == PG_WIN1256);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_WIN1256);
 
        UtfToLocal(src, dest, ULmapWIN1256,
                           sizeof(ULmapWIN1256) / sizeof(pg_utf_to_local), PG_WIN1256, len);
@@ -58,9 +56,7 @@ win1256_to_utf8(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_WIN1256);
-       Assert(PG_GETARG_INT32(1) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1256, PG_UTF8);
 
        LocalToUtf(src, dest, LUmapWIN1256,
                        sizeof(LUmapWIN1256) / sizeof(pg_local_to_utf), PG_WIN1256, len);
index e731a812f10bef72d6cf9724274be96635baa1a2..eb59947d471fab22a94d0110fbbfedbbe6667661 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win1258/utf8_and_win1258.c,v 1.3.2.1 2006/05/21 20:05:50 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win1258/utf8_and_win1258.c,v 1.3.2.2 2009/01/29 19:24:37 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -40,9 +40,7 @@ win1258_to_utf8(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_WIN1258);
-       Assert(PG_GETARG_INT32(1) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1258, PG_UTF8);
 
        LocalToUtf(src, dest, LUmapWIN1258,
                        sizeof(LUmapWIN1258) / sizeof(pg_local_to_utf), PG_WIN1258, len);
@@ -57,9 +55,7 @@ utf8_to_win1258(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_UTF8);
-       Assert(PG_GETARG_INT32(1) == PG_WIN1258);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_WIN1258);
 
        UtfToLocal(src, dest, ULmapWIN1258,
                           sizeof(ULmapWIN1258) / sizeof(pg_utf_to_local), PG_WIN1258, len);
index 685c357d8bcdd8ddcfe5dd9b69a5abab59985308..49af9725d451f98271f74525071f66a8800237fc 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win874/utf8_and_win874.c,v 1.13.2.1 2006/05/21 20:05:50 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win874/utf8_and_win874.c,v 1.13.2.2 2009/01/29 19:24:37 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -41,9 +41,7 @@ utf8_to_win874(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_UTF8);
-       Assert(PG_GETARG_INT32(1) == PG_WIN874);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_WIN874);
 
        UtfToLocal(src, dest, ULmapWIN874,
                           sizeof(ULmapWIN874) / sizeof(pg_utf_to_local), PG_WIN874, len);
@@ -58,9 +56,7 @@ win874_to_utf8(PG_FUNCTION_ARGS)
        unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
        int                     len = PG_GETARG_INT32(4);
 
-       Assert(PG_GETARG_INT32(0) == PG_WIN874);
-       Assert(PG_GETARG_INT32(1) == PG_UTF8);
-       Assert(len >= 0);
+       CHECK_ENCODING_CONVERSION_ARGS(PG_WIN874, PG_UTF8);
 
        LocalToUtf(src, dest, LUmapWIN874,
                           sizeof(LUmapWIN874) / sizeof(pg_local_to_utf), PG_WIN874, len);
index 5e841629d82f4aa40a4290b24944574513c3f987..f2206902f41be5c5d1764cedf8c611fc540453b3 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * conversion functions between pg_wchar and multibyte streams.
  * Tatsuo Ishii
- * $PostgreSQL: pgsql/src/backend/utils/mb/wchar.c,v 1.47.2.7 2008/10/27 19:37:42 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/mb/wchar.c,v 1.47.2.8 2009/01/29 19:24:37 tgl Exp $
  *
  * WIN1250 client encoding updated by Pavel Behal
  *
@@ -1326,6 +1326,39 @@ pg_verify_mbstr(int encoding, const char *mbstr, int len, bool noError)
        return true;
 }
 
+/*
+ * check_encoding_conversion_args: check arguments of a conversion function
+ *
+ * "expected" arguments can be either an encoding ID or -1 to indicate that
+ * the caller will check whether it accepts the ID.
+ *
+ * Note: the errors here are not really user-facing, so elog instead of
+ * ereport seems sufficient.  Also, we trust that the "expected" encoding
+ * arguments are valid encoding IDs, but we don't trust the actuals.
+ */
+void
+check_encoding_conversion_args(int src_encoding,
+                                                          int dest_encoding,
+                                                          int len,
+                                                          int expected_src_encoding,
+                                                          int expected_dest_encoding)
+{
+       if (!PG_VALID_ENCODING(src_encoding))
+               elog(ERROR, "invalid source encoding ID: %d", src_encoding);
+       if (src_encoding != expected_src_encoding && expected_src_encoding >= 0)
+               elog(ERROR, "expected source encoding \"%s\", but got \"%s\"",
+                        pg_enc2name_tbl[expected_src_encoding].name,
+                        pg_enc2name_tbl[src_encoding].name);
+       if (!PG_VALID_ENCODING(dest_encoding))
+               elog(ERROR, "invalid destination encoding ID: %d", dest_encoding);
+       if (dest_encoding != expected_dest_encoding && expected_dest_encoding >= 0)
+               elog(ERROR, "expected destination encoding \"%s\", but got \"%s\"",
+                        pg_enc2name_tbl[expected_dest_encoding].name,
+                        pg_enc2name_tbl[dest_encoding].name);
+       if (len < 0)
+               elog(ERROR, "encoding conversion length must not be negative");
+}
+
 /*
  * report_invalid_encoding: complain about invalid multibyte character
  *
index 55c3a40d421d0bf7880acce4ffe0d91b0f9630ec..13a38286e1fee55299bf7c3f28fe1a69f81ac35d 100644 (file)
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/include/mb/pg_wchar.h,v 1.63.2.1 2006/05/21 20:05:50 tgl Exp $ */
+/* $PostgreSQL: pgsql/src/include/mb/pg_wchar.h,v 1.63.2.2 2009/01/29 19:24:37 tgl Exp $ */
 
 #ifndef PG_WCHAR_H
 #define PG_WCHAR_H
@@ -286,6 +286,19 @@ typedef struct
        unsigned int utf;                       /* UTF8 */
 } pg_local_to_utf;
 
+/*
+ * Support macro for encoding conversion functions to validate their
+ * arguments.  (This could be made more compact if we included fmgr.h
+ * here, but we don't want to do that because this header file is also
+ * used by frontends.)
+ */
+#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding,destencoding) \
+       check_encoding_conversion_args(PG_GETARG_INT32(0), \
+                                                                  PG_GETARG_INT32(1), \
+                                                                  PG_GETARG_INT32(4), \
+                                                                  (srcencoding), \
+                                                                  (destencoding))
+
 extern int     pg_mb2wchar(const char *from, pg_wchar *to);
 extern int     pg_mb2wchar_with_len(const char *from, pg_wchar *to, int len);
 extern int     pg_char_and_wchar_strcmp(const char *s1, const pg_wchar *s2);
@@ -340,6 +353,12 @@ extern bool pg_verifymbstr(const char *mbstr, int len, bool noError);
 extern bool pg_verify_mbstr(int encoding, const char *mbstr, int len,
                                                        bool noError);
 
+extern void check_encoding_conversion_args(int src_encoding,
+                                                                                  int dest_encoding,
+                                                                                  int len,
+                                                                                  int expected_src_encoding,
+                                                                                  int expected_dest_encoding);
+
 extern void report_invalid_encoding(int encoding, const char *mbstr, int len);
 extern void report_untranslatable_char(int src_encoding, int dest_encoding,
                                                                           const char *mbstr, int len);