Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests

2005-05-05 Thread Bruce Momjian
Andrew Dunstan wrote:
 
 After some further digging, I think we have 3 problems.
 
 1. On Windows gettext wants to hijack printf and friends, as below. This
 strikes me as rather unfriendly behaviour by a library header file.
 Anyway, mercifully libintl.h is included in our source in exactly one
 spot, so I think the thing to do for this problem is a) undo that
 hijacking and b) make sure any hijacking we want to do occurs after the
 point where that file in included (in c.h). This causes most of the
 noise, but is probably harmless, since our hijacking does in fact win
 out. We need to fix the arnings, though.
 
 2. We have multiple #defines for snprintf and vsnprintf (in port.h and
 win32.h).
 
 3. ecpg wants to use our pg*printf routines (because USE_SNPRINTF is
 defined) but doesn't know where to find them.
 
 what a mess :-(

Based on the mess analysis, I decided it is better to allow libintl to
use its own snprintf() for Win32 when NLS is enabled, rather than try to
override that with our own snprintf.  I have added code to configure.in
so that we don't check for arg control in native snprintf on Win32
because when we are using NLS, we are going to get their snprintf anyway
and not the native one.

Patch attached and applied.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073
Index: configure
===
RCS file: /cvsroot/pgsql/configure,v
retrieving revision 1.435
diff -c -c -r1.435 configure
*** configure   5 May 2005 11:50:17 -   1.435
--- configure   5 May 2005 19:13:35 -
***
*** 14706,14712 
  
  # Force use of our snprintf if system's doesn't do arg control
  # This feature is used by NLS
! if test $enable_nls = yes  test $pgac_need_repl_snprintf = no; then
echo $as_me:$LINENO: checking whether printf supports argument control 5
  echo $ECHO_N checking whether printf supports argument control... $ECHO_C 
6
  if test ${pgac_cv_printf_arg_control+set} = set; then
--- 14706,14718 
  
  # Force use of our snprintf if system's doesn't do arg control
  # This feature is used by NLS
! if test $enable_nls = yes 
!test $pgac_need_repl_snprintf = no 
! # On Win32, libintl replaces snprintf() with its own version that
! # understands arg control, so we don't need our own.  In fact, it
! # also uses macros that conflict with ours, so we _can't_ use
! # our own.
!test $PORTNAME != win32; then
echo $as_me:$LINENO: checking whether printf supports argument control 5
  echo $ECHO_N checking whether printf supports argument control... $ECHO_C 
6
  if test ${pgac_cv_printf_arg_control+set} = set; then
Index: configure.in
===
RCS file: /cvsroot/pgsql/configure.in,v
retrieving revision 1.408
diff -c -c -r1.408 configure.in
*** configure.in5 May 2005 11:50:18 -   1.408
--- configure.in5 May 2005 19:13:36 -
***
*** 1095,1101 
  
  # Force use of our snprintf if system's doesn't do arg control
  # This feature is used by NLS
! if test $enable_nls = yes  test $pgac_need_repl_snprintf = no; then
PGAC_FUNC_PRINTF_ARG_CONTROL
if test $pgac_cv_printf_arg_control != yes ; then
  pgac_need_repl_snprintf=yes
--- 1095,1107 
  
  # Force use of our snprintf if system's doesn't do arg control
  # This feature is used by NLS
! if test $enable_nls = yes 
!test $pgac_need_repl_snprintf = no 
! # On Win32, libintl replaces snprintf() with its own version that 
! # understands arg control, so we don't need our own.  In fact, it 
! # also uses macros that conflict with ours, so we _can't_ use
! # our own.
!test $PORTNAME != win32; then
PGAC_FUNC_PRINTF_ARG_CONTROL
if test $pgac_cv_printf_arg_control != yes ; then
  pgac_need_repl_snprintf=yes

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests

2005-03-20 Thread Andrew Dunstan

After some further digging, I think we have 3 problems.

1. On Windows gettext wants to hijack printf and friends, as below. This
strikes me as rather unfriendly behaviour by a library header file.
Anyway, mercifully libintl.h is included in our source in exactly one
spot, so I think the thing to do for this problem is a) undo that
hijacking and b) make sure any hijacking we want to do occurs after the
point where that file in included (in c.h). This causes most of the
noise, but is probably harmless, since our hijacking does in fact win
out. We need to fix the arnings, though.

2. We have multiple #defines for snprintf and vsnprintf (in port.h and
win32.h).

3. ecpg wants to use our pg*printf routines (because USE_SNPRINTF is
defined) but doesn't know where to find them.

