Re: writing c functions for postgres

From: "Albe Laurenz" <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "eehab hamzeh *EXTERN*" <eehab40(at)hotmail(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: writing c functions for postgres
Date: 2009-04-07 06:48:51
Message-ID: D960CB61B694CF459DCFB4B0128514C202FF654D@exadv11.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers 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

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Glyn Astill 2009-04-07 08:35:21 Re: writing c functions for postgres
Previous Message Bruce Momjian 2009-04-07 04:02:41 pgsql: Add doc link to section about how to compile triggers.

Browse pgsql-general by date

  From Date Subject
Next Message Magnus Hagander 2009-04-07 07:02:26 Re: Anyone testing changes to libpq/bcc32.mak?
Previous Message Niederland 2009-04-07 05:37:08 exit code 128