Re: Problems using palloc in postgresql user C functions - Mailing list pgsql-novice

From Joe Conway
Subject Re: Problems using palloc in postgresql user C functions
Date
Msg-id 3E77EF4A.1080002@joeconway.com
Whole thread Raw
In response to Problems using palloc in postgresql user C functions  (John Gunther <inbox@bucksvsbytes.com>)
Responses Re: Problems using palloc in postgresql user C functions
List 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


pgsql-novice by date:

Previous
From: Jonathon Batson
Date:
Subject: Re: Last access time for a table
Next
From: John Gunther
Date:
Subject: Re: Problems using palloc in postgresql user C functions