what a mess :-(

cheers

andrew


Bruce Momjian wrote:

Thanks to Andrew Dunstan, I found the cause of these link errors. 
Andrew found this in libintl:
   
   #undef snprintf
   #define snprintf libintl_snprintf
   extern int snprintf (char *, size_t, const char *, ...);

What is happening is that we do:

   #define snprintfpg_snprintf

and then libintl.h (?) does:

   #define snprintf libintl_snprintf

so the effect is:

   #define pg_snprintf libintl_snprintf

In fact, in this example, the system complains about a missing X3 symbol:

   #define X1 X2
   #define X2 X3
   
   int
   main(int argc, char *argv[])
   {
   X1;
   }

so the effet of the defines is:

   #define X1 X3

Anyway, the reason ecpg is failing is that it is the only client-side
program that doesn't use libintl for internationalization.  It is on our
TODO list to do that, but it hasn't been done yet.

However, only Win32 is seeing this failure, and only when configure
--enable-nls.  I think this is because only Win32 does the redefine of
snprint and friends.

Comments?
   
---

Nicolai Tufar wrote:
  

On Wed, 16 Mar 2005 01:00:21 -0500 (EST), Bruce Momjian
pgman@candle.pha.pa.us wrote:


I have applied a modified version of your patch, attached.
  

I am so sorry, I sent untested patch again.  Thank you very
much for patience in fixing it. The patch looks perfectly
fine and works under Solaris. 

Under win32 I am still struggling with build environment.
In many directories link fails with undefined reference to
`pg_snprintf' in other it fails with  undefined reference to
`_imp__libintl_sprintf'. In yet another directory it fails with
both, like in src/interfaces/ecpg/pgtypeslib:

dlltool --export-all  --output-def pgtypes.def numeric.o datetime.o
common.o dt_common.o timestamp.o interval.o pgstrcasecmp.o
dllwrap  -o libpgtypes.dll --dllname libpgtypes.dll  --def pgtypes.def
numeric.o datetime.o common.o dt_common.o timestamp.o interval.o
pgstrcasecmp.o  -L../../../../src/port -lm
numeric.o(.text+0x19ea):numeric.c: undefined reference to
`_imp__libintl_sprintf'
datetime.o(.text+0x476):datetime.c: undefined reference to `pg_snprintf'
common.o(.text+0x1cd):common.c: undefined reference to `pg_snprintf'
common.o(.text+0x251):common.c: undefined reference to `pg_snprintf'
dt_common.o(.text+0x538):dt_common.c: undefined reference to
`_imp__libintl_sprintf'
dt_common.o(.text+0x553):dt_common.c: undefined reference to
`_imp__libintl_sprintf'
dt_common.o(.text+0x597):dt_common.c: undefined reference to
`_imp__libintl_sprintf'
dt_common.o(.text+0x5d5):dt_common.c: undefined reference to
`_imp__libintl_sprintf'
dt_common.o(.text+0x628):dt_common.c: undefined reference to
`_imp__libintl_sprintf'
dt_common.o(.text+0x7e8):dt_common.c: more undefined references to
`_imp__libintl_sprintf' follow
c:\MinGW\bin\dllwrap.exe: c:\MinGW\bin\gcc exited with status 1
make: *** [libpgtypes.a] Error 1

Could someone with a better grasp of configure and 
win32 environment check it? Aparently no one regularily 
compiles source code under win32 during development cycle
these days.


Best regards,
Nicolai

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster




  



---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests

2005-03-19 Thread Bruce Momjian

Thanks to Andrew Dunstan, I found the cause of these link errors. 
Andrew found this in libintl:

#undef snprintf
#define snprintf libintl_snprintf
extern int snprintf (char *, size_t, const char *, ...);

What is happening is that we do:

#define snprintfpg_snprintf

and then libintl.h (?) does:

#define snprintf libintl_snprintf

so the effect is:

#define pg_snprintf libintl_snprintf

In fact, in this example, the system complains about a missing X3 symbol:

#define X1 X2
#define X2 X3

int
main(int argc, char *argv[])
{
X1;
}

so the effet of the defines is:

#define X1 X3

Anyway, the reason ecpg is failing is that it is the only client-side
program that doesn't use libintl for internationalization.  It is on our
TODO list to do that, but it hasn't been done yet.

However, only Win32 is seeing this failure, and only when configure
--enable-nls.  I think this is because only Win32 does the redefine of
snprint and friends.

Comments?

---

Nicolai Tufar wrote:
 On Wed, 16 Mar 2005 01:00:21 -0500 (EST), Bruce Momjian
 pgman@candle.pha.pa.us wrote:
  
  I have applied a modified version of your patch, attached.
 
 I am so sorry, I sent untested patch again.  Thank you very
 much for patience in fixing it. The patch looks perfectly
 fine and works under Solaris. 
 
 Under win32 I am still struggling with build environment.
 In many directories link fails with undefined reference to
 `pg_snprintf' in other it fails with  undefined reference to
 `_imp__libintl_sprintf'. In yet another directory it fails with
 both, like in src/interfaces/ecpg/pgtypeslib:
 
 dlltool --export-all  --output-def pgtypes.def numeric.o datetime.o
 common.o dt_common.o timestamp.o interval.o pgstrcasecmp.o
 dllwrap  -o libpgtypes.dll --dllname libpgtypes.dll  --def pgtypes.def
 numeric.o datetime.o common.o dt_common.o timestamp.o interval.o
 pgstrcasecmp.o  -L../../../../src/port -lm
 numeric.o(.text+0x19ea):numeric.c: undefined reference to
 `_imp__libintl_sprintf'
 datetime.o(.text+0x476):datetime.c: undefined reference to `pg_snprintf'
 common.o(.text+0x1cd):common.c: undefined reference to `pg_snprintf'
 common.o(.text+0x251):common.c: undefined reference to `pg_snprintf'
 dt_common.o(.text+0x538):dt_common.c: undefined reference to
 `_imp__libintl_sprintf'
 dt_common.o(.text+0x553):dt_common.c: undefined reference to
 `_imp__libintl_sprintf'
 dt_common.o(.text+0x597):dt_common.c: undefined reference to
 `_imp__libintl_sprintf'
 dt_common.o(.text+0x5d5):dt_common.c: undefined reference to
 `_imp__libintl_sprintf'
 dt_common.o(.text+0x628):dt_common.c: undefined reference to
 `_imp__libintl_sprintf'
 dt_common.o(.text+0x7e8):dt_common.c: more undefined references to
 `_imp__libintl_sprintf' follow
 c:\MinGW\bin\dllwrap.exe: c:\MinGW\bin\gcc exited with status 1
 make: *** [libpgtypes.a] Error 1
 
 Could someone with a better grasp of configure and 
 win32 environment check it? Aparently no one regularily 
 compiles source code under win32 during development cycle
 these days.
 
 
 Best regards,
 Nicolai
 
 ---(end of broadcast)---
 TIP 4: Don't 'kill -9' the postmaster
 

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 8: explain analyze is your friend


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests

2005-03-19 Thread Greg Stark
Bruce Momjian pgman@candle.pha.pa.us writes:

 so the effect is:
 
   #define pg_snprintf libintl_snprintf

That's not how CPP works.

 In fact, in this example, the system complains about a missing X3 symbol:
 
   #define X1 X2
   #define X2 X3

In this case any occurrence of X1 replaced by X2 but then the result is
rescanned for macros and X2 is turned into X3.

-- 
greg


---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests to fail

2005-03-16 Thread Nicolai Tufar
On Wed, 16 Mar 2005 01:00:21 -0500 (EST), Bruce Momjian
pgman@candle.pha.pa.us wrote:
 
 I have applied a modified version of your patch, attached.

I am so sorry, I sent untested patch again.  Thank you very
much for patience in fixing it. The patch looks perfectly
fine and works under Solaris. 

Under win32 I am still struggling with build environment.
In many directories link fails with undefined reference to
`pg_snprintf' in other it fails with  undefined reference to
`_imp__libintl_sprintf'. In yet another directory it fails with
both, like in src/interfaces/ecpg/pgtypeslib:

dlltool --export-all  --output-def pgtypes.def numeric.o datetime.o
common.o dt_common.o timestamp.o interval.o pgstrcasecmp.o
dllwrap  -o libpgtypes.dll --dllname libpgtypes.dll  --def pgtypes.def
numeric.o datetime.o common.o dt_common.o timestamp.o interval.o
pgstrcasecmp.o  -L../../../../src/port -lm
numeric.o(.text+0x19ea):numeric.c: undefined reference to
`_imp__libintl_sprintf'
datetime.o(.text+0x476):datetime.c: undefined reference to `pg_snprintf'
common.o(.text+0x1cd):common.c: undefined reference to `pg_snprintf'
common.o(.text+0x251):common.c: undefined reference to `pg_snprintf'
dt_common.o(.text+0x538):dt_common.c: undefined reference to
`_imp__libintl_sprintf'
dt_common.o(.text+0x553):dt_common.c: undefined reference to
`_imp__libintl_sprintf'
dt_common.o(.text+0x597):dt_common.c: undefined reference to
`_imp__libintl_sprintf'
dt_common.o(.text+0x5d5):dt_common.c: undefined reference to
`_imp__libintl_sprintf'
dt_common.o(.text+0x628):dt_common.c: undefined reference to
`_imp__libintl_sprintf'
dt_common.o(.text+0x7e8):dt_common.c: more undefined references to
`_imp__libintl_sprintf' follow
c:\MinGW\bin\dllwrap.exe: c:\MinGW\bin\gcc exited with status 1
make: *** [libpgtypes.a] Error 1

Could someone with a better grasp of configure and 
win32 environment check it? Aparently no one regularily 
compiles source code under win32 during development cycle
these days.


Best regards,
Nicolai

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests

2005-03-16 Thread Bruce Momjian
Nicolai Tufar wrote:
 On Wed, 16 Mar 2005 01:00:21 -0500 (EST), Bruce Momjian
 pgman@candle.pha.pa.us wrote:
  
  I have applied a modified version of your patch, attached.
 

Here is a patch that fixes the %*$ case.

FYI, I am going to pgindent snprintf.c to make it consistent so please
us CVS for your next patch.

I will work on your Win32 compile problem next.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073
Index: src/port/snprintf.c
===
RCS file: /cvsroot/pgsql/src/port/snprintf.c,v
retrieving revision 1.20
diff -c -c -r1.20 snprintf.c
*** src/port/snprintf.c 16 Mar 2005 06:00:58 -  1.20
--- src/port/snprintf.c 16 Mar 2005 14:59:00 -
***
*** 467,481 
fmtparptr[i]-charvalue = va_arg(args, int);
break;
case FMTLEN:
!   if (i + 1  fmtpos  fmtpar[i + 1].func != FMTWIDTH)
!   fmtpar[i + 1].len = va_arg(args, int);
/* For %*.*f, use the second arg */
!   if (i + 2  fmtpos  fmtpar[i + 1].func == FMTWIDTH)
!   fmtpar[i + 2].len = va_arg(args, int);
break;
case FMTWIDTH:
if (i + 1  fmtpos)
!   fmtpar[i + 1].maxwidth = fmtpar[i + 
1].precision =

va_arg(args, int);
break;
}
--- 467,481 
fmtparptr[i]-charvalue = va_arg(args, int);
break;
case FMTLEN:
!   if (i + 1  fmtpos  fmtparptr[i + 1]-func != 
FMTWIDTH)
!   fmtparptr[i + 1]-len = va_arg(args, int);
/* For %*.*f, use the second arg */
!   if (i + 2  fmtpos  fmtparptr[i + 1]-func == 
FMTWIDTH)
!   fmtparptr[i + 2]-len = va_arg(args, int);
break;
case FMTWIDTH:
if (i + 1  fmtpos)
!   fmtparptr[i + 1]-maxwidth = fmtparptr[i + 
1]-precision =

