Ticket #33145: postgresql91.diff

File postgresql91.diff, 20.0 KB (added by mail_ben_schmidt@…, 12 years ago)
  • Portfile

    diff -Naur /opt/local/var/macports/sources/rsync.macports.org/release/tarballs/ports/databases/postgresql91/Portfile ./Portfile
    old new  
    55
    66name                    postgresql91
    77version                 9.1.2
    8 revision        1
     8revision                6
    99categories              databases
    1010platforms               darwin
    1111maintainers             mww jwa
     
    3737patchfiles              src_pl_plpython_Makefile.patch
    3838
    3939set libdir              ${prefix}/lib/${name}
     40
     41if {[variant_isset icu]} {
     42    pre-configure {
     43        system "${prefix}/bin/autoreconf263 ${worksrcpath}"
     44    }
     45}
     46
    4047configure.args  --sysconfdir=${prefix}/etc/${name} \
    4148                                --bindir=${libdir}/bin \
    4249                                --libdir=${libdir} \
     
    128135        configure.env-append            TCLSH=${prefix}/bin/tclsh
    129136}
    130137
     138variant icu description {use ICU for locale-aware text functionality} {
     139        depends_lib-append              port:icu
     140        depends_build-append            port:autoconf263
     141        patchfiles-append               pg912_icu_2012-02-15.patch
     142        configure.args-append           --with-icu
     143}
     144
     145default_variants +icu
     146
    131147post-install {
    132148    ui_msg "\nTo use the postgresql server, install the ${name}-server port"
    133149}
  • files/pg912_icu_2012-02-15.patch

    diff -Naur /opt/local/var/macports/sources/rsync.macports.org/release/tarballs/ports/databases/postgresql91/files/pg912_icu_2012-02-15.patch ./files/pg912_icu_2012-02-15.patch
    old new  
     1diff -Naur postgresql-9.1.2-orig/configure.in postgresql-9.1.2/configure.in
     2--- configure.in        2012-02-03 11:47:01.000000000 +1100
     3+++ configure.in        2012-02-03 11:49:06.000000000 +1100
     4@@ -692,6 +692,16 @@
     5 AC_MSG_RESULT([$with_selinux])
     6 
     7 #
     8+# ICU
     9+#
     10+AC_MSG_CHECKING([whether to build with ICU support])
     11+PGAC_ARG_BOOL(with, icu, no, [  --with-icu              build with ICU support],
     12+              [AC_DEFINE([USE_ICU], 1, [Define to build with ICU support. (--with-icu)])])
     13+AC_MSG_RESULT([$with_icu])
     14+AC_SUBST(with_icu)
     15+
     16+
     17+#
     18 # Readline
     19 #
     20 PGAC_ARG_BOOL(with, readline, yes,
     21@@ -950,6 +960,31 @@
     22   fi
     23 fi
     24 
     25+if test "$with_icu" = yes ; then
     26+  AC_CHECK_LIB(icui18n, ucol_open_48, [], [
     27+    AC_CHECK_LIB(icui18n, ucol_open_44, [], [
     28+       AC_CHECK_LIB(icui18n, ucol_open_43, [], [
     29+          AC_CHECK_LIB(icui18n, ucol_open_3_8, [], [
     30+             AC_CHECK_LIB(icui18n, ucol_open_3_6, [], [
     31+                AC_CHECK_LIB(icui18n, ucol_open_3_4, [], [AC_MSG_ERROR([library 'icui18n' is required for ICU])])
     32+             ])
     33+          ])
     34+       ])
     35+    ])
     36+  ])
     37+  AC_CHECK_LIB(icuuc, ucnv_fromUChars_48, [], [
     38+    AC_CHECK_LIB(icuuc, ucnv_fromUChars_44, [], [
     39+       AC_CHECK_LIB(icuuc, ucnv_fromUChars_43, [], [
     40+          AC_CHECK_LIB(icuuc, ucnv_fromUChars_3_8, [], [
     41+             AC_CHECK_LIB(icuuc, ucnv_fromUChars_3_6, [], [
     42+                AC_CHECK_LIB(icuuc, ucnv_fromUChars_3_4, [], [AC_MSG_ERROR([library 'icuuc' is required for ICU])])
     43+             ])
     44+          ])
     45+       ])
     46+    ])
     47+  ])
     48+fi
     49+
     50 if test "$with_pam" = yes ; then
     51   AC_CHECK_LIB(pam,    pam_start, [], [AC_MSG_ERROR([library 'pam' is required for PAM])])
     52 fi
     53@@ -1062,6 +1097,10 @@
     54   AC_CHECK_FUNCS([ERR_set_mark])
     55 fi
     56 
     57+if test "$with_icu" = yes ; then
     58+  AC_CHECK_HEADER(unicode/utypes.h, [], [AC_MSG_ERROR([header file <unicode/utypes.h> is required for ICU])])
     59+fi
     60+
     61 if test "$with_pam" = yes ; then
     62   AC_CHECK_HEADERS(security/pam_appl.h, [],
     63                    [AC_CHECK_HEADERS(pam/pam_appl.h, [],
     64diff -Naur postgresql-9.1.2-orig/src/backend/utils/adt/formatting.c postgresql-9.1.2/src/backend/utils/adt/formatting.c
     65--- src/backend/utils/adt/formatting.c  2012-02-03 11:47:02.000000000 +1100
     66+++ src/backend/utils/adt/formatting.c  2012-02-03 11:49:37.000000000 +1100
     67@@ -92,6 +92,12 @@
     68 #include "utils/numeric.h"
     69 #include "utils/pg_locale.h"
     70 
     71+#ifdef USE_ICU
     72+#include <unicode/utypes.h>   /* Basic ICU data types */
     73+#include <unicode/ucnv.h>     /* C   Converter API    */
     74+#include <unicode/ustring.h>
     75+#endif /* USE_ICU */
     76+
     77 /* ----------
     78  * Routines type
     79  * ----------
     80@@ -942,6 +948,12 @@
     81 } NUMProc;
     82 
     83 
     84+#ifdef USE_ICU
     85+static UConverter *conv = NULL;
     86+#define STACKBUFLEN            1024 / sizeof(UChar)
     87+#endif   /* USE_ICU */
     88+
     89+
     90 /* ----------
     91  * Functions
     92  * ----------
     93@@ -1498,6 +1510,82 @@
     94                for (p = result; *p; p++)
     95                        *p = pg_ascii_tolower((unsigned char) *p);
     96        }
     97+#ifdef USE_ICU
     98+       /* use ICU only when max encoding length > one */
     99+       else if (pg_database_encoding_max_length() > 1)
     100+       {
     101+               UChar       sourcebuf[STACKBUFLEN], destbuf[STACKBUFLEN];
     102+               UChar      *source, *dest;
     103+               int                     buflen;
     104+               size_t          result_size, usize;
     105+               UErrorCode  status = U_ZERO_ERROR;
     106+
     107+               if (conv == NULL)
     108+               {
     109+                       conv = ucnv_open(NULL, &status);
     110+                       if (U_FAILURE(status))
     111+                       {
     112+                               ereport(ERROR,
     113+                                               (errcode(status),
     114+                                                errmsg("ICU error: oracle_compat.c, could not get converter for \"%s\"", ucnv_getDefaultName())));
     115+                       }
     116+               }
     117+
     118+               if (nbytes >= STACKBUFLEN / sizeof(UChar))
     119+               {
     120+                       buflen = (nbytes + 1) * sizeof(UChar);
     121+                       source = palloc(buflen);
     122+                       dest = palloc(buflen);
     123+               }
     124+               else
     125+               {
     126+                       buflen = STACKBUFLEN;
     127+                       source = sourcebuf;
     128+                       dest = destbuf;
     129+               }
     130+               // convert to UTF-16
     131+               ucnv_toUChars(conv, source, buflen, buff, nbytes, &status);
     132+               if (U_FAILURE(status))
     133+               {
     134+                       ereport(ERROR,
     135+                                               (errcode(status),
     136+                                                errmsg("ICU error: Could not convert string")));
     137+               }
     138+               
     139+               // run desired function
     140+               buflen = u_strToLower(dest, buflen, source, -1, NULL, &status);
     141+               if (U_FAILURE(status))
     142+               {
     143+                       ereport(ERROR,
     144+                                               (errcode(status),
     145+                                                errmsg("ICU error: Could not modify case")));
     146+               }
     147+
     148+               // and convert modified utf-16 string back to text
     149+               result_size = UCNV_GET_MAX_BYTES_FOR_STRING(buflen, ucnv_getMaxCharSize(conv));
     150+               result = palloc(result_size);
     151+
     152+               usize = ucnv_fromUChars(conv, result, result_size,
     153+                                                                dest, buflen, &status);
     154+
     155+               if (U_FAILURE(status))
     156+               {
     157+                       /* Invalid multibyte character encountered ... shouldn't happen */
     158+                       ereport(ERROR,
     159+                                       (errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
     160+                                        errmsg("ICU: invalid multibyte character for locale")));
     161+               }
     162+
     163+               Assert(usize <= (size_t) (buflen * sizeof(UChar)));
     164+
     165+               if (nbytes >= STACKBUFLEN / sizeof(UChar))
     166+               {
     167+                       pfree(source);
     168+                       pfree(dest);
     169+               }
     170+               return result;
     171+       }
     172+#else
     173 #ifdef USE_WIDE_UPPER_LOWER
     174        else if (pg_database_encoding_max_length() > 1)
     175        {
     176@@ -1551,6 +1639,7 @@
     177                pfree(workspace);
     178        }
     179 #endif   /* USE_WIDE_UPPER_LOWER */
     180+#endif   /* USE_ICU */
     181        else
     182        {
     183                pg_locale_t mylocale = 0;
     184@@ -1619,6 +1708,82 @@
     185                for (p = result; *p; p++)
     186                        *p = pg_ascii_toupper((unsigned char) *p);
     187        }
     188+#ifdef USE_ICU
     189+       /* use ICU only when max encoding length > one */
     190+       else if (pg_database_encoding_max_length() > 1)
     191+       {
     192+               UChar       sourcebuf[STACKBUFLEN], destbuf[STACKBUFLEN];
     193+               UChar      *source, *dest;
     194+               int                     buflen;
     195+               size_t          result_size, usize;
     196+               UErrorCode  status = U_ZERO_ERROR;
     197+
     198+               if (conv == NULL)
     199+               {
     200+                       conv = ucnv_open(NULL, &status);
     201+                       if (U_FAILURE(status))
     202+                       {
     203+                               ereport(ERROR,
     204+                                               (errcode(status),
     205+                                                errmsg("ICU error: oracle_compat.c, could not get converter for \"%s\"", ucnv_getDefaultName())));
     206+                       }
     207+               }
     208+
     209+               if (nbytes >= STACKBUFLEN / sizeof(UChar))
     210+               {
     211+                       buflen = (nbytes + 1) * sizeof(UChar);
     212+                       source = palloc(buflen);
     213+                       dest = palloc(buflen);
     214+               }
     215+               else
     216+               {
     217+                       buflen = STACKBUFLEN;
     218+                       source = sourcebuf;
     219+                       dest = destbuf;
     220+               }
     221+               // convert to UTF-16
     222+               ucnv_toUChars(conv, source, buflen, buff, nbytes, &status);
     223+               if (U_FAILURE(status))
     224+               {
     225+                       ereport(ERROR,
     226+                                               (errcode(status),
     227+                                                errmsg("ICU error: Could not convert string")));
     228+               }
     229+               
     230+               // run desired function
     231+               buflen = u_strToUpper(dest, buflen, source, -1, NULL, &status);
     232+               if (U_FAILURE(status))
     233+               {
     234+                       ereport(ERROR,
     235+                                               (errcode(status),
     236+                                                errmsg("ICU error: Could not modify case")));
     237+               }
     238+
     239+               // and convert modified utf-16 string back to text
     240+               result_size = UCNV_GET_MAX_BYTES_FOR_STRING(buflen, ucnv_getMaxCharSize(conv));
     241+               result = palloc(result_size);
     242+
     243+               usize = ucnv_fromUChars(conv, result, result_size,
     244+                                                                dest, buflen, &status);
     245+
     246+               if (U_FAILURE(status))
     247+               {
     248+                       /* Invalid multibyte character encountered ... shouldn't happen */
     249+                       ereport(ERROR,
     250+                                       (errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
     251+                                        errmsg("ICU: invalid multibyte character for locale")));
     252+               }
     253+
     254+               Assert(usize <= (size_t) (buflen * sizeof(UChar)));
     255+
     256+               if (nbytes >= STACKBUFLEN / sizeof(UChar))
     257+               {
     258+                       pfree(source);
     259+                       pfree(dest);
     260+               }
     261+               return result;
     262+       }
     263+#else
     264 #ifdef USE_WIDE_UPPER_LOWER
     265        else if (pg_database_encoding_max_length() > 1)
     266        {
     267@@ -1672,6 +1837,7 @@
     268                pfree(workspace);
     269        }
     270 #endif   /* USE_WIDE_UPPER_LOWER */
     271+#endif /* USE_ICU */
     272        else
     273        {
     274                pg_locale_t mylocale = 0;
     275@@ -1752,6 +1918,82 @@
     276                                                (c >= '0' && c <= '9'));
     277                }
     278        }
     279+#ifdef USE_ICU
     280+       /* use ICU only when max encoding length > one */
     281+       else if (pg_database_encoding_max_length() > 1)
     282+       {
     283+               UChar       sourcebuf[STACKBUFLEN], destbuf[STACKBUFLEN];
     284+               UChar      *source, *dest;
     285+               int                     buflen;
     286+               size_t          result_size, usize;
     287+               UErrorCode  status = U_ZERO_ERROR;
     288+
     289+               if (conv == NULL)
     290+               {
     291+                       conv = ucnv_open(NULL, &status);
     292+                       if (U_FAILURE(status))
     293+                       {
     294+                               ereport(ERROR,
     295+                                               (errcode(status),
     296+                                                errmsg("ICU error: oracle_compat.c, could not get converter for \"%s\"", ucnv_getDefaultName())));
     297+                       }
     298+               }
     299+
     300+               if (nbytes >= STACKBUFLEN / sizeof(UChar))
     301+               {
     302+                       buflen = (nbytes + 1) * sizeof(UChar);
     303+                       source = palloc(buflen);
     304+                       dest = palloc(buflen);
     305+               }
     306+               else
     307+               {
     308+                       buflen = STACKBUFLEN;
     309+                       source = sourcebuf;
     310+                       dest = destbuf;
     311+               }
     312+               // convert to UTF-16
     313+               ucnv_toUChars(conv, source, buflen, buff, nbytes, &status);
     314+               if (U_FAILURE(status))
     315+               {
     316+                       ereport(ERROR,
     317+                                               (errcode(status),
     318+                                                errmsg("ICU error: Could not convert string")));
     319+               }
     320+               
     321+               // run desired function
     322+               buflen = u_strToTitle(dest, buflen, source, -1, NULL, NULL, &status);
     323+               if (U_FAILURE(status))
     324+               {
     325+                       ereport(ERROR,
     326+                                               (errcode(status),
     327+                                                errmsg("ICU error: Could not modify case")));
     328+               }
     329+
     330+               // and convert modified utf-16 string back to text
     331+               result_size = UCNV_GET_MAX_BYTES_FOR_STRING(buflen, ucnv_getMaxCharSize(conv));
     332+               result = palloc(result_size);
     333+
     334+               usize = ucnv_fromUChars(conv, result, result_size,
     335+                                                                dest, buflen, &status);
     336+
     337+               if (U_FAILURE(status))
     338+               {
     339+                       /* Invalid multibyte character encountered ... shouldn't happen */
     340+                       ereport(ERROR,
     341+                                       (errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
     342+                                        errmsg("ICU: invalid multibyte character for locale")));
     343+               }
     344+
     345+               Assert(usize <= (size_t) (buflen * sizeof(UChar)));
     346+
     347+               if (nbytes >= STACKBUFLEN / sizeof(UChar))
     348+               {
     349+                       pfree(source);
     350+                       pfree(dest);
     351+               }
     352+               return result;
     353+       }
     354+#else
     355 #ifdef USE_WIDE_UPPER_LOWER
     356        else if (pg_database_encoding_max_length() > 1)
     357        {
     358@@ -1817,6 +2059,7 @@
     359                pfree(workspace);
     360        }
     361 #endif   /* USE_WIDE_UPPER_LOWER */
     362+#endif /* USE_ICU */
     363        else
     364        {
     365                pg_locale_t mylocale = 0;
     366diff -Naur postgresql-9.1.2-orig/src/backend/utils/adt/varlena.c postgresql-9.1.2/src/backend/utils/adt/varlena.c
     367--- src/backend/utils/adt/varlena.c     2012-02-03 11:47:02.000000000 +1100
     368+++ src/backend/utils/adt/varlena.c     2012-02-03 11:49:06.000000000 +1100
     369@@ -30,6 +30,15 @@
     370 #include "utils/lsyscache.h"
     371 #include "utils/pg_locale.h"
     372 
     373+#ifdef USE_ICU
     374+#include <unicode/utypes.h>   /* Basic ICU data types */
     375+#include <unicode/ucnv.h>     /* C   Converter API    */
     376+#include <unicode/ucol.h>
     377+#include <unicode/uloc.h>
     378+#include "unicode/uiter.h"
     379+#define USTACKBUFLEN           STACKBUFLEN / sizeof(UChar)
     380+#endif /* USE_ICU */
     381+
     382 
     383 /* GUC variable */
     384 int                    bytea_output = BYTEA_OUTPUT_HEX;
     385@@ -1295,6 +1304,134 @@
     386        {
     387 #define STACKBUFLEN            1024
     388 
     389+#ifdef USE_ICU
     390+
     391+               if (pg_database_encoding_max_length() > 1)
     392+               {
     393+                       static UCollator * collator = NULL;
     394+                       UErrorCode  status = U_ZERO_ERROR;
     395+
     396+                       /* We keep a static collator "forever", since it is hard
     397+                        * coded into the database cluster at initdb time
     398+                        * anyway. Create it first time we get here. */
     399+                       if (collator == NULL)
     400+                       {
     401+                               /* Expect LC_COLLATE to be set to something that ICU
     402+                                * will understand. This is quite probable, since ICU
     403+                                * does a lot of heuristics with this argument. I'd
     404+                                * rather set this in xlog.c, but it seems ICU forgets
     405+                                * it??? */
     406+                               uloc_setDefault(setlocale(LC_COLLATE, NULL), &status);
     407+                               if(U_FAILURE(status))
     408+                               {
     409+                                       ereport(WARNING,
     410+                                                       (errcode(status),
     411+                                                        errmsg("ICU Error: varlena.c, could not set default lc_collate")));
     412+                               }
     413+                               collator = ucol_open(NULL, &status);
     414+                               if (U_FAILURE(status))
     415+                               {
     416+                                       ereport(WARNING,
     417+                                                       (errcode(status),
     418+                                                        errmsg("ICU Error: varlena.c, could not open collator")));
     419+                               }
     420+                       }
     421+                       
     422+                       if (GetDatabaseEncoding() == PG_UTF8)
     423+                       {
     424+                               UCharIterator sIter, tIter;
     425+                               uiter_setUTF8(&sIter, arg1, len1);
     426+                               uiter_setUTF8(&tIter, arg2, len2);
     427+                               result = ucol_strcollIter(collator, &sIter, &tIter, &status);
     428+                               if (U_FAILURE(status))
     429+                               {
     430+                                       ereport(WARNING,
     431+                                                       (errcode(status),
     432+                                                        errmsg("ICU Error: varlena.c, could not collate")));
     433+                               }
     434+                       }
     435+                       else {
     436+                               /* We keep a static converter "forever".
     437+                                * Create it first time we get here. */
     438+                               static UConverter * conv = NULL;
     439+                               if (conv == NULL)
     440+                               {
     441+                                       conv = ucnv_open(NULL, &status);
     442+                                       if (U_FAILURE(status) || conv == NULL)
     443+                                       {
     444+                                               ereport(ERROR,
     445+                                                               (errcode(status),
     446+                                                                errmsg("ICU error: varlena.c, could not get converter for \"%s\"", ucnv_getDefaultName())));
     447+                                       }
     448+                               }
     449+
     450+                               UChar   a1buf[USTACKBUFLEN],
     451+                                               a2buf[USTACKBUFLEN];
     452+                               int             a1len = USTACKBUFLEN,
     453+                                               a2len = USTACKBUFLEN;   
     454+                               UChar   *a1p,
     455+                                               *a2p;
     456+                               if (len1 >= USTACKBUFLEN / sizeof(UChar))
     457+                               {
     458+                                       a1len = (len1 + 1) * sizeof(UChar);
     459+                                       a1p = (UChar *) palloc(a1len); 
     460+                               }
     461+                               else
     462+                                       a1p = a1buf;
     463+
     464+                               if (len2 >= USTACKBUFLEN / sizeof(UChar))
     465+                               {
     466+                                       a2len = (len2 + 1) * sizeof(UChar);
     467+                                       a2p = (UChar *) palloc(a2len);
     468+                               }
     469+                               else
     470+                                       a2p = a2buf;
     471+
     472+                               ucnv_toUChars(conv, a1p, a1len, arg1, len1, &status);
     473+                               if(U_FAILURE(status))
     474+                               {
     475+                                       ereport(WARNING,
     476+                                                       (errcode(status),
     477+                                                        errmsg("ICU Error: varlena.c, could not convert to UChars")));
     478+                               }
     479+                               ucnv_toUChars(conv, a2p, a2len, arg2, len2, &status);
     480+                               if(U_FAILURE(status))
     481+                               {
     482+                                       ereport(WARNING,
     483+                                                       (errcode(status),
     484+                                                        errmsg("ICU Error: varlena.c, could not convert to UChars")));
     485+                               }
     486+
     487+                               result = ucol_strcoll(collator, a1p, -1, a2p, -1);
     488+                               if(U_FAILURE(status))
     489+                               {
     490+                                       ereport(WARNING,
     491+                                                       (errcode(status),
     492+                                                        errmsg("ICU Error: varlena.c, could not collate")));
     493+                               }
     494+                               if (len1 * sizeof(UChar) >= USTACKBUFLEN)
     495+                                       pfree(a1p);
     496+                               if (len2 * sizeof(UChar) >= USTACKBUFLEN)
     497+                                       pfree(a2p);
     498+                       }
     499+                       /*
     500+                        * In some locales wcscoll() can claim that nonidentical strings
     501+                        * are equal.  Believing that this might be so also for ICU, and
     502+                        * believing that would be bad news for a number of
     503+                        * reasons, we follow Perl's lead and sort "equal" strings
     504+                        * according to strcmp (on the byte representation).
     505+                        */
     506+                       if (result == 0)
     507+                       {
     508+                               result = strncmp(arg1, arg2, Min(len1, len2));
     509+                               if ((result == 0) && (len1 != len2))
     510+                                       result = (len1 < len2) ? -1 : 1;
     511+                       }
     512+
     513+                       return result;
     514+               }
     515+#endif /* USE_ICU */
     516+
     517                char            a1buf[STACKBUFLEN];
     518                char            a2buf[STACKBUFLEN];
     519                char       *a1p,
     520diff -Naur postgresql-9.1.2-orig/src/backend/utils/mb/encnames.c postgresql-9.1.2/src/backend/utils/mb/encnames.c
     521--- src/backend/utils/mb/encnames.c     2012-02-03 11:47:02.000000000 +1100
     522+++ src/backend/utils/mb/encnames.c     2012-02-03 11:49:06.000000000 +1100
     523@@ -394,6 +394,118 @@
     524 };
     525 
     526 
     527+#ifdef USE_ICU
     528+/*
     529+ * Try to map most internal character encodings to the proper and
     530+ * preferred IANA string. Use this in mbutils.c to feed ICU info about
     531+ * the database's character encoding.
     532+ *
     533+ * Palle Girgensohn, 2005
     534+ */
     535+
     536+pg_enc2name pg_enc2iananame_tbl[] =
     537+{
     538+       {
     539+               "US-ASCII", PG_SQL_ASCII
     540+       },
     541+       {
     542+               "EUC-JP", PG_EUC_JP
     543+       },
     544+       {
     545+               "GB2312", PG_EUC_CN
     546+       },
     547+       {
     548+               "EUC-KR", PG_EUC_KR
     549+       },
     550+       {
     551+               "ISO-2022-CN", PG_EUC_TW
     552+       },
     553+       {
     554+               "KS_C_5601-1987", PG_JOHAB  /* either KS_C_5601-1987 or ISO-2022-KR ??? */
     555+       },
     556+       {
     557+               "UTF-8", PG_UTF8
     558+       },
     559+       {
     560+               "MULE_INTERNAL", PG_MULE_INTERNAL  /* is not for real */
     561+       },
     562+       {
     563+               "ISO-8859-1", PG_LATIN1
     564+       },
     565+       {
     566+               "ISO-8859-2", PG_LATIN2
     567+       },
     568+       {
     569+               "ISO-8859-3", PG_LATIN3
     570+       },
     571+       {
     572+               "ISO-8859-4", PG_LATIN4
     573+       },
     574+       {
     575+               "ISO-8859-9", PG_LATIN5
     576+       },
     577+       {
     578+               "ISO-8859-10", PG_LATIN6
     579+       },
     580+       {
     581+               "ISO-8859-13", PG_LATIN7
     582+       },
     583+       {
     584+               "ISO-8859-14", PG_LATIN8
     585+       },
     586+       {
     587+               "ISO-8859-15", PG_LATIN9
     588+       },
     589+       {
     590+               "ISO-8859-16", PG_LATIN10
     591+       },
     592+       {
     593+               "windows-1256", PG_WIN1256
     594+       },
     595+       {
     596+               "windows-874", PG_WIN874
     597+       },
     598+       {
     599+               "KOI8-R", PG_KOI8R
     600+       },
     601+       {
     602+               "windows-1251", PG_WIN1251
     603+       },
     604+       {
     605+               "ISO-8859-5", PG_ISO_8859_5
     606+       },
     607+       {
     608+               "ISO-8859-6", PG_ISO_8859_6
     609+       },
     610+       {
     611+               "ISO-8859-7", PG_ISO_8859_7
     612+       },
     613+       {
     614+               "ISO-8859-8", PG_ISO_8859_8
     615+       },
     616+       {
     617+               "windows-1250", PG_WIN1250
     618+       },
     619+       {
     620+               "Shift_JIS", PG_SJIS
     621+       },
     622+       {
     623+               "Big5", PG_BIG5
     624+       },
     625+       {
     626+               "GBK", PG_GBK
     627+       },
     628+       {
     629+               "cp949", PG_UHC
     630+       },
     631+       {
     632+               "GB18030", PG_GB18030
     633+       }
     634+};
     635+#endif /* USE_ICU */
     636+
     637+
     638+
     639 /* ----------
     640  * Encoding checks, for error returns -1 else encoding id
     641  * ----------
     642diff -Naur postgresql-9.1.2-orig/src/backend/utils/mb/mbutils.c postgresql-9.1.2/src/backend/utils/mb/mbutils.c
     643--- src/backend/utils/mb/mbutils.c      2012-02-03 11:47:02.000000000 +1100
     644+++ src/backend/utils/mb/mbutils.c      2012-02-03 11:49:06.000000000 +1100
     645@@ -14,6 +14,9 @@
     646 #include "utils/builtins.h"
     647 #include "utils/memutils.h"
     648 #include "utils/syscache.h"
     649+#ifdef USE_ICU
     650+#include <unicode/ucnv.h>
     651+#endif /* USE_ICU */
     652 
     653 /*
     654  * When converting strings between different encodings, we assume that space
     655@@ -857,6 +860,9 @@
     656 
     657        DatabaseEncoding = &pg_enc2name_tbl[encoding];
     658        Assert(DatabaseEncoding->encoding == encoding);
     659+#ifdef USE_ICU
     660+       ucnv_setDefaultName((&pg_enc2iananame_tbl[encoding])->name);
     661+#endif
     662 }
     663 
     664 /*
     665diff -Naur postgresql-9.1.2-orig/src/include/mb/pg_wchar.h postgresql-9.1.2/src/include/mb/pg_wchar.h
     666--- src/include/mb/pg_wchar.h   2012-02-03 11:47:02.000000000 +1100
     667+++ src/include/mb/pg_wchar.h   2012-02-03 11:49:06.000000000 +1100
     668@@ -261,6 +261,9 @@
     669 } pg_enc2name;
     670 
     671 extern pg_enc2name pg_enc2name_tbl[];
     672+#ifdef USE_ICU
     673+extern pg_enc2name pg_enc2iananame_tbl[];
     674+#endif
     675 
     676 /*
     677  * Encoding names for gettext
     678diff -Naur postgresql-9.1.2-orig/src/include/pg_config.h.in postgresql-9.1.2/src/include/pg_config.h.in
     679--- src/include/pg_config.h.in  2012-02-03 11:47:02.000000000 +1100
     680+++ src/include/pg_config.h.in  2012-02-03 11:49:06.000000000 +1100
     681@@ -290,6 +290,12 @@
     682 /* Define to 1 if you have the `eay32' library (-leay32). */
     683 #undef HAVE_LIBEAY32
     684 
     685+/* Define to 1 if you have the `icui18n' library (-licui18n). */
     686+#undef HAVE_LIBICUI18N
     687+
     688+/* Define to 1 if you have the `icuuc' library (-licuuc). */
     689+#undef HAVE_LIBICUUC
     690+
     691 /* Define to 1 if you have the `ldap' library (-lldap). */
     692 #undef HAVE_LIBLDAP
     693 
     694@@ -759,6 +765,9 @@
     695 /* Define to 1 to build with Bonjour support. (--with-bonjour) */
     696 #undef USE_BONJOUR
     697 
     698+/* Define to build with ICU support. (--with-icu) */
     699+#undef USE_ICU
     700+
     701 /* Define to 1 if you want float4 values to be passed by value.
     702    (--enable-float4-byval) */
     703 #undef USE_FLOAT4_BYVAL