Re: Problems using palloc in postgresql user C functions

From: Joe Conway <mail(at)joeconway(dot)com>
To: John Gunther <inbox(at)bucksvsbytes(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Problems using palloc in postgresql user C functions
Date: 2003-03-19 04:17:14
Message-ID: 3E77EF4A.1080002@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

John Gunther wrote:
> I'm creating a shared library of PostgreSQL user functions written in C.
> A couple of PG facilities appear very convenient or essential tools for
> use in user functions: the palloc function (to allocate PG memory) and
> the PG_STR_GET_TEXT and PG_TEXT_GET_STR macros (used to convert between
> PG text strings and regular C strings). The problem that arises when I
> use these, though, is that they generate unresolved references,
> requiring including a seemingly endless chain of dependent PG source
> files in the compilation of the library.
>

PG_TEXT_GET_STR and PG_STR_GET_TEXT are only locally defined in
varlena.c. You'll need to define these yourself:
#define PG_TEXT_GET_STR(textp_) \
DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(textp_)))
#define PG_STR_GET_TEXT(str_) \
DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(str_)))

palloc is defined in src/include/utils/palloc.h, so you need to include
that or more likely postgres.h which will include it for you, i.e.:
#include "postgres.h"

Try studying one of the contrib libraries for examples of use (e.g.
contrib/tablefunc makes use of a GET_STR macro that is the same as
PG_TEXT_GET_STR).

HTH,

Joe

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message John Gunther 2003-03-19 04:51:59 Re: Problems using palloc in postgresql user C functions
Previous Message Jonathon Batson 2003-03-19 04:09:51 Re: Last access time for a table