va_arg(args, int);
break;
}

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests

2005-03-15 Thread Bruce Momjian

I have applied a modified version of your patch, attached.

initdb will not work without %*s support, so I had to add that.  Please
look over my work.  I don't think i handle %*1$ but I am not even sure
what that means or if our translators would ever use such a thing.  You
can probably test that better than I can.

Your patch didn't handle signed vs. unsigned va_arg values properly..

There were also maxwidth tests around 's' that I had to remove to
support %*.  I think those tests are down in fmtstr too but please
check.

initdb and regression pass.

---

Nicolai Tufar wrote:
 Resubmission of yesterday's patch so that it would
 cont conflict with Bruce's cvs commit. Pleas apply.
 
 Best regards,
 Nicolai.
 
 
 On Sat, 12 Mar 2005 01:58:15 +0200, Nicolai Tufar [EMAIL PROTECTED] wrote:
  On Thu, 10 Mar 2005 19:21:41 -0500 (EST), Bruce Momjian
  pgman@candle.pha.pa.us wrote:
The CVS-tip implementation is fundamentally broken and won't work even
for our internal uses.  I've not wasted time complaining about it
because I thought we were going to replace it.  If we can't find a
usable replacement then we're going to have to put a lot of effort
into fixing what's there.  On the whole I think the effort would be
better spent importing someone else's solution.
  
   Oh, so our existing implementation doesn't even meet our needs. OK.
  
  Which made me wander why did I not aggree with
  Tom Lane's suggestion to make do three passes
  instead of two. Tom was right, as usual. It happened to
  be much easier than I expected. The patch is attached.
  Please apply.
  
  Tom, what do you think? Will it be fine with you?
  
  Best regards,
  Nicolai
  
  
 

[ Attachment, skipping... ]

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073
Index: src/port/snprintf.c
===
RCS file: /cvsroot/pgsql/src/port/snprintf.c,v
retrieving revision 1.19
diff -c -c -r1.19 snprintf.c
*** src/port/snprintf.c 12 Mar 2005 04:00:56 -  1.19
--- src/port/snprintf.c 16 Mar 2005 05:46:33 -
***
*** 151,170 
  
  #define   FMTSTR  1
  #define   FMTNUM  2
