Re: Problems using palloc in postgresql user C functions

Поиск
Список
Период
Сортировка
От John Gunther
Тема Re: Problems using palloc in postgresql user C functions
Дата
Msg-id 3E77F76F.6060705@bucksvsbytes.com
обсуждение исходный текст
Ответ на Re: Problems using palloc in postgresql user C functions  (Joe Conway <mail@joeconway.com>)
Ответы Re: Problems using palloc in postgresql user C functions  (Joe Conway <mail@joeconway.com>)
Список 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 по дате отправления:

Предыдущее
От: Joe Conway
Дата:
Сообщение: Re: Problems using palloc in postgresql user C functions
Следующее
От: Joe Conway
Дата:
Сообщение: Re: Problems using palloc in postgresql user C functions