Re: [HACKERS] pgsql: Fix compiler warnings on 64-bit boxes:

Lists: pgsql-committerspgsql-hackers
From: teodor(at)postgresql(dot)org (Teodor Sigaev)
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix compiler warnings on 64-bit boxes: difference between
Date: 2006-09-06 07:22:14
Message-ID: 20060906072214.950149FB264@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

Log Message:
-----------
Fix compiler warnings on 64-bit boxes: difference between
pointers are int64, but warnings are emitted for position info in
error messages in parser, so, just cast it to int32

Modified Files:
--------------
pgsql/contrib/hstore:
hstore_io.c (r1.1 -> r1.2)
(http://developer.postgresql.org/cvsweb.cgi/pgsql/contrib/hstore/hstore_io.c.diff?r1=1.1&r2=1.2)


From: Gavin Sherry <swm(at)linuxworld(dot)com(dot)au>
To: Teodor Sigaev <teodor(at)postgresql(dot)org>
Cc: pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Fix compiler warnings on 64-bit boxes:
Date: 2006-09-06 07:37:46
Message-ID: Pine.LNX.4.58.0609061730360.6458@linuxworld.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On Wed, 6 Sep 2006, Teodor Sigaev wrote:

> Log Message:
> -----------
> Fix compiler warnings on 64-bit boxes: difference between
> pointers are int64, but warnings are emitted for position info in
> error messages in parser, so, just cast it to int32
>
> Modified Files:
> --------------
> pgsql/contrib/hstore:
> hstore_io.c (r1.1 -> r1.2)
> (http://developer.postgresql.org/cvsweb.cgi/pgsql/contrib/hstore/hstore_io.c.diff?r1=1.1&r2=1.2)

It might seem a minor quibble, but it seems like a more reliable approach
might be to cast to a 64 bit type and user a 64 bit int formatter.

It seems unlikely that state->ptr - state->begin would yield a number that
large but I don't know that that would be true of every platform or user.

Thanks,

Gavin


From: Teodor Sigaev <teodor(at)sigaev(dot)ru>
To: Gavin Sherry <swm(at)linuxworld(dot)com(dot)au>
Cc: Teodor Sigaev <teodor(at)postgresql(dot)org>, pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Fix compiler warnings on 64-bit boxes:
Date: 2006-09-06 08:05:41
Message-ID: 44FE8155.9080401@sigaev.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

> It might seem a minor quibble, but it seems like a more reliable approach
> might be to cast to a 64 bit type and user a 64 bit int formatter.
%ld ? %lld? depending on architecture?

>
> It seems unlikely that state->ptr - state->begin would yield a number that
> large but I don't know that that would be true of every platform or user.

I don't believe that it can be more that 1Gb - it's a limit for any varlena type.

--
Teodor Sigaev E-mail: teodor(at)sigaev(dot)ru
WWW: http://www.sigaev.ru/


From: Gavin Sherry <swm(at)linuxworld(dot)com(dot)au>
To: Teodor Sigaev <teodor(at)sigaev(dot)ru>
Cc: pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Fix compiler warnings on 64-bit boxes:
Date: 2006-09-06 08:13:37
Message-ID: Pine.LNX.4.58.0609061812130.6703@linuxworld.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On Wed, 6 Sep 2006, Teodor Sigaev wrote:

> > It might seem a minor quibble, but it seems like a more reliable approach
> > might be to cast to a 64 bit type and user a 64 bit int formatter.
> %ld ? %lld? depending on architecture?
>
> >
> > It seems unlikely that state->ptr - state->begin would yield a number that
> > large but I don't know that that would be true of every platform or user.
>
> I don't believe that it can be more that 1Gb - it's a limit for any varlena type.
>

True. int32 should be fine.

Thanks,

gavin


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Teodor Sigaev <teodor(at)postgresql(dot)org>, pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Fix compiler warnings on 64-bit boxes:
Date: 2006-09-06 13:56:46
Message-ID: 7659.1157551006@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

Gavin Sherry <swm(at)linuxworld(dot)com(dot)au> writes:
> It might seem a minor quibble, but it seems like a more reliable approach
> might be to cast to a 64 bit type and user a 64 bit int formatter.

int64 is a real pain to use in error messages because of the
machine-dependence of the format string --- the translation machinery
doesn't work reliably if you try to do

ereport(...errmsg("trouble at offset " UINT64_FORMAT, bigintvar));

because any given translator will see only one of the several possible
source strings. You can get around this if you have to (print the
bigint into a char[n] local array and then use %s in the message),
but it's not worth it when dealing with values that can't plausibly
overflow an int. I think Teodor fixed it the right way.

regards, tom lane


From: Teodor Sigaev <teodor(at)sigaev(dot)ru>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org, pgsql-committers(at)postgresql(dot)org
Subject: Re: [HACKERS] pgsql: Fix compiler warnings on 64-bit
Date: 2006-09-06 16:41:24
Message-ID: 44FEFA34.7060305@sigaev.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

> ereport(...errmsg("trouble at offset " UINT64_FORMAT, bigintvar));

One more solution: add format code %D to expand_fmt_string() which should be
expanded to usual %d on 32-bit architecture and to UINT64_FORMAT on 64-bit.

--
Teodor Sigaev E-mail: teodor(at)sigaev(dot)ru
WWW: http://www.sigaev.ru/


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Teodor Sigaev <teodor(at)sigaev(dot)ru>
Cc: pgsql-hackers(at)postgresql(dot)org, pgsql-committers(at)postgresql(dot)org
Subject: Re: [HACKERS] pgsql: Fix compiler warnings on 64-bit boxes:
Date: 2006-09-06 16:55:07
Message-ID: 20830.1157561707@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

Teodor Sigaev <teodor(at)sigaev(dot)ru> writes:
>> ereport(...errmsg("trouble at offset " UINT64_FORMAT, bigintvar));

> One more solution: add format code %D to expand_fmt_string() which should be
> expanded to usual %d on 32-bit architecture and to UINT64_FORMAT on 64-bit.

Not very workable unless you can figure out how to teach gcc what it means...
else we lose compiler checking that the corresponding argument matches,
which'd be even more important than usual with a machine-dependent
format code.

regards, tom lane