No title
Dear Sir
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
here are the code and the error , i compile them using vc++ 6 and VC++ 2008 and minGW the example below are for minGW
THANKS
#include "postgres.h"
#include <string.h>
#include "fmgr.h"
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
/* by value */
PG_FUNCTION_INFO_V1(add_one);
Datum
add_one(PG_FUNCTION_ARGS)
{
int32 arg = PG_GETARG_INT32(0);
PG_RETURN_INT32(arg + 1);
}
/* by reference, fixed length */
PG_FUNCTION_INFO_V1(add_one_float8);
Datum
add_one_float8(PG_FUNCTION_ARGS)
{
/* The macros for FLOAT8 hide its pass-by-reference nature. */
float8 arg = PG_GETARG_FLOAT8(0);
PG_RETURN_FLOAT8(arg + 1.0);
}
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));
new_point->x = pointx->x;
new_point->y = pointy->y;
PG_RETURN_POINT_P(new_point);
}
/* by reference, variable length */
PG_FUNCTION_INFO_V1(copytext);
Datum
copytext(PG_FUNCTION_ARGS)
{
text *t = PG_GETARG_TEXT_P(0);
/*
* VARSIZE is the total size of the struct in bytes.
*/
text *new_t = (text *) palloc(VARSIZE(t));
VARATT_SIZEP(new_t) = VARSIZE(t);
/*
* VARDATA is a pointer to the data region of the struct.
*/
memcpy((void *) VARDATA(new_t), /* destination */
(void *) VARDATA(t), /* source */
VARSIZE(t)-VARHDRSZ); /* how many bytes */
PG_RETURN_TEXT_P(new_t);
}
PG_FUNCTION_INFO_V1(concat_text);
Datum
concat_text(PG_FUNCTION_ARGS)
{
text *arg1 = PG_GETARG_TEXT_P(0);
text *arg2 = PG_GETARG_TEXT_P(1);
int32 new_text_size = VARSIZE(arg1) + VARSIZE(arg2) - VARHDRSZ;
text *new_text = (text *) palloc(new_text_size);
VARATT_SIZEP(new_text) = new_text_size;
memcpy(VARDATA(new_text), VARDATA(arg1), VARSIZE(arg1)-VARHDRSZ);
memcpy(VARDATA(new_text) + (VARSIZE(arg1)-VARHDRSZ),
VARDATA(arg2), VARSIZE(arg2)-VARHDRSZ);
PG_RETURN_TEXT_P(new_text);
}
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
Please any direction of how to solve the problem
here is the command i wrote in MinGW
gcc -shared -o hamzeh.dll tt1.o -L "c:/programme/postgresql/8.3/lib" -lpostgres
thanks
_________________________________________________________________
Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy!
http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us
2009/4/6 eehab hamzeh <eehab40@hotmail.com>:
Dear Sir
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 directionshere are the code and the error , i compile them using vc++ 6 and VC++ 2008
and minGW the example below are for minGWTHANKS
#include "postgres.h"
#include <string.h>
#include "fmgr.h"#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif/* by value */
PG_FUNCTION_INFO_V1(add_one);
Datum
add_one(PG_FUNCTION_ARGS)
{
int32 arg = PG_GETARG_INT32(0);PG_RETURN_INT32(arg + 1);
}/* by reference, fixed length */
PG_FUNCTION_INFO_V1(add_on e_float8);
Datum
add_one_float8(PG_FUNCTION_ARGS)
{
/* The macros for FLOAT8 hide its pass-by-reference nature. */
float8 arg = PG_GETARG_FLOAT8(0);PG_RETURN_FLOAT8(arg + 1.0);
}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));new_point->x = pointx->x;
new_point->y = pointy->y;PG_RETURN_POINT_P(new_point);
}/* by reference, variable length */
PG_FUNCTION_INFO_V1(copytext);
Datum
copytext(PG_FUNCTION_ARGS)
{
text *t = PG_GETARG_TEXT_P(0);
/*
* VARSIZE is the total size of the struct in bytes.
*/
text *new_t = (text *) palloc(VARSIZE(t));
VARATT_SIZEP(new_t) = VARSIZE(t);
/*
* VARDATA is a pointer to the data region of the struct.
*/
memcpy((void *) VARDATA(new_t), /* destination */
(void *) VARDATA(t), /* source */
VARSIZE(t)-VARHDRSZ); /* how many bytes */
PG_RETURN_TEXT_P(new_t);
}PG_FUNCTION_INFO_V1(concat_text);
Datum
concat_text(PG_FUNCTION_ARGS)
{
text *arg1 = PG_GETARG_TEXT_P(0);
text *arg2 = PG_GETARG_TEXT_P(1);
int32 new_text_size = VARSIZE(arg1) + VARSIZE(arg2) - VARHDRSZ;
text *new_text = (text *) palloc(new_text_size);VARATT_SIZEP(new_text) = new_text_size;
memcpy(VARDATA(new_text), VARDATA(arg1), VARSIZE(arg1)-VARHDRSZ);
memcpy(VARDATA(new_text) + (VARSIZE(arg1)-VARHDRSZ ),
VARDATA(arg2), VARSIZE(arg2)-VARHDRSZ);
PG_RETURN_TEXT_P(new_text);
}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 filePlease any direction of how to solve the problem
here is the command i wrote in MinGW
gcc -shared -o hamzeh.dll tt1.o -L "c:/programme/postgresql/8.3/lib"
-lpostgres
try c:\programme\ ....
And try the option -I (include)
REPLY TO pgsql-general@portgresql.org,please...
Comitters is not a list to make questions :)
And please, when you post a question put a description
in the subject of the mail.
Thanks.
--
Emanuel Calvo Franco
Sumate al ARPUG !
(www.postgres-arg.org -
www.arpug.com.ar)
ArPUG / AOSUG Member
Postgresql Support & Admin
2009/4/6 eehab hamzeh <eehab40@hotmail.com>:
Dear Sir,
I have replied to the commiters again while i recive an email from
pgsql-general@postgresql.org
saying this is not the right place for this question, i expect that the
Comitters are the right place. sorry again and i will stop sending emails to
commiters.
i kindly want to ask again you for further explanation of the I option.
my command for should looks like this thengcc -shared -o hamzeh.dll tt1.o -L "c:/programme/postgresql/8.3/lib"
-I (include) postgresI am a new user to MinGw
Thanks again
AFAIK gcc has an option -I for detail the path of the includes.
I think there must be inside a folder called 'server' in the same
path.
Yes, i was who said to you that committers is not the right place :)
--
Emanuel Calvo Franco
Sumate al ARPUG !
(www.postgres-arg.org -
www.arpug.com.ar)
ArPUG / AOSUG Member
Postgresql Support & Admin
Import Notes
Reply to msg id not found: BLU133-W15854EC968453C10793080A0840@phx.gbl