! #define   FMTFLOAT3
! #define   FMTCHAR 4
  
  static void
  dopr(char *buffer, const char *format, va_list args, char *end)
  {
int ch;
-   int64   value;
-   double  fvalue;
int longlongflag = 0;
int longflag = 0;
int pointflag = 0;
int maxwidth = 0;
-   char   *strvalue;
int ljust;
int len;
int zpad;
--- 151,170 
  
  #define   FMTSTR  1
  #define   FMTNUM  2
! #define   FMTNUM_U3
! #define   FMTFLOAT4
! #define   FMTCHAR 5
! #define   FMTWIDTH6
! #define   FMTLEN  7
  
  static void
  dopr(char *buffer, const char *format, va_list args, char *end)
  {
int ch;
int longlongflag = 0;
int longflag = 0;
int pointflag = 0;
int maxwidth = 0;
int ljust;
int len;
int zpad;
***
*** 173,178 
--- 173,179 
const char* fmtbegin;
int fmtpos = 1;
int realpos = 0;
+   int precision;
int position;
char*output;
int percents = 1;
***
*** 195,200 
--- 196,203 
int pointflag;
charfunc;
int realpos;
+   int longflag;
+   int longlongflag;
} *fmtpar, **fmtparptr;
  
/* Create enough structures to hold all arguments */
***
*** 229,240 
longflag = longlongflag = pointflag = 0;
fmtbegin = format - 1;
realpos = 0;
!   position = 0;
nextch:
ch = *format++;
switch (ch)
{
!   case 0:
goto performpr;
case '-':
   

Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests

2005-03-14 Thread Bruce Momjian
Nicolai Tufar wrote:
 On Thu, 10 Mar 2005 19:21:41 -0500 (EST), Bruce Momjian
 pgman@candle.pha.pa.us wrote:
   The CVS-tip implementation is fundamentally broken and won't work even
   for our internal uses.  I've not wasted time complaining about it
   because I thought we were going to replace it.  If we can't find a
   usable replacement then we're going to have to put a lot of effort
   into fixing what's there.  On the whole I think the effort would be
   better spent importing someone else's solution.
  
  Oh, so our existing implementation doesn't even meet our needs. OK.

(Your new patch is in the queue.)

I have been thinking about our current snprintf() implementation.  As I
remember, we use snprintf mostly for an snprintf that doesn't support
long long, and now those that don't support %$.  I am wondering if we
should just process long long args and %$ args, and pass everything else
to the native snprintf.

In fact, one trick would be to substitute long long and %$ in the printf
format string, and then pass that to the native libc printf, with
adjustments for the printf format arguments.  That might be simpler than
emulating all of snprintf.

FYI, now that we are using pg_snprintf macros the native snprintf is
available to us.

Anyway, I am sure there are some platforms that don't have vsnprint or
snprintf, but could we just say we don't support them, or emulate one of
we only have the other?

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
  joining column's datatypes do not match


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests to fail

2005-03-14 Thread Tom Lane
Bruce Momjian pgman@candle.pha.pa.us writes:
 I am wondering if we should just process long long args and %$ args,
 and pass everything else to the native snprintf.

AFAICS this is a non-starter --- how will you construct the call to
snprintf?  Or even vsnprintf?  C doesn't provide the tools you need
to make it happen.

regards, tom lane

---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests

2005-03-14 Thread Bruce Momjian
Tom Lane wrote:
 Bruce Momjian pgman@candle.pha.pa.us writes:
  I am wondering if we should just process long long args and %$ args,
  and pass everything else to the native snprintf.
 
 AFAICS this is a non-starter --- how will you construct the call to
 snprintf?  Or even vsnprintf?  C doesn't provide the tools you need
 to make it happen.

Couldn't you spin through the varargs and reconstruct a new one?
Is there no way to create a va_arg va_list structure in C?

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 6: Have you searched our list archives?

   http://archives.postgresql.org


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests to fail

2005-03-14 Thread Tom Lane
Bruce Momjian pgman@candle.pha.pa.us writes:
 Is there no way to create a va_arg va_list structure in C?

Exactly.  The standard lets you *read out* from such a structure,
but there's no provision for creating one on-the-fly.

regards, tom lane

---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
  joining column's datatypes do not match


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests to fail

2005-03-12 Thread Nicolai Tufar
Resubmission of yesterday's patch so that it would
cont conflict with Bruce's cvs commit. Pleas apply.

Best regards,
Nicolai.


On Sat, 12 Mar 2005 01:58:15 +0200, Nicolai Tufar [EMAIL PROTECTED] wrote:
 On Thu, 10 Mar 2005 19:21:41 -0500 (EST), Bruce Momjian
 pgman@candle.pha.pa.us wrote:
   The CVS-tip implementation is fundamentally broken and won't work even
   for our internal uses.  I've not wasted time complaining about it
   because I thought we were going to replace it.  If we can't find a
   usable replacement then we're going to have to put a lot of effort
   into fixing what's there.  On the whole I think the effort would be
   better spent importing someone else's solution.
 
  Oh, so our existing implementation doesn't even meet our needs. OK.
 
 Which made me wander why did I not aggree with
 Tom Lane's suggestion to make do three passes
 instead of two. Tom was right, as usual. It happened to
 be much easier than I expected. The patch is attached.
 Please apply.
 
 Tom, what do you think? Will it be fine with you?
 
 Best regards,
 Nicolai
 
 

*** ./src/port/snprintf.c.orig	Sat Mar 12 09:13:43 2005
--- ./src/port/snprintf.c	Sat Mar 12 10:01:44 2005
***
*** 195,200 
--- 195,202 
  		int	pointflag;
  		char	func;
  		int	realpos;
+ 		int	longflag;
+ 		int	longlongflag;
  	} *fmtpar, **fmtparptr;
  
  	/* Create enough structures to hold all arguments */
***
*** 264,275 
--- 266,279 
  		realpos = position;
  		len = 0;
  		goto nextch;
+ /*
  	case '*':
  		if (pointflag)
  			maxwidth = va_arg(args, int);
  		else
  			len = va_arg(args, int);
  		goto nextch;
+ */
  	case '.':
  		pointflag = 1;
  		goto nextch;
***
*** 301,316 
  #endif
  	case 'u':
  	case 'U':
! 		/* fmtnum(value,base,dosign,ljust,len,zpad,output) */
! 		if (longflag)
! 		{
! 			if (longlongflag)
! value = va_arg(args, uint64);
! 			else
! value = va_arg(args, unsigned long);
! 		}
! 		else
! 			value = va_arg(args, unsigned int);
  		fmtpar[fmtpos].fmtbegin = fmtbegin;
  		fmtpar[fmtpos].fmtend = format;
  		fmtpar[fmtpos].numvalue = value;
--- 305,312 
  #endif
  	case 'u':
  	case 'U':
! 		fmtpar[fmtpos].longflag = longflag;
! 		fmtpar[fmtpos].longlongflag = longlongflag;
  		fmtpar[fmtpos].fmtbegin = fmtbegin;
  		fmtpar[fmtpos].fmtend = format;
  		fmtpar[fmtpos].numvalue = value;
***
*** 325,340 
  		break;
  	case 'o':
  	case 'O':
! 		/* fmtnum(value,base,dosign,ljust,len,zpad,output) */
! 		if (longflag)
! 		{
! 			if (longlongflag)
! value = va_arg(args, uint64);
! 			else
! value = va_arg(args, unsigned long);
! 		}
! 		else
! 			value = va_arg(args, unsigned int);
  		fmtpar[fmtpos].fmtbegin = fmtbegin;
  		fmtpar[fmtpos].fmtend = format;
  		fmtpar[fmtpos].numvalue = value;
--- 321,328 
  		break;
  	case 'o':
  	case 'O':
! 		fmtpar[fmtpos].longflag = longflag;
! 		fmtpar[fmtpos].longlongflag = longlongflag;
  		fmtpar[fmtpos].fmtbegin = fmtbegin;
  		fmtpar[fmtpos].fmtend = format;
  		fmtpar[fmtpos].numvalue = value;
***
*** 349,365 
  		break;
  	case 'd':
  	case 'D':
! 		if (longflag)
! 		{
! 			if (longlongflag)
! 			{
! value = va_arg(args, int64);
! 			}
! 			else
! value = va_arg(args, long);
! 		}
! 		else
! 			value = va_arg(args, int);
  		fmtpar[fmtpos].fmtbegin = fmtbegin;
  		fmtpar[fmtpos].fmtend = format;
  		fmtpar[fmtpos].numvalue = value;
--- 337,344 
  		break;
  	case 'd':
  	case 'D':
! 		fmtpar[fmtpos].longflag = longflag;
! 		fmtpar[fmtpos].longlongflag = longlongflag;
  		fmtpar[fmtpos].fmtbegin = fmtbegin;
  		fmtpar[fmtpos].fmtend = format;
  		fmtpar[fmtpos].numvalue = value;
***
*** 373,387 
  		fmtpos++;
  		break;
  	case 'x':
! 		if (longflag)
! 		{
! 			if (longlongflag)
! value = va_arg(args, uint64);
! 			else
! value = va_arg(args, unsigned long);
! 		}
! 		else
! 			value = va_arg(args, unsigned int);
  		fmtpar[fmtpos].fmtbegin = fmtbegin;
  		fmtpar[fmtpos].fmtend = format;
  		fmtpar[fmtpos].numvalue = value;
--- 352,359 
  		fmtpos++;
  		break;
  	case 'x':
! 		fmtpar[fmtpos].longflag = longflag;
! 		fmtpar[fmtpos].longlongflag = longlongflag;
  		fmtpar[fmtpos].fmtbegin = fmtbegin;
  		fmtpar[fmtpos].fmtend = format;
  		fmtpar[fmtpos].numvalue = value;
***
*** 395,409 
  		fmtpos++;
  		break;
  	case 'X':
! 		if (longflag)
! 		{
! 			if (longlongflag)
! value = va_arg(args, uint64);
! 			else
! value = va_arg(args, unsigned long);
! 			

Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests

2005-03-11 Thread Bruce Momjian
Tom Lane wrote:
 [EMAIL PROTECTED] writes:
  Please see my posting about using a macro for snprintf.
 
  Wasn't the issue about odd behavior of the Win32 linker choosing the wrong
  vnsprintf?
 
 You're right, the point about the macro was to avoid linker weirdness on
 Windows.  We need to do that part in any case.  I think Bruce confused
 that issue with the one about whether our version supported %n$
 adequately ... which it doesn't just yet ...

Perhaps I am reading old email in this reply but I thought I should
clarify:

Once we do:

#define vsnprintf(...)pg_vsnprintf(__VA_ARGS__)
#define snprintf(...) pg_snprintf(__VA_ARGS__)
#define printf(...)   pg_printf(__VA_ARGS__)

we also rename the functions in snprintf.c to pg_* names so there is no
longer a conflict with the system libc versions.

The macro is to prevent our snprintf from leaking out of libraries like
libpq, not to fix the win32 linker problem, which we already had fixed
by reordering the entries in the C file.

Perhaps the macro idea originally came as a fix for Win32 but it is much
larger that that now.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests

2005-03-11 Thread Bruce Momjian
Nicolai Tufar wrote:
 On Thu, 10 Mar 2005 16:26:47 -0500 (EST), Bruce Momjian
 pgman@candle.pha.pa.us wrote:
  Please see my posting about using a macro for snprintf.  If the current
  implementation of snprintf is enough for our existing translation users
  we probably don't need to add anything more to it because snprintf will
  not be exported to client applications.
 
 Oh, Bruce. It will be the best solution. I was worried about
 the problems with my modifications to snprintf.c Tom Lane
 pointed out. But if we really separate snprintf() used by
 messages and snprintf() used by the like of 
 src/backend/utils/adt/int8.c then we are safe. We can claim
 current release safe and I will modify src/port/snprintf.c at my
 leisure later. I will try out your modifications tomorrow. It
 is late here and I have a PostgreSQL class to to teach 
 tomorrow ;)
 
 I still think that it is more convenient to rip off current
 implementation of snprintf.c and replace it with a very much
 stripped down of Trio's one. I will work on it and try to get
 a patch in one week's time. Thank you all for your patience.

I am not heading in the direction of using a different snprintf for
messages and for int8.c.  I am just renaming the calls via macros so we
don't leak snprintf from libpq.

One new idea I had was to have pg_snprintf() look over the format string
and adjust the arguments to match what the format string is requesting,
remove %$ from the format string, and then pass it to the native libc
snprintf().  That might be the easiest solution for the many platforms
with a good snprintf but not %$ support.

Is that possible/easier?

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests to fail

2005-03-11 Thread Nicolai Tufar
On Thu, 10 Mar 2005 19:21:41 -0500 (EST), Bruce Momjian
pgman@candle.pha.pa.us wrote:
  The CVS-tip implementation is fundamentally broken and won't work even
  for our internal uses.  I've not wasted time complaining about it
  because I thought we were going to replace it.  If we can't find a
  usable replacement then we're going to have to put a lot of effort
  into fixing what's there.  On the whole I think the effort would be
  better spent importing someone else's solution.
 
 Oh, so our existing implementation doesn't even meet our needs. OK.

Which made me wander why did I not aggree with
Tom Lane's suggestion to make do three passes 
instead of two. Tom was right, as usual. It happened to 
be much easier than I expected. The patch is attached.
Please apply. 

Tom, what do you think? Will it be fine with you?

Best regards,
Nicolai
*** ./src/port/snprintf.c.orig	Sat Mar 12 01:28:49 2005
--- ./src/port/snprintf.c	Sat Mar 12 01:08:30 2005
***
*** 195,200 
--- 195,202 
  		int	pointflag;
  		char	func;
  		int	realpos;
+ 		int	longflag;
+ 		int	longlongflag;
  	} *fmtpar, **fmtparptr;
  
  	/* Create enough structures to hold all arguments */
