Search Postgresql Archives

Re: writing c functions for postgres

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux