Re: Win32 fix for pg_dumpall - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: Win32 fix for pg_dumpall
Date
Msg-id 200408081507.i78F70N04713@candle.pha.pa.us
Whole thread Raw
In response to Re: Win32 fix for pg_dumpall  (Andrew Dunstan <andrew@dunslane.net>)
List pgsql-patches
Andrew Dunstan wrote:
>
>
> Bruce Momjian wrote:
>
> >
> >              /*
> >+              *    Sometime the child returns "\r\n", which doesn't match
> >+              *    our version string.  The backend uses
> >+              *    setvbuf(stdout, NULL, _IONBF, 0), but pg_dump doesn't
> >+              *    so we have to fix it here.
> >+              */
> >+             if (strlen(line) >= 2 &&
> >+                 line[strlen(line)-2] == '\r' &&
> >+                 line[strlen(line)-1] == '\n')
> >+             {
> >+                 line[strlen(line)-2] == '\n';
> >+                 line[strlen(line)-1] == '\0';
> >+             }
> >+
> >+             /*
> >
> >
> >
>
> I do not see how the comment relates at all to the code following it -
> buffer mode and line end mode are two different things. Also, the

Yea, you would _think_ they are unrelated on Win32, but they aren't.
:-)

Turns out when you do that call in the backend, all EOLs become \n and
not \r\n.  This is what Claudio found.  Let me document the strangeness
of this more clearly.

> repeated calls to strlen(line) are horribly inefficient - it should be
> called once and stashed in an int (I once made an order of magnitude
> speedup in a program by correcting a piece of someone else's code that
> looked like this: for (i = 0; i <= strlen(s); i++) where s was an
> invariant very long string)

OK, I will clean that up too, but after beta1.

--
  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

pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Win32 tablespace
Next
From: Andreas Pflug
Date:
Subject: Re: Win32 tablespace