***
*** 263,274 
--- 265,278 
  		realpos = position;
  		len = 0;
  		goto nextch;
+ /*
  	case '*':
  		if (pointflag)
  			maxwidth = va_arg(args, int);
  		else
  			len = va_arg(args, int);
  		goto nextch;
+ */
  	case '.':
  		pointflag = 1;
  		goto nextch;
***
*** 300,315 
  #endif
  	case 'u':
  	case 'U':
! 		/* fmtnum(value,base,dosign,ljust,len,zpad,output) */
! 		if (longflag)
! 		{
! 			if (longlongflag)
! value = va_arg(args, uint64);
! 			else
! value = va_arg(args, unsigned long);
! 		}
! 		else
! 			value = va_arg(args, unsigned int);
  		fmtpar[fmtpos].fmtbegin = fmtbegin;
  		fmtpar[fmtpos].fmtend = format;
  		fmtpar[fmtpos].numvalue = value;
--- 304,311 
  #endif
  	case 'u':
  	case 'U':
! 		fmtpar[fmtpos].longflag = longflag;
! 		fmtpar[fmtpos].longlongflag = longlongflag;
  		fmtpar[fmtpos].fmtbegin = fmtbegin;
  		fmtpar[fmtpos].fmtend = format;
  		fmtpar[fmtpos].numvalue = value;
***
*** 324,339 
  		break;
  	case 'o':
  	case 'O':
! 		/* fmtnum(value,base,dosign,ljust,len,zpad,output) */
! 		if (longflag)
! 		{
! 			if (longlongflag)
! value = va_arg(args, uint64);
! 			else
! value = va_arg(args, unsigned long);
! 		}
! 		else
! 			value = va_arg(args, unsigned int);
  		fmtpar[fmtpos].fmtbegin = fmtbegin;
  		fmtpar[fmtpos].fmtend = format;
  		fmtpar[fmtpos].numvalue = value;
--- 320,327 
  		break;
  	case 'o':
  	case 'O':
! 		fmtpar[fmtpos].longflag = longflag;
! 		fmtpar[fmtpos].longlongflag = longlongflag;
  		fmtpar[fmtpos].fmtbegin = fmtbegin;
  		fmtpar[fmtpos].fmtend = format;
  		fmtpar[fmtpos].numvalue = value;
***
*** 348,364 
  		break;
  	case 'd':
  	case 'D':
! 		if (longflag)
! 		{
! 			if (longlongflag)
! 			{
! value = va_arg(args, int64);
! 			}
! 			else
! value = va_arg(args, long);
! 		}
! 		else
! 			value = va_arg(args, int);
  		fmtpar[fmtpos].fmtbegin = fmtbegin;
  		fmtpar[fmtpos].fmtend = format;
  		fmtpar[fmtpos].numvalue = value;
--- 336,343 
  		break;
  	case 'd':
  	case 'D':
! 		fmtpar[fmtpos].longflag = longflag;
! 		fmtpar[fmtpos].longlongflag = longlongflag;
  		fmtpar[fmtpos].fmtbegin = fmtbegin;
  		fmtpar[fmtpos].fmtend = format;
  		fmtpar[fmtpos].numvalue = value;
***
*** 372,386 
  		fmtpos++;
  		break;
  	case 'x':
! 		if (longflag)
! 		{
! 			if (longlongflag)
! value = va_arg(args, uint64);
! 			else
! value = va_arg(args, unsigned long);
! 		}
! 		else
! 			value = va_arg(args, unsigned int);
  		fmtpar[fmtpos].fmtbegin = fmtbegin;
  		fmtpar[fmtpos].fmtend = format;
  		fmtpar[fmtpos].numvalue = value;
