Re: writing c functions for postgres

Поиск
Список
Период
Сортировка
От Albe Laurenz
Тема Re: writing c functions for postgres
Дата
Msg-id D960CB61B694CF459DCFB4B0128514C202FF654D@exadv11.host.magwien.gv.at
обсуждение исходный текст
Ответ на writing c functions for postgres  (eehab hamzeh <eehab40@hotmail.com>)
Ответы Re: writing c functions for postgres  (Glyn Astill <glynastill@yahoo.co.uk>)
Список pgsql-general
eehab hamzeh wrote:
> I am trying to build some functions using C language. these functions are
> mentioned in the postgresql documentation.
>
> the only function that are work are the one with int32 variable.
> the other function bring errors and are not working
> any body can give directions
>
> #include "postgres.h"
> #include <string.h>
> #include "fmgr.h"
>
> #ifdef PG_MODULE_MAGIC
> PG_MODULE_MAGIC;
> #endif
>
[...]
>
> PG_FUNCTION_INFO_V1(makepoint);
>
> Datum
> makepoint(PG_FUNCTION_ARGS)
> {
>     /* Here, the pass-by-reference nature of Point is not hidden. */
>     Point     *pointx = PG_GETARG_POINT_P(0);
>     Point     *pointy = PG_GETARG_POINT_P(1);
>     Point     *new_point = (Point *) palloc(sizeof(Point));
>
[...]
>
> PG_FUNCTION_INFO_V1(copytext);
>
> Datum
> copytext(PG_FUNCTION_ARGS)
> {
[...]
>     VARATT_SIZEP(new_t) = VARSIZE(t);
[...]
> }
>
> PG_FUNCTION_INFO_V1(concat_text);
>
> Datum
> concat_text(PG_FUNCTION_ARGS)
> {
[...]
>     VARATT_SIZEP(new_text) = new_text_size;
[...]
> }
>
>
> the error
>
> in function 'makepoint':
> error: 'Point' undeclared (first use in this function)
> error: (each undeclared identifier is reported only one
> error: for each function it appears in.)
> error: 'pointx' undeclared (first use in ´this function)
> error: 'pointy' undeclared (first use in his fnction)
> error 'new_point' undeclared (first use in his function)
> error: syntax error befre ')' oken
> in function 'copy text':
> error: 'invalid lvalue in assinment
> In function 'concat_text'
> error: invalid lvalue in assignement
> warning no new line at end of file

These error messages are certainly not what you saw on the screen.
It is best to copy and paste error messages!

If you want to have Point, you'll have to
#include "utils/geo_decls.h"

The "invalid lvalue" errors are generated because gcc does not
know VARATT_SIZEP and assumes it is a function returning int.
I recommend that you always use gcc with -Wall to see warnings!

I can find no VARATT_SIZEP in the PostgreSQL 8.3 headers.
Where did you get that from?

Yours,
Laurenz Albe

В списке pgsql-general по дате отправления:

Предыдущее
От: "Albe Laurenz"
Дата:
Сообщение: Re: Querying Large Objects
Следующее
От: "Albe Laurenz"
Дата:
Сообщение: Re: Convert Oracle function to PostgreSQL