Re: return value of a version-1 C function (Solved)

From: Francesco Casadei <f_casadei(at)libero(dot)it>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Francesco Casadei <f_casadei(at)libero(dot)it>, pgsql-general(at)postgresql(dot)org
Subject: Re: return value of a version-1 C function (Solved)
Date: 2001-06-06 11:44:44
Message-ID: 20010606134444.A9320@goku.kasby
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jun 05, 2001 at 10:35:17AM -0400, Tom Lane wrote:
> Francesco Casadei <f_casadei(at)libero(dot)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
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>
> end of the original message

The example with Text in section 13.4 of the PostgreSQL 7.1.2 Programmer's
Guide is quite self-explanatory. I was looking for BpChar and didn't pay
attention to it. The docs talk about "variable-length types", bringing as
example the text data type and I didn't know that fixed-length data type
(CHAR(n), i.e. BpChar) are actually the same as TEXT, VARCHAR and bytea. The
only difference is semantic.

typedef struct varlena bytea;
typedef struct varlena text;
typedef struct varlena BpChar; /* blank-padded char, ie SQL char(n) */
typedef struct varlena VarChar; /* var-length char, ie SQL varchar(n) */

Next time I will read ALL the docs before doing anything, sorry.

Francesco Casadei

P.S. I attached the wrong file to my previous post: that was the old (wrong)
version.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Marc Valentin 2001-06-06 12:04:47 Kylix dbexpress driver ?
Previous Message Ognyan Kulev 2001-06-06 11:41:29 Database quotas for users