pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Marcin Ligorowski <ligo@interia.pl>
To: Adam M <gnuman1@gmail.com>
Cc: pgsql-odbc@postgresql.org
Subject: Re: resolution for bug 1010313
Date: Tue, 19 Aug 2008 20:35:36 +0200
Message-ID: <48AB1278.2000703@interia.pl> (raw)
In-Reply-To: <84b37b360808081403k749196c1u314d2f1a00cd4e61@mail.gmail.com>
References: <20080729073626.37DFD6D57E@f09.poczta.interia.pl>
	<84b37b360808081403k749196c1u314d2f1a00cd4e61@mail.gmail.com>

Bellow are changes in patch format obtained by using diff utility.

Marcin

inline patch 1: win_unicode.c Fri Jul 25 12:52:06 2008 (+25/-5 lines) download inline-1.patch--- win_unicode.c.org Sat Sep 1 01:40:10 2007 +++ win_unicode.c Fri Jul 25 12:52:06 2008 @@ -54,6 +54,13 @@ +int is_big_endian() +{ + union { long l; char c[sizeof (long)]; } u; + u.l = 1; + return (u.c[sizeof (long) - 1] == 1); +} + SQLULEN ucs2strlen(const SQLWCHAR *ucs2str) { SQLULEN len; @@ -66,6 +73,17 @@ char * utf8str; + static int is_endian_calc = 0; + static int big_endian = 0; + if(!is_endian_calc) + { + big_endian = is_big_endian(); + is_endian_calc = 1; + } + if (!ucs2str) { *olen = SQL_NULL_DATA; @@ -78,8 +96,8 @@ if (utf8str) { int i, len = 0; - UInt2 byte2code; - Int4 byte4code, surrd1, surrd2; + union { UInt2 i; char c[sizeof (UInt2)]; } byte2code; + union { Int4 i; char c[sizeof (Int4)]; } byte4code, surrd1, surrd2; const SQLWCHAR *wstr; for (i = 0, wstr = ucs2str; i < ilen; i++, wstr++) @@ -95,35 +113,62 @@ } else if ((*wstr & byte3check) == 0) { - byte2code = byte2_base | + byte2code.i = byte2_base | ((byte2_mask1 & *wstr) >> 6) | ((byte2_mask2 & *wstr) << 8); - memcpy(utf8str + len, (char *) &byte2code, sizeof(byte2code)); - len += sizeof(byte2code); + if(big_endian) + { + memcpy(utf8str + len, (char *) &byte2code.c[1], 1); + memcpy(utf8str + len + 1, (char *) &byte2code.c[0], 1); } + else + { + memcpy(utf8str + len, (char *) &byte2code.i,
sizeof(byte2code.i)); + } + len += sizeof(byte2code.i); + } else if (surrog1_bits == (*wstr & surrog_check)) { - surrd1 = (*wstr & ~surrog_check) + surrogate_adjust; + surrd1.i = (*wstr & ~surrog_check) + surrogate_adjust; wstr++; i++; - surrd2 = (*wstr & ~surrog_check); - byte4code = byte4_base | - ((byte4_sr1_mask1 & surrd1) >> 8) | - ((byte4_sr1_mask2 & surrd1) << 6) | - ((byte4_sr1_mask3 & surrd1) << 20) | - ((byte4_sr2_mask1 & surrd2) << 10) | - ((byte4_sr2_mask2 & surrd2) << 24); - memcpy(utf8str + len, (char *) &byte4code, sizeof(byte4code)); - len += sizeof(byte4code); + surrd2.i = (*wstr & ~surrog_check); + byte4code.i = byte4_base | + ((byte4_sr1_mask1 & surrd1.i) >> 8) | + ((byte4_sr1_mask2 & surrd1.i) << 6) | + ((byte4_sr1_mask3 & surrd1.i) << 20) | + ((byte4_sr2_mask1 & surrd2.i) << 10) | + ((byte4_sr2_mask2 & surrd2.i) << 24); + if(big_endian) + { + memcpy(utf8str + len, (char *) &byte2code.c[3], 1); + memcpy(utf8str + len + 1, (char *) &byte2code.c[2], 1); + memcpy(utf8str + len + 2, (char *) &byte2code.c[1], 1); + memcpy(utf8str + len + 3, (char *) &byte2code.c[0], 1); } else { - byte4code = byte3_base | + memcpy(utf8str + len, (char *) &byte4code.i, sizeof(byte4code.i)); + } + len += sizeof(byte4code.i); + } + else + { + byte4code.i = byte3_base | ((byte3_mask1 & *wstr) >> 12) | ((byte3_mask2 & *wstr) << 2) | ((byte3_mask3 & *wstr) << 16); - memcpy(utf8str + len, (char *) &byte4code, 3); + if(big_endian) + { + memcpy(utf8str + len, (char *) &byte2code.c[3], 1); + memcpy(utf8str + len + 1, (char *) &byte2code.c[2], 1); + memcpy(utf8str + len + 2, (char *) &byte2code.c[1], 1); + } + else + { + memcpy(utf8str + len, (char *) &byte4code.i, 3); + } len += 3; } } Adam M pisze: > On Tue, Jul 29, 2008 at 2:36 AM, Marcin Ligorowski <ligo@interia.pl> wrote: > >> Below is source code that I've implemented >> (I've send all ucs2_to_utf8 function source code) >> > > Is it possible to attach your changes as a patch? In-line posting of > some code changes (and in non-patch format) really is not an ideal way > to post changes. > > Thanks, > Adam > ---------------------------------------------------------------------- Igrzyska z nagrodami! Kliknij>>>> http://link.interia.pl/f1edb

view thread (3+ messages)

Message-ID: <48AB1278.2000703@interia.pl>
Permalink:  ../48AB1278.2000703@interia.pl/
Also on:    postgresql.org/message-id/48AB1278.2000703@interia.pl

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-odbc@postgresql.org
  Cc: ligo@interia.pl, gnuman1@gmail.com
  Subject: Re: resolution for bug 1010313
  In-Reply-To: <48AB1278.2000703@interia.pl>
  References: <20080729073626.37DFD6D57E@f09.poczta.interia.pl> <84b37b360808081403k749196c1u314d2f1a00cd4e61@mail.gmail.com> <48AB1278.2000703@interia.pl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox