Re: [BUGS] BUG #6480: NLS text width problem

2012-03-12 Thread Sergey Burladyan
Tom Lane  writes:

> Ah, nevermind --- I re-read the patch and realized that it was already
> doing exactly what I said.  Committed, sorry for the noise.

Great, thank you, Tom!

-- 
Sergey Burladyan

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


Re: [BUGS] BUG #6480: NLS text width problem

2012-03-07 Thread Tom Lane
Sergey Burladyan  writes:
> Tom Lane  writes:
>> I think it'd be better to avoid depending on %*s for the data string
>> and instead use it (with appropriate adjustment of the calculation)
>> for the space-separator part of the format.  Since that's a constant
>> empty string, there shouldn't be any possibility of libc doing something
>> other than what we intend.

> Sorry, I'm going on vacation for four days. Can't answer right now...

Ah, nevermind --- I re-read the patch and realized that it was already
doing exactly what I said.  Committed, sorry for the noise.

regards, tom lane

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


Re: [BUGS] BUG #6480: NLS text width problem

2012-03-07 Thread Sergey Burladyan
Tom Lane  writes:

> I think it'd be better to avoid depending on %*s for the data string
> and instead use it (with appropriate adjustment of the calculation)
> for the space-separator part of the format.  Since that's a constant
> empty string, there shouldn't be any possibility of libc doing something
> other than what we intend.

Sorry, I'm going on vacation for four days. Can't answer right now...

-- 
Sergey Burladyan

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


Re: [BUGS] BUG #6480: NLS text width problem

2012-03-06 Thread Tom Lane
Sergey Burladyan  writes:
> Peter Eisentraut  writes:
>> Can you prepare a patch?

> Surely, I was sent this patch to pgsql-hackers and added to the 
> commitfest-next to
> be sure I'll never lost it 
> https://commitfest.postgresql.org/action/patch_view?id=816