--- 351,358 
  		fmtpos++;
  		break;
  	case 'x':
! 		fmtpar[fmtpos].longflag = longflag;
! 		fmtpar[fmtpos].longlongflag = longlongflag;
  		fmtpar[fmtpos].fmtbegin = fmtbegin;
  		fmtpar[fmtpos].fmtend = format;
  		fmtpar[fmtpos].numvalue = value;
***
*** 394,408 
  		fmtpos++;
  		break;
  	case 'X':
! 		if (longflag)
! 		{
! 			if (longlongflag)
! value = va_arg(args, uint64);
! 			else
! value = va_arg(args, unsigned long);
! 		}
! 		else
! 			value = va_arg(args, unsigned int);
  		fmtpar[fmtpos].fmtbegin = fmtbegin;
  		fmtpar[fmtpos].fmtend = format;
  		fmtpar[fmtpos].numvalue = value;
--- 366,373 
  		fmtpos++;
  	

Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests to fail

2005-03-10 Thread Nicolai Tufar
On Wed, 9 Mar 2005 22:51:27 -0500 (EST), Bruce Momjian
pgman@candle.pha.pa.us wrote:
  What do you think about it? Shall I abandon FreeBSD and go ahead
  Incorporating Trio?
 
 Yes, maybe just add the proper %$ handling from Trio to what we have
 now.

Adding proper %$ from Trio will require too much effort. I would
rather not do it. Not because I am lazy but because:

1) Trio team seem to be very serious about standards, update
the library as soon as new standards come out:
quote
Trio fully implements the C99 (ISO/IEC 9899:1999) and UNIX98 (the
Single Unix Specification, Version 2) standards, as well as many
features from other implementations, e.g. the GNU libc and BSD4.
/quote

2) If we integrate the whole library in source code we will
not have to maintain it and will rely on Trio team for bug fixes
and updates. Integrating it will be very easy since all of the 
functions begin with trio_. I used it instead of the src/port/snrpintf.c
one and it passes regression tests under Win32 just fine.

The downside is that Trio library is rather big. It is 3 .c and 6 .h
files totalling 11556 lines. Compiled it is 71224 bytes not stripped
and 56204 bytes stripped on Solaris 10 for x86, 32-bit. Even for
a shared library it will probably be too much. Trio has a lot
of string handling functions which are probably not necessary.
Would you like me to try to remove everything unnecessary from
it or we will settle with the full version?


Regards,
Nicolai Tufar

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests

2005-03-10 Thread Bruce Momjian
Nicolai Tufar wrote:
 On Wed, 9 Mar 2005 22:51:27 -0500 (EST), Bruce Momjian
 pgman@candle.pha.pa.us wrote:
   What do you think about it? Shall I abandon FreeBSD and go ahead
   Incorporating Trio?
  
  Yes, maybe just add the proper %$ handling from Trio to what we have
  now.
 
 Adding proper %$ from Trio will require too much effort. I would
 rather not do it. Not because I am lazy but because:
 
 1) Trio team seem to be very serious about standards, update
 the library as soon as new standards come out:
 quote
 Trio fully implements the C99 (ISO/IEC 9899:1999) and UNIX98 (the
 Single Unix Specification, Version 2) standards, as well as many
 features from other implementations, e.g. the GNU libc and BSD4.
 /quote
 
 2) If we integrate the whole library in source code we will
 not have to maintain it and will rely on Trio team for bug fixes
 and updates. Integrating it will be very easy since all of the 
 functions begin with trio_. I used it instead of the src/port/snrpintf.c
 one and it passes regression tests under Win32 just fine.
 
 The downside is that Trio library is rather big. It is 3 .c and 6 .h
 files totalling 11556 lines. Compiled it is 71224 bytes not stripped
 and 56204 bytes stripped on Solaris 10 for x86, 32-bit. Even for
 a shared library it will probably be too much. Trio has a lot
 of string handling functions which are probably not necessary.
 Would you like me to try to remove everything unnecessary from
 it or we will settle with the full version?

Please see my posting about using a macro for snprintf.  If the current
implementation of snprintf is enough for our existing translation users
we probably don't need to add anything more to it because snprintf will
not be exported to client applications.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests

2005-03-10 Thread Nicolai Tufar
On Thu, 10 Mar 2005 16:26:47 -0500 (EST), Bruce Momjian
pgman@candle.pha.pa.us wrote:
 Please see my posting about using a macro for snprintf.  If the current
 implementation of snprintf is enough for our existing translation users
 we probably don't need to add anything more to it because snprintf will
 not be exported to client applications.

Oh, Bruce. It will be the best solution. I was worried about
the problems with my modifications to snprintf.c Tom Lane
pointed out. But if we really separate snprintf() used by
messages and snprintf() used by the like of 
src/backend/utils/adt/int8.c then we are safe. We can claim
current release safe and I will modify src/port/snprintf.c at my
leisure later. I will try out your modifications tomorrow. It
is late here and I have a PostgreSQL class to to teach 
tomorrow ;)

I still think that it is more convenient to rip off current
implementation of snprintf.c and replace it with a very much
stripped down of Trio's one. I will work on it and try to get
a patch in one week's time. Thank you all for your patience.


Best regards,
Nicolai Tufar


 
 --
   Bruce Momjian|  http://candle.pha.pa.us
   pgman@candle.pha.pa.us   |  (610) 359-1001
   +  If your life is a hard drive, |  13 Roberts Road
   +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073
 
 ---(end of broadcast)---
 TIP 2: you can get off all lists at once with the unregister command
 (send unregister YourEmailAddressHere to [EMAIL PROTECTED])


---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests to fail

2005-03-10 Thread Tom Lane
Bruce Momjian pgman@candle.pha.pa.us writes:
 Please see my posting about using a macro for snprintf.  If the current
 implementation of snprintf is enough for our existing translation users
 we probably don't need to add anything more to it because snprintf will
 not be exported to client applications.

The CVS-tip implementation is fundamentally broken and won't work even
for our internal uses.  I've not wasted time complaining about it
because I thought we were going to replace it.  If we can't find a
usable replacement then we're going to have to put a lot of effort
into fixing what's there.  On the whole I think the effort would be
better spent importing someone else's solution.

regards, tom lane

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests

2005-03-10 Thread Bruce Momjian
Tom Lane wrote:
 Bruce Momjian pgman@candle.pha.pa.us writes:
  Please see my posting about using a macro for snprintf.  If the current
  implementation of snprintf is enough for our existing translation users
  we probably don't need to add anything more to it because snprintf will
  not be exported to client applications.
 
 The CVS-tip implementation is fundamentally broken and won't work even
 for our internal uses.  I've not wasted time complaining about it
 because I thought we were going to replace it.  If we can't find a
 usable replacement then we're going to have to put a lot of effort
 into fixing what's there.  On the whole I think the effort would be
 better spent importing someone else's solution.

Oh, so our existing implementation doesn't even meet our needs. OK.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests

2005-03-10 Thread Tom Lane
[EMAIL PROTECTED] writes:
 Please see my posting about using a macro for snprintf.

 Wasn't the issue about odd behavior of the Win32 linker choosing the wrong
 vnsprintf?

