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

From John Gunther
Subject Re: Problems using palloc in postgresql user C functions
Date
Msg-id 3E77F76F.6060705@bucksvsbytes.com
Whole thread Raw
In response to Re: Problems using palloc in postgresql user C functions  (Joe Conway <mail@joeconway.com>)
Responses Re: Problems using palloc in postgresql user C functions
List pgsql-novice
Joe,

Thanks for the fast, late night answer. I've got that much. But when I
compile and link my library with those statements (using libtool and
gcc) I get "undefined reference" errors for the following: textin,
textout, DirectFunctionCall1, CurrentMemoryContext,  MemoryContextAlloc,
and pg_detoast_datum. Handling these errors is where my understanding
fails? Can they be ignored somehow because they will be resolved at
execution time? It looks like they're fatal and preventing the library
from being created.

John

Joe Conway wrote:

> 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: Joe Conway
Date:
Subject: Re: Problems using palloc in postgresql user C functions
Next
From: Joe Conway
Date:
Subject: Re: Problems using palloc in postgresql user C functions