BUG #3264: SPI: int64's sometimes returned by value sometimes by reference

From: "Adam Kunen" <adam(dot)kunen(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #3264: SPI: int64's sometimes returned by value sometimes by reference
Date: 2007-05-10 00:58:31
Message-ID: 200705100058.l4A0wVtk064113@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 3264
Logged by: Adam Kunen
Email address: adam(dot)kunen(at)gmail(dot)com
PostgreSQL version: 8.2.4
Operating system: Ubuntu 7.04 - AMD64
Description: SPI: int64's sometimes returned by value sometimes by
reference
Details:

I have the ubuntu standard install of postgresql (including devel headers,
etc) for the 64-bit platform.

I have noticed some discrepencies with 64-bit values in tuples.
For a given row with multiple int8's I have noticed sometimes the value will
be passed by value and sometime by reference.

On my platform a int is 32-bit, long is 64-bit.

The DatumGetInt64 breaks for this because it seems to just be
dereferencing/casting a pointer, as defined as:

#define DatumGetInt64(X) (* ((int64 *) DatumGetPointer(X)))

So in my C trigger code I have been forced to make a wrapper around
SPI_getbinval to get my int64's that looks at the
TupleDesc->attrs[x]->attrbyval to determine which course of actions..
this is my wrapper:

int64 wrapper_get_int64(HeapTuple tup, TupleDesc desc, int colnum, bool
*isnull)
{
// get the value or pointer
Datum tmp = SPI_getbinval(tup, desc, colnum, isnull);

// if its null, return 0
if(*isnull)return 0;

// if its pass by value, return the int64
if(desc->attrs[colnum-1]->attbyval)return (int64)tmp;

// if its pass by reference, deref and return
else return DatumGetInt64(tmp);

}

This works great for me.

In all of the examples and contrib code i don't see anyone checking this,
all I see are examples like:

DatumGetInt64(SPI_getbinval(tup, desc, colnum, isnull));

So maybee this is not a bug... maybe a nice note about this in the docs
would be good. But it seems to me that some of the contrib code could fail
on a 64-bit platform when 64-bits can be passed by value.

If i'm missing something here, let me know :)

thanks
-Adam Kunen

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2007-05-10 04:37:18 Re: BUG #3264: SPI: int64's sometimes returned by value sometimes by reference
Previous Message Chris Browne 2007-05-09 13:40:06 Re: PSQL support on HP-UX, Solaris and AIX