You're right, the point about the macro was to avoid linker weirdness on
Windows.  We need to do that part in any case.  I think Bruce confused
that issue with the one about whether our version supported %n$
adequately ... which it doesn't just yet ...

regards, tom lane

---(end of broadcast)---
TIP 8: explain analyze is your friend


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests to fail

2005-03-10 Thread Nicolai Tufar
Tom Lane wrote:
 The CVS-tip implementation is fundamentally broken and won't work even
 for our internal uses.  I've not wasted time complaining about it
 because I thought we were going to replace it.  If we can't find a
 usable replacement then we're going to have to put a lot of effort
 into fixing what's there.  On the whole I think the effort would be
 better spent importing someone else's solution.

Bruce Momjian wrote:
 Oh, so our existing implementation doesn't even meet our needs. OK.

Very well, I too, tend to think that importing some else's solution
is the way to go. Tom, have you looked at Trio? If it is fine with you too,
I will strip it to the bare minimum needed for snprintf(), vsnprintf() and
printf() by Saturday.

Regards,
Nicolai Tufar

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests to fail

2005-03-10 Thread Tom Lane
Nicolai Tufar [EMAIL PROTECTED] writes:
 Very well, I too, tend to think that importing some else's solution
 is the way to go. Tom, have you looked at Trio?

I have not seen it ... but if it looks reasonable to you, have a go
at it.

regards, tom lane

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests to fail

2005-03-10 Thread Nicolai Tufar
On Fri, 11 Mar 2005 01:14:31 -0500, Tom Lane wrote:
 Nicolai Tufar [EMAIL PROTECTED] writes:
  Very well, I too, tend to think that importing some else's solution
  is the way to go. Tom, have you looked at Trio?
 
 I have not seen it ... but if it looks reasonable to you, have a go
 at it.

It looks reasonable to me. It claims to: fully implement C99 (ISO/IEC
9899:1999) and UNIX98 (the
Single Unix Specification, Version 2) standards, as well as many
features from other implementations, e.g. the GNU libc and BSD4.

I compiled and run regression tests with it used instead of 
our current implementation and it worked fine under win32 and
Solaris x86. The only problem is that it is 11000 lines as
oposed to our curent implementation's 600. I  will remove
everything unnecessary and submit a patch for consideration.

Regards,
Nicolai Tufar

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests to fail

2005-03-09 Thread Nicolai Tufar
Dear all,
After struggling for one week to to integrate FreeBSD's vfprintf.c into
PostgreSQL I finally gave up. It is too dependent on underlying
FreeBSD system functions. To incorporate it into PostgreSQL we need
to move vfprintf.c file itself, two dozen files form gdtoa and a half
a dozen __XXtoa.c files scattered in apparently random fashion all
around FreeBSD source tree.

