datum passed to macro which expects a pointer

Started by Gavin Sherryover 18 years ago10 messagespatches
Jump to latest
#1Gavin Sherry
swm@linuxworld.com.au

This may seem a little pedantic but I noticed a few places where we pass
a datum to a macro which treats the datum as a pointer. This works now
but might not in the future (if, say, Datum were to be 8 bytes).

Thanks,

Gavin

Attachments:

datum.difftext/x-diff; charset=us-asciiDownload+7-7
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Gavin Sherry (#1)
Re: datum passed to macro which expects a pointer

Gavin Sherry <swm@alcove.com.au> writes:

This may seem a little pedantic but I noticed a few places where we pass
a datum to a macro which treats the datum as a pointer. This works now
but might not in the future (if, say, Datum were to be 8 bytes).

Yeah, definitely something to fix. I think though that the cases
like this:

! PG_RETURN_TEXT_P(DatumGetPointer(result));

might as well just use PG_RETURN_DATUM instead of casting twice.

Was this just eyeball inspection or did you find a compiler that would
complain about this?

regards, tom lane

#3Gavin Sherry
swm@linuxworld.com.au
In reply to: Tom Lane (#2)
Re: datum passed to macro which expects a pointer

On Sat, Apr 12, 2008 at 06:02:39PM -0400, Tom Lane wrote:

Gavin Sherry <swm@alcove.com.au> writes:

This may seem a little pedantic but I noticed a few places where we pass
a datum to a macro which treats the datum as a pointer. This works now
but might not in the future (if, say, Datum were to be 8 bytes).

Yeah, definitely something to fix. I think though that the cases
like this:

! PG_RETURN_TEXT_P(DatumGetPointer(result));

might as well just use PG_RETURN_DATUM instead of casting twice.

Oh of course. Updated patch attached.

Was this just eyeball inspection or did you find a compiler that would
complain about this?

I wish. It was actually thrown up when we (Greenplum) changed the macros
to be inline functions as part of changing Datum to be 8 bytes. By using
inline functions we get proper type checking from the compiler and since
we have only a small number of target platforms and architectures,
inlining isn't an issue.

Thanks,

Gavin

Attachments:

datum2.difftext/x-diff; charset=us-asciiDownload+7-7
#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Gavin Sherry (#3)
Re: datum passed to macro which expects a pointer

Gavin Sherry <swm@alcove.com.au> writes:

I wish. It was actually thrown up when we (Greenplum) changed the macros
to be inline functions as part of changing Datum to be 8 bytes.

Hmmm ... Datum has been 8 bytes for many years, on 64-bit machines.
What is it you're trying to accomplish by making it wider on 32-bitters?

regards, tom lane

#5Gavin Sherry
swm@linuxworld.com.au
In reply to: Tom Lane (#4)
Re: datum passed to macro which expects a pointer

On Sat, Apr 12, 2008 at 07:07:48PM -0400, Tom Lane wrote:

Gavin Sherry <swm@alcove.com.au> writes:

I wish. It was actually thrown up when we (Greenplum) changed the macros
to be inline functions as part of changing Datum to be 8 bytes.

Hmmm ... Datum has been 8 bytes for many years, on 64-bit machines.
What is it you're trying to accomplish by making it wider on 32-bitters?

I miss stated there. This was actually about making key 64 bit types
pass by value instead of pass by reference.

Thanks,

Gavin

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Gavin Sherry (#3)
Re: datum passed to macro which expects a pointer

Gavin Sherry <swm@alcove.com.au> writes:

might as well just use PG_RETURN_DATUM instead of casting twice.

Oh of course. Updated patch attached.

Applied, thanks.

regards, tom lane

#7Bruce Momjian
bruce@momjian.us
In reply to: Gavin Sherry (#5)
Re: datum passed to macro which expects a pointer

"Gavin Sherry" <swm@alcove.com.au> writes:

On Sat, Apr 12, 2008 at 07:07:48PM -0400, Tom Lane wrote:

Gavin Sherry <swm@alcove.com.au> writes:

I wish. It was actually thrown up when we (Greenplum) changed the macros
to be inline functions as part of changing Datum to be 8 bytes.

Hmmm ... Datum has been 8 bytes for many years, on 64-bit machines.
What is it you're trying to accomplish by making it wider on 32-bitters?

I miss stated there. This was actually about making key 64 bit types
pass by value instead of pass by reference.

There was a patch to do this posted recently here as well.

http://archives.postgresql.org/pgsql-patches/2008-03/msg00335.php

Hm. I suppose it's true that you could make Datum 64-bit even on 32-bit
machines and make int8 and float8 pass-by-value. Seems unlikely to be a net
win though.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's On-Demand Production Tuning

#8Gavin Sherry
swm@linuxworld.com.au
In reply to: Bruce Momjian (#7)
Re: datum passed to macro which expects a pointer

On Sun, Apr 13, 2008 at 01:42:02AM +0100, Gregory Stark wrote:

"Gavin Sherry" <swm@alcove.com.au> writes:

On Sat, Apr 12, 2008 at 07:07:48PM -0400, Tom Lane wrote:

Gavin Sherry <swm@alcove.com.au> writes:

I wish. It was actually thrown up when we (Greenplum) changed the macros
to be inline functions as part of changing Datum to be 8 bytes.

Hmmm ... Datum has been 8 bytes for many years, on 64-bit machines.
What is it you're trying to accomplish by making it wider on 32-bitters?

I miss stated there. This was actually about making key 64 bit types
pass by value instead of pass by reference.

There was a patch to do this posted recently here as well.

http://archives.postgresql.org/pgsql-patches/2008-03/msg00335.php

Hm. I suppose it's true that you could make Datum 64-bit even on 32-bit
machines and make int8 and float8 pass-by-value. Seems unlikely to be a net
win though.

A very quick scan showed me that one bet is missed in this patch which
we learned about the hard way: write_auth_file() assumes timestamptz is
pass by reference.

I'm also not sure if endianness is completely covered in the patch but
it looks fairly accurate. I think PointerGetDatum() may need the union
trick (it's late where I am).

There were other places in the code which were assuming Datums were
equivalent to pointers. I'll dig them up.

Also, it means we can clean up parts of numeric.c which special case
calls from aggregates.

Seems like a pretty clean patch though.

Thanks,

Gavin

#9Gavin Sherry
swm@linuxworld.com.au
In reply to: Tom Lane (#6)
Re: datum passed to macro which expects a pointer

Hi all,

Attached are more fixes.

Thanks,

Gavin, with Feng Tian

Attachments:

more_datum_fixes.difftext/x-diff; charset=us-asciiDownload+96-95
#10Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Gavin Sherry (#9)
Re: datum passed to macro which expects a pointer

Gavin Sherry wrote:

Hi all,

Attached are more fixes.

Applied, thanks.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support