Re: Complier warnings on mingw gcc 4.5.0

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Alvaro Herrera <alvherre(at)commandprompt(dot)com>, Itagaki Takahiro <itagaki(dot)takahiro(at)gmail(dot)com>, Hiroshi Inoue <inoue(at)tpf(dot)co(dot)jp>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Complier warnings on mingw gcc 4.5.0
Date: 2010-12-16 17:15:09
Message-ID: 23102.1292519709@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> It's working, but I don't think it's right :-) In particular, I don't
> believe this, or rather I don't believe that its converse is false:

> /* If not HAVE_GETOPT, we are using src/port/getopt.c, which has
> optreset */

Yeah, that was a 90% solution. I had first tried to look at whether
LIBOBJS contains "getopt.o", but it turns out that some versions of
autoconf actively prevent you from referencing that variable at all
in configure.in :-(.

> The trouble is that while we've forced use of our getopt.c, we haven't
> inhibited configure from checking the system's getopt. So on my test
> system HAVE_GETOPT is defined. Possibly I was wrong about needing to
> have optreset set with use of our port.

That's what I thought before.

At least in src/port/getopt.c (haven't looked at getopt_long), it would
only take one more line of code to make it safe against optreset not
being used. All that we need is an invariant that "place" is not
pointing at potentially volatile storage when we return -1, and most of
the returns have that already. (We don't really care about whether it
can be reset without a previous set of calls having been run to
completion, because we don't need that.)

If the same is true in getopt_long, then what I think we should do is
actually *remove* optreset from our implementations, and instead specify
that you can only switch to a new argv array after -1 has been returned.
That would remove a whole lot of unecessarily tense interactions with
the system libraries.

This is just in the nature of a cleanup so it probably needn't be
backpatched, unless people would rather that code be the same across all
branches (which does have its advantages).

Comments?

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David E. Wheeler 2010-12-16 17:19:17 Re: Extensions, patch v18 (merge against master, bitrot-only-fixes)
Previous Message Robert Haas 2010-12-16 17:12:30 Re: [PATCH] V3: Idle in transaction cancellation