Instead I researched some other implementations of snprintf on
the web released under a license compatible with PostgreSQL's.
The most suitable one I have come upon is Trio
[http://daniel.haxx.se/projects/trio/].
It is distributed under a MIT-like license which, I think will be
compatible with us.

What do you think about it? Shall I abandon FreeBSD and go ahead
ncorporatng Tro?

And by the way, what s the concluson of snprntf() vs. pg_snprintf()
and UNIX libraries discussion a week ago? Which one shall 
I implement?

Regards,
Nicolai Tufar

---(end of broadcast)---
TIP 6: Have you searched our list archives?

   http://archives.postgresql.org


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests

2005-03-09 Thread Bruce Momjian
Nicolai Tufar wrote:
 Dear all,
 After struggling for one week to to integrate FreeBSD's vfprintf.c into
 PostgreSQL I finally gave up. It is too dependent on underlying
 FreeBSD system functions. To incorporate it into PostgreSQL we need
 to move vfprintf.c file itself, two dozen files form gdtoa and a half
 a dozen __XXtoa.c files scattered in apparently random fashion all
 around FreeBSD source tree.
 
 Instead I researched some other implementations of snprintf on
 the web released under a license compatible with PostgreSQL's.
 The most suitable one I have come upon is Trio
 [http://daniel.haxx.se/projects/trio/].
 It is distributed under a MIT-like license which, I think will be
 compatible with us.
 
 What do you think about it? Shall I abandon FreeBSD and go ahead
 ?ncorporat?ng Tr?o?

Yes, maybe just add the proper %$ handling from Trio to what we have
now.

 And by the way, what ?s the conclus?on of snpr?ntf() vs. pg_snprintf()
 and UNIX libraries discussion a week ago? Which one shall 
 I implement?

I think the proper direction is not to export snprintf() from libpq so
that user applications will use the native snprintf, but our code can
use our custom version.

I will work on a patch now.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests to fail

2005-03-02 Thread Nicolai Tufar
On Wed, 2 Mar 2005 09:24:32 +0100, Joerg Hessdoerfer
[EMAIL PROTECTED] wrote:
 don't know if PG borrowed the code from here, but according to the manpage
 FreeBSD 5.3 seems to have a quite complete implementation, see
 http://www.freebsd.org/cgi/man.cgi?query=snprintfapropos=0sektion=3manpath=FreeBSD+5.3-RELEASE+and+Portsformat=html
 
 Would this help?

Yes, it would. With Tom Lane's blessing I am starting on incorporating it into
PG now.

---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests

2005-03-02 Thread Bruce Momjian
Tom Lane wrote:
 Bruce Momjian pgman@candle.pha.pa.us writes:
  Have we considered what is going to happen to applications when they use
  our snprintf instead of the one from the operating system?
 
 Hmm ...
 
 First line of thought: we surely must not insert a snprintf into
 libpq.so unless it is 100% up to spec *and* has no performance issues
 ... neither of which can be claimed of the CVS-tip version.

Agreed, and we have to support all the 64-bit specifications a port
might support like %qd and %I64d as well as %lld.  I have added that to
our current CVS version.

 Second line of thought: libpq already feels free to insert allegedly
 up-to-spec versions of a number of things, and no one has complained.
 Maybe the linker prevents problems by not linking these versions to
 any calls from outside libpq?

I just tested on BSD/OS and a program with a single printf() call does
call our printf if libpq is used on the link line.  The program makes no
libpq calls at all.

 Third thought: Windows' linker seems to be broken enough that it may
 create problems of this ilk that exist on no other platform.

Yes, strangly the Window's linker is fine because libpqdll.def defines
what symbols are exported.  I don't think Unix has that capability.

Is there any way we can have just gettext() call our snprintf under a
special name?

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests to fail

2005-03-02 Thread Tom Lane
Bruce Momjian pgman@candle.pha.pa.us writes:
 Tom Lane wrote:
 First line of thought: we surely must not insert a snprintf into
 libpq.so unless it is 100% up to spec *and* has no performance issues
 ... neither of which can be claimed of the CVS-tip version.

 Agreed, and we have to support all the 64-bit specifications a port
 might support like %qd and %I64d as well as %lld.  I have added that to
 our current CVS version.

I really dislike that idea and request that you revert it.

 Is there any way we can have just gettext() call our snprintf under a
 special name?

The issue only comes up in libpq --- in the backend there is no reason
that snprintf can't be our snprintf, and likewise in self-contained
programs like psql.  It might be worth the pain-in-the-neck quality to
have libpq refer to the functions as pq_snprintf etc.  Perhaps we could
do this via macros

#define snprintfpq_snprintf

and not have to uglify the source code.

regards, tom lane

---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests

2005-03-02 Thread Bruce Momjian
Tom Lane wrote:
 Bruce Momjian pgman@candle.pha.pa.us writes:
  Tom Lane wrote:
  First line of thought: we surely must not insert a snprintf into
  libpq.so unless it is 100% up to spec *and* has no performance issues
  ... neither of which can be claimed of the CVS-tip version.
 
  Agreed, and we have to support all the 64-bit specifications a port
  might support like %qd and %I64d as well as %lld.  I have added that to
  our current CVS version.
 
 I really dislike that idea and request that you revert it.

Done.

  Is there any way we can have just gettext() call our snprintf under a
  special name?
 
 The issue only comes up in libpq --- in the backend there is no reason
 that snprintf can't be our snprintf, and likewise in self-contained
 programs like psql.  It might be worth the pain-in-the-neck quality to
 have libpq refer to the functions as pq_snprintf etc.  Perhaps we could
 do this via macros
 
 #define snprintf  pq_snprintf
 
 and not have to uglify the source code.

Yes, this is what I was thinking of too.  I think it would need a macro
in libpq to map the libc names to the pq_* names, and a separate /port C
file that maps the normal libc names to the pg_* names.  For client
applications and the backend, this new C file would catch all the
snprintf calls, while for libpq the pg_* calls would be used directly
and the new C file with the libc symbols would not be pulled in.

Does that sound like a plan?

The reason we can't just use the macro everwhere is that we don't want
applications using libpq to all be using pg_* functions, only psql and
our own.  The only other solution I can think of is to make sure all
client apps use FRONTEND as a define and trigger the macros from libc
names to pg_* names on that.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests to fail

2005-03-01 Thread Nicolai Tufar
On Tue, 1 Mar 2005 00:55:20 -0500 (EST), Bruce Momjian 
 My next guess
 is that Win32 isn't handling va_arg(..., long long int) properly.
 

I am trying various combination of number and types
of parameters in my test program and everything prints fine.
When it comes to pg, it fails :(

template1=# select * from test where x  1000::int8;
 x

 -869367531
(1 row)

I am not too fluent in source code, could someone
point me to there actual call to snprintf() is being done
when a query like this is executed. I could not find it myslef
:(

Regards,
Nick

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests

2005-03-01 Thread Bruce Momjian
Nicolai Tufar wrote:
 On Tue, 1 Mar 2005 00:55:20 -0500 (EST), Bruce Momjian 
  My next guess
  is that Win32 isn't handling va_arg(..., long long int) properly.
  
 
 I am trying various combination of number and types
 of parameters in my test program and everything prints fine.
 When it comes to pg, it fails :(
 
 template1=# select * from test where x  1000::int8;
  x
 
  -869367531
 (1 row)
 
 I am not too fluent in source code, could someone
 point me to there actual call to snprintf() is being done
 when a query like this is executed. I could not find it myslef

Sure, in src/backend/utils/adt/int8.c, there is a call in int8out():

if ((len = snprintf(buf, MAXINT8LEN, INT64_FORMAT, val))  0)

and that calls port/snprintf.c.

I have added a puts() in snprintf.c to make sure it is getting the
long/long specifier.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  pgman@candle.pha.pa.us   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests to fail

2005-03-01 Thread Nicolai Tufar
I spent all day debugging it. Still have absolutely
no idea what could possibly go wrong. Does
anyone have a slightest clue what can it be and
why it manifests itself only on win32?


On Tue, 1 Mar 2005 09:29:07 -0500 (EST), Bruce Momjian
pgman@candle.pha.pa.us wrote:
 Nicolai Tufar wrote:
  On Tue, 1 Mar 2005 00:55:20 -0500 (EST), Bruce Momjian
   My next guess
   is that Win32 isn't handling va_arg(..., long long int) properly.
  
 
  I am trying various combination of number and types
  of parameters in my test program and everything prints fine.
  When it comes to pg, it fails :(
 
  template1=# select * from test where x  1000::int8;
   x
  
   -869367531
  (1 row)
 
  I am not too fluent in source code, could someone
  point me to there actual call to snprintf() is being done
  when a query like this is executed. I could not find it myslef
 
 Sure, in src/backend/utils/adt/int8.c, there is a call in int8out():
 
 if ((len = snprintf(buf, MAXINT8LEN, INT64_FORMAT, val))  0)
 
 and that calls port/snprintf.c.
 
 I have added a puts() in snprintf.c to make sure it is getting the
 long/long specifier.
 
 --
   Bruce Momjian|  http://candle.pha.pa.us
   pgman@candle.pha.pa.us   |  (610) 359-1001
   +  If your life is a hard drive, |  13 Roberts Road
   +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073


---(end of broadcast)---
TIP 8: explain analyze is your friend


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests

2005-03-01 Thread Tom Lane
[EMAIL PROTECTED] writes:
 Just a question, and don't mind me if I am being rude, isn't this the
 WRONG PLACE for a printf function? Wouldn't an itoa function be more
 efficient and be less problematic?

This particular call could be so replaced, but it wouldn't solve the
general problem.  snprintf has to work.

regards, tom lane

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests to fail

2005-03-01 Thread Magnus Hagander
 I spent all day debugging it. Still have absolutely
 no idea what could possibly go wrong. Does
 anyone have a slightest clue what can it be and
 why it manifests itself only on win32?

It may be that the CLIB  has badly broken support for 64bit 
integers on 32
bit platforms. Does anyone know of any Cygwin/Ming issues?

Is this only with the new snprintf code in Win32?

Yes.


Is this a problem with snprintf as implemented in src/port?

Yes. Only. It works with the snprintf() in the runtime (this particular
part).


Is there a reason why we don't use the snprintf that comes with the
various C compilers?

It does not support positional parameters (I think it's called) which
is required for proper translations.
We do use that one when it works...

//Magnus

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests to fail

2005-03-01 Thread Nicolai Tufar
On Tue, 1 Mar 2005 15:38:58 -0500 (EST), [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 Is there a reason why we don't use the snprintf that comes with the
 various C compilers?

snprintf() is usually buried in OS libraries. We implement
our own snprintf to make things like this:
snprintf(buf,%2$s %1$s,world,Hello); 
which is not supported on some platforms work.

We do it for national language translation of
messages. In some languages you may need
to change order of parameters to make a meaningful
sentence.

Another question is why we are using it for printing
values from database. I am not too good on function
overriding in standard C but maybe there is a way
to usage of standard snprintf() in a particular place.

---(end of broadcast)---
TIP 6: Have you searched our list archives?

   http://archives.postgresql.org


Re: [pgsql-hackers-win32] [HACKERS] snprintf causes regression tests to fail

2005-03-01 Thread Tom Lane
[EMAIL PROTECTED] writes:
 Well, here is a stupid question, do we even know which snprintf we are
 using on Win32? May it be possible that we are using the MingW version
 which may be broken?

The regression tests were not failing until we started using the port/
version ...

regards, tom lane

---(end of broadcast)---
TIP 6: Have you searched our list archives?

   http://archives.postgresql.org