Hmm, this patch makes it obvious that the current incarnation of
pg_wcswidth has never worked.  Good thing it's been unused for the same
length of time :-(

> Unfortunately, I was sent it with content-disposition: inline by mistake, as
> result, web interface divided it by two independent parts. Also this patch 
> for 9.1

I'm a bit nervous about the idea of back-patching this, as if there is
anything wrong with it it will break code that works perfectly fine for
most people.  Possibly more to the point, it is making assumptions about
the behavior of printf with %*s that I think are unportable.  Even
granted that libc is glibc, isn't this pretty much guaranteed to fail
if glibc's idea of the encoding is different from pset.encoding?

I think it'd be better to avoid depending on %*s for the data string
and instead use it (with appropriate adjustment of the calculation)
for the space-separator part of the format.  Since that's a constant
empty string, there shouldn't be any possibility of libc doing something
other than what we intend.

regards, tom lane

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


Re: [BUGS] BUG #6480: NLS text width problem

2012-03-06 Thread Sergey Burladyan
Peter Eisentraut  writes:

> On ons, 2012-02-22 at 22:37 +0400, Sergey Burladyan wrote:
> > eshkin...@gmail.com writes:
> > 
> > > The following bug has been logged on the website:
> > >
> > > Bug reference:  6480
> > > Logged by:  Sergey Burladyan
> > > Email address:  eshkin...@gmail.com
> > > PostgreSQL version: 9.1.2
> > > Operating system:   Debian testing
> > > Description:
> > >
> > > This code incorrectly calculate width for translated text if it multibyte
> > > string. strlen(ct) vs. UTF-8
> > >
> > > src/bin/psql/describe.c:2100
>
> Can you prepare a patch?
>

Surely, I was sent this patch to pgsql-hackers and added to the commitfest-next 
to
be sure I'll never lost it 
https://commitfest.postgresql.org/action/patch_view?id=816

Unfortunately, I was sent it with content-disposition: inline by mistake, as
result, web interface divided it by two independent parts. Also this patch for 
9.1

To resolve this issue, I was rebased this patch to current master (bc97c38) and 
send
it as attachment. Here it is:

>From 489ce7f9e8ccea9d760504d3b100b67d11968516 Mon Sep 17 00:00:00 2001
From: Sergey Burladyan 
Date: Tue, 28 Feb 2012 04:41:15 +0400
Subject: [PATCH] Fix NLS text width and pg_wcswidth function

---
 src/bin/psql/describe.c |4 ++--
 src/bin/psql/mbprint.c  |7 ---
 src/bin/psql/mbprint.h  |2 +-
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 4eee4be..de89b09 100644
*** a/src/bin/psql/describe.c
--- b/src/bin/psql/describe.c
*** describeOneTableDetails(const char *sche
*** 2165,2171 
  			if (i == 0)
  printfPQExpBuffer(&buf, "%s: %s", s, PQgetvalue(result, i, 0));
  			else
! printfPQExpBuffer(&buf, "%*s  %s", (int) strlen(s), "", PQgetvalue(result, i, 0));
  			if (i < tuples - 1)
  appendPQExpBuffer(&buf, ",");
  
--- 2165,2171 
  			if (i == 0)
  printfPQExpBuffer(&buf, "%s: %s", s, PQgetvalue(result, i, 0));
  			else
! printfPQExpBuffer(&buf, "%*s  %s", pg_wcswidth(s, strlen(s), pset.encoding), "", PQgetvalue(result, i, 0));
  			if (i < tuples - 1)
  appendPQExpBuffer(&buf, ",");
  
*** describeOneTableDetails(const char *sche
*** 2206,2212 
  	  ct, PQgetvalue(result, i, 0));
  else
  	printfPQExpBuffer(&buf, "%*s  %s",
! 	  (int) strlen(ct), "",
  	  PQgetvalue(result, i, 0));
  if (i < tuples - 1)
  	appendPQExpBuffer(&buf, ",");
--- 2206,2212 
  	  ct, PQgetvalue(result, i, 0));
  else
  	printfPQExpBuffer(&buf, "%*s  %s",
! 	  pg_wcswidth(ct, strlen(ct), pset.encoding), "",
  	  PQgetvalue(result, i, 0));
  if (i < tuples - 1)
  	appendPQExpBuffer(&buf, ",");
diff --git a/src/bin/psql/mbprint.c b/src/bin/psql/mbprint.c
index 32fc756..f246d00 100644
*** a/src/bin/psql/mbprint.c
--- b/src/bin/psql/mbprint.c
*** mb_utf_validate(unsigned char *pwcs)
*** 172,178 
   * only appear on one line. OTOH it is easier to use if this applies to you.
   */
  int
! pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding)
  {
  	int			width = 0;
  
--- 172,178 
   * only appear on one line. OTOH it is easier to use if this applies to you.
   */
  int
! pg_wcswidth(const char *pwcs, size_t len, int encoding)
  {
  	int			width = 0;
  
*** pg_wcswidth(const unsigned char *pwcs, s
*** 181,195 
  		int			chlen,
  	chwidth;
  
! 		chlen = PQmblen((const char *) pwcs, encoding);
  		if (chlen > len)
  			break;/* Invalid string */
  
! 		chwidth = PQdsplen((const char *) pwcs, encoding);
  
  		if (chwidth > 0)
  			width += chwidth;
  		pwcs += chlen;
  	}
  	return width;
  }
--- 181,196 
  		int			chlen,
  	chwidth;
  
! 		chlen = PQmblen(pwcs, encoding);
  		if (chlen > len)
  			break;/* Invalid string */
  
! 		chwidth = PQdsplen(pwcs, encoding);
  
  		if (chwidth > 0)
  			width += chwidth;
  		pwcs += chlen;
+ 		len -= chlen;
  	}
  	return width;
  }
diff --git a/src/bin/psql/mbprint.h b/src/bin/psql/mbprint.h
index 83050ff..01064d3 100644
*** a/src/bin/psql/mbprint.h
--- b/src/bin/psql/mbprint.h
*** struct lineptr
*** 10,16 
  };
  
  extern unsigned char *mbvalidate(unsigned char *pwcs, int encoding);
