Re: Problems using palloc in postgresql user C functions

From: John Gunther <inbox(at)bucksvsbytes(dot)com>
To:
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Problems using palloc in postgresql user C functions
Date: 2003-03-19 04:51:59
Message-ID: 3E77F76F.6060705@bucksvsbytes.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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
>
>
>

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Joe Conway 2003-03-19 05:17:03 Re: Problems using palloc in postgresql user C functions
Previous Message Joe Conway 2003-03-19 04:17:14 Re: Problems using palloc in postgresql user C functions