Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 6665464FCED for ; Tue, 29 Jul 2008 04:36:42 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 41801-08 for ; Tue, 29 Jul 2008 04:36:33 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp239.poczta.interia.pl (smtp239.poczta.interia.pl [217.74.64.239]) by postgresql.org (Postfix) with ESMTP id 9C2DD64FCEA for ; Tue, 29 Jul 2008 04:36:29 -0300 (ADT) Received: by smtp239.poczta.interia.pl (INTERIA.PL, from userid 502) id 12BB6D2AA0; Tue, 29 Jul 2008 09:36:27 +0200 (CEST) Received: from f09.poczta.interia.pl (f09.poczta.interia.pl [10.217.2.9]) by smtp239.poczta.interia.pl (INTERIA.PL) with ESMTP id 9F469D2A86 for ; Tue, 29 Jul 2008 09:36:26 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by f09.poczta.interia.pl (Postfix) with ESMTP id 37DFD6D57E for ; Tue, 29 Jul 2008 09:36:26 +0200 (CEST) Date: 29 Jul 2008 09:36:26 +0200 From: Marcin Ligorowski Subject: resolution for bug 1010313 To: pgsql-odbc@postgresql.org MIME-Version: 1.0 Content-Type: TEXT/plain; CHARSET=ISO-8859-2 Content-Transfer-Encoding: QUOTED-PRINTABLE X-ORIGINATE-IP: 139.181.124.2 IMPORTANCE: Normal X-MSMAIL-PRIORITY: Normal X-PRIORITY: 3 X-Mailer: PSE3 Message-Id: <20080729073626.37DFD6D57E@f09.poczta.interia.pl> X-EMID: b1240acc X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=MISSING_MIMEOLE=0.001 X-Spam-Level: X-Archive-Number: 200807/4 X-Sequence-Number: 9559 =0AI've resolved bug number 1010313 (it was neccessary for me because I use= psqlodbc driver =0Aon Sun Solaris Sparc with UTF-8 characters).=0A=0ATop r= esolve this bug I've added is_big_endian() that determines whether platform= supports=0Abig endian or little endian bytes order.=0AThis method is also = used becuase it is not possible to use any standard define,=0Athat is "stan= dard define" and works for different compiler and operating systems.=0A=0AA= dditionaly, becuase I don't want to calculate every time in ucs2_to_utf8 fu= nction=0Aplatform endianness I've used two static variables, first big_endi= an stores endianness status=0Aand second is_endian_calc determines whether = endianness was calculated.=0A=0AAnd finally, in ucs2_to_utf8 I've added swa= pping bytes for big_endian platform.=0A=0ABelow is source code that I've im= plemented=0A(I've send all ucs2_to_utf8 function source code)=0A=0Aint is_b= ig_endian()=0A{=0A=09union { long l; char c[sizeof (long)]; } u;=0A u.l = =3D 1; =0A return (u.c[sizeof (long) - 1] =3D=3D 1);=0A}=0A=0Achar *ucs2= _to_utf8(const SQLWCHAR *ucs2str, SQLLEN ilen, SQLLEN *olen, BOOL lower_ide= ntifier)=0A{=0A=09char *=09utf8str;=0A/*mylog("ucs2_to_utf8 %p ilen=3D%d ",= ucs2str, ilen);*/=0A=0A=09/*=0A=09* is this a bigendian machine ?=0A=09*/= =0A=09static int is_endian_calc =3D 0;=0A=09static int big_endian =3D 0;=0A= =09if(!is_endian_calc)=0A=09{=0A=09=09big_endian =3D is_big_endian();=0A=09= =09is_endian_calc =3D 1;=0A=09}=0A=0A=09if (!ucs2str)=0A=09{=0A=09=09*olen = =3D SQL_NULL_DATA;=0A=09=09return NULL;=0A=09}=0A=09if (SQL_NTS =3D=3D ilen= )=0A=09=09ilen =3D ucs2strlen(ucs2str);=0A/*mylog(" newlen=3D%d", ilen);*/= =0A=09utf8str =3D (char *) malloc(ilen * 4 + 1);=0A=09if (utf8str)=0A=09{= =0A=09=09int=09i, len =3D 0;=0A=09=09union { UInt2 i; char c[sizeof (UInt2)= ]; } byte2code;=0A=09=09union { Int4 i; char c[sizeof (Int4)]; } byte4code= , surrd1, surrd2;=0A=09=09const SQLWCHAR=09*wstr;=0A=0A=09=09for (i =3D 0, = wstr =3D ucs2str; i < ilen; i++, wstr++)=0A=09=09{=0A=09=09=09if (!*wstr)= =0A=09=09=09=09break;=0A=09=09=09else if (0 =3D=3D (*wstr & 0xffffff80)) /*= ASCII */=0A=09=09=09{=0A=09=09=09=09if (lower_identifier)=0A=09=09=09=09= =09utf8str[len++] =3D (char) tolower(*wstr);=0A=09=09=09=09else=0A=09=09=09= =09=09utf8str[len++] =3D (char) *wstr;=0A=09=09=09}=0A=09=09=09else if ((*w= str & byte3check) =3D=3D 0)=0A=09=09=09{=0A=09=09=09=09byte2code.i =3D byte= 2_base |=0A=09=09=09=09=09 ((byte2_mask1 & *wstr) >> 6) |=0A=09=09=09=09= =09 ((byte2_mask2 & *wstr) << 8);=0A=09=09=09=09if(big_endian)=0A=09=09= =09=09{=0A=09=09=09=09=09memcpy(utf8str + len, (char *) &byte2code.c[1], 1)= ;=0A=09=09=09=09=09memcpy(utf8str + len + 1, (char *) &byte2code.c[0], 1);= =0A=09=09=09=09}=0A=09=09=09=09else=0A=09=09=09=09{=0A=09=09=09=09=09memcpy= (utf8str + len, (char *) &byte2code.i, sizeof(byte2code.i));=0A=09=09=09=09= }=0A=09=09=09=09len +=3D sizeof(byte2code.i); =0A=09=09=09}=0A=09=09=09/* s= urrogate pair check for non ucs-2 code */ =0A=09=09=09else if (surrog1_bits= =3D=3D (*wstr & surrog_check))=0A=09=09=09{=0A=09=09=09=09surrd1.i =3D (*w= str & ~surrog_check) + surrogate_adjust;=0A=09=09=09=09wstr++;=0A=09=09=09= =09i++;=0A=09=09=09=09surrd2.i =3D (*wstr & ~surrog_check);=0A=09=09=09=09b= yte4code.i =3D byte4_base |=0A=09=09=09=09=09 ((byte4_sr1_mask1 & surrd1.= i) >> 8) |=0A=09=09=09=09=09 ((byte4_sr1_mask2 & surrd1.i) << 6) |=0A=09= =09=09=09=09 ((byte4_sr1_mask3 & surrd1.i) << 20) |=0A=09=09=09=09=09 (= (byte4_sr2_mask1 & surrd2.i) << 10) |=0A=09=09=09=09=09 ((byte4_sr2_mask2= & surrd2.i) << 24);=0A=09=09=09=09if(big_endian)=0A=09=09=09=09{=0A=09=09= =09=09=09memcpy(utf8str + len, (char *) &byte2code.c[3], 1);=0A=09=09=09=09= =09memcpy(utf8str + len + 1, (char *) &byte2code.c[2], 1);=0A=09=09=09=09= =09memcpy(utf8str + len + 2, (char *) &byte2code.c[1], 1);=0A=09=09=09=09= =09memcpy(utf8str + len + 3, (char *) &byte2code.c[0], 1);=0A=09=09=09=09}= =0A=09=09=09=09else=0A=09=09=09=09{=0A=09=09=09=09=09memcpy(utf8str + len, = (char *) &byte4code.i, sizeof(byte4code.i));=0A=09=09=09=09}=0A=09=09=09=09= len +=3D sizeof(byte4code.i);=0A=09=09=09}=0A=09=09=09else=0A=09=09=09{=0A= =09=09=09=09byte4code.i =3D byte3_base |=0A=09=09=09=09=09 ((byte3_mask1= & *wstr) >> 12) | =0A=09=09=09=09=09 ((byte3_mask2 & *wstr) << 2) | =0A= =09=09=09=09=09 ((byte3_mask3 & *wstr) << 16);=0A=09=09=09=09if(big_endi= an)=0A=09=09=09=09{=0A=09=09=09=09=09memcpy(utf8str + len, (char *) &byte2c= ode.c[3], 1);=0A=09=09=09=09=09memcpy(utf8str + len + 1, (char *) &byte2cod= e.c[2], 1);=0A=09=09=09=09=09memcpy(utf8str + len + 2, (char *) &byte2code.= c[1], 1);=0A=09=09=09=09}=0A=09=09=09=09else=0A=09=09=09=09{=0A=09=09=09=09= =09memcpy(utf8str + len, (char *) &byte4code.i, 3);=0A=09=09=09=09}=0A=09= =09=09=09len +=3D 3;=0A=09=09=09}=0A=09=09} =0A=09=09utf8str[len] =3D '\0';= =0A=09=09if (olen)=0A=09=09=09*olen =3D len;=0A=09}=0A/*mylog(" olen=3D%d %= s\n", *olen, utf8str ? utf8str : "");*/=0A=09return utf8str;=0A} ---------------------------------------------------------------------- W kosciele tez zdarzaja sie wpadki! Smieszny filmik >>> http://link.interia.pl/f1e61