Re: return value of a version-1 C function (Solved) - Mailing list pgsql-general

From Tom Lane
Subject Re: return value of a version-1 C function (Solved)
Date
Msg-id 15288.991751717@sss.pgh.pa.us
Whole thread Raw
In response to return value of a version-1 C function (Solved)  (Francesco Casadei <f_casadei@libero.it>)
Responses Re: return value of a version-1 C function (Solved)  (Francesco Casadei <f_casadei@libero.it>)
List pgsql-general
Francesco Casadei <f_casadei@libero.it> writes:
> 1) SPI_connect() and SPI_finish() mark a new memory context; since I must
> return cod I need to SPI_palloc() it in the upper Executor context. The
> problem is: how can I free the SPI_palloc()'ed memory?

I don't believe you need to.  AFAICT, SPI_palloc will allocate in the
context that was current when SPI_connect was called.  Assuming that
that was the active context when your function was entered, that is the
right context to palloc your result value in.  It's the executor's
responsibility to clean up the result value, not yours.

> 2) If I use the VARSIZE(__PTR) macro (defined in postgres.h) to set
> the size of cod, the compiler will complain about an invalid
> lvalue. This is not valid:

> VARSIZE(cod) = VARHDRSZ + 8;

Right.  As of 7.1 this should be

    VARATT_SIZEP(cod) = VARHDRSZ + 8;

Did we miss any places in the documentation where this needs to be
updated?

> 3) The following variable is an identifier (Name):

> Name tablename = PG_GETARG_NAME(0);

> (void)strlcat(query, NameStr(fieldname), sizeof(query));

Should be NameStr(*tablename).  Not too consistent maybe, but I didn't
invent that macro ;-)

            regards, tom lane

pgsql-general by date:

Previous
From: Evelio Martinez
Date:
Subject: Postgresql and W98
Next
From: Tom Lane
Date:
Subject: Re: psql , stored procedure, triggers and errors