! extern int	pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding);
  extern void pg_wcsformat(const unsigned char *pwcs, size_t len, int encoding, struct lineptr * lines, int count);
  extern void pg_wcssize(const unsigned char *pwcs, size_t len, int encoding,
  		   int *width, int *height, int *format_size);
--- 10,16 
  };
  
  extern unsigned char *mbvalidate(unsigned char *pwcs, int encoding);
! extern int	pg_wcswidth(const char *pwcs, size_t len, int encoding);
  extern void pg_wcsformat(const unsigned char *pwcs, size_t len, int encoding, struct lineptr * lines, int count);
  extern void pg_wcssize(const unsigned char *pwcs, size_t len, int encoding

Re: [BUGS] BUG #6480: NLS text width problem

2012-03-02 Thread Peter Eisentraut
On ons, 2012-02-22 at 22:37 +0400, Sergey Burladyan wrote:
> eshkin...@gmail.com writes:
> 
> > The following bug has been logged on the website:
> >
> > Bug reference:  6480
> > Logged by:  Sergey Burladyan
> > Email address:  eshkin...@gmail.com
> > PostgreSQL version: 9.1.2
> > Operating system:   Debian testing
> > Description:
> >
> > This code incorrectly calculate width for translated text if it multibyte
> > string. strlen(ct) vs. UTF-8
> >
> > src/bin/psql/describe.c:2100

Can you prepare a patch?



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


Re: [BUGS] BUG #6480: NLS text width problem

2012-02-22 Thread Sergey Burladyan
eshkin...@gmail.com writes:

> The following bug has been logged on the website:
>
> Bug reference:  6480
> Logged by:  Sergey Burladyan
> Email address:  eshkin...@gmail.com
> PostgreSQL version: 9.1.2
> Operating system:   Debian testing
> Description:
>
> This code incorrectly calculate width for translated text if it multibyte
> string. strlen(ct) vs. UTF-8
>
> src/bin/psql/describe.c:2100

Test case:

create table t ();
create table t_1 () inherits (t);
create table t_2 () inherits (t);
create table d () inherits (t_1, t_2);

\d+ t
\d+ d

 Table "public.t"
 Column | Type | Modifiers | Storage | Description 
+--+---+-+-
Child tables: t_1,
  t_2
Has OIDs: no

 Table "public.d"
 Column | Type | Modifiers | Storage | Description 
+--+---+-+-
Inherits: t_1,
  t_2
Has OIDs: no

English, correct indentation:
. . .
Child tables: t_1,
  t_2
. . .
Inherits: t_1,
  t_2

Russian (UTF-8), wrong indentation:

 Таблица "public.t"
 Колонка | Тип | Модификаторы | Хранилище | Описание 
-+-+--+---+--
Дочерние таблицы: t_1,
 t_2
Содержит OID: нет


 Таблица "public.d"
 Колонка | Тип | Модификаторы | Хранилище | Описание 
-+-+--+---+--
Наследует: t_1,
t_2
Содержит OID: нет

-- 
Sergey Burladyan

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


[BUGS] BUG #6480: NLS text width problem

2012-02-21 Thread eshkinkot
The following bug has been logged on the website:

Bug reference:  6480
Logged by:  Sergey Burladyan
Email address:  eshkin...@gmail.com
PostgreSQL version: 9.1.2
Operating system:   Debian testing
Description:

This code incorrectly calculate width for translated text if it multibyte
string. strlen(ct) vs. UTF-8

src/bin/psql/describe.c:2100
else
{
/* display the list of child tables */
const char *ct = _("Child tables");

for (i = 0; i < tuples; i++)
{
if (i == 0)
printfPQExpBuffer(&buf, "%s: %s",
  ct, 
PQgetvalue(result, i, 0));
else
printfPQExpBuffer(&buf, "%*s  %s",
  (int) 
strlen(ct), "",
  
PQgetvalue(result, i, 0));
if (i < tuples - 1)
appendPQExpBuffer(&buf, ",");

printTableAddFooter(&cont, buf.data);
}
}
PQclear(result);



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs