Extending PostgreSQL on Windows

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Extending PostgreSQL on Windows

Kostadin Zhelev
Hi I intalled postgreSQL 8.0.3 from win installer.
I am trying to create my own c functions to exetend the functionallity of postgres. I had some trouble so I tryed add_one function as it is shown in the documentation. When I use the old convention I am able to run the function fine when I use the new convention with the macros after i call the function I get the following error:
server closed the connection unexpectedly
 This probably means the server terminated abnormally
 before or while processing the request.
 
After playing with it a little I came if a conclusion that the arguments or the fcinfo struct is not properly initialized since the code breaks only when I try to access the arguments either through the macros or directly. My IDE is VS.NET 2003
The code that brakes is the following:
 

PG_FUNCTION_INFO_V1(add_one);

Datum

add_one(PG_FUNCTION_ARGS)

{

int32 arg = PG_GETARG_INT32(0);

PG_RETURN_INT32(arg);

}

But the following works:

Datum

add_one(PG_FUNCTION_ARGS)

{

FunctionCallInfo fcc;

fcc = (struct FunctionCallInfoData *)malloc(sizeof(struct FunctionCallInfoData));

fcc->nargs = 4;

return (int32)fcc->nargs;

}

Any help will be appreciated.



email:[hidden email]


Yahoo! Sports
Rekindle the Rivalries. Sign up for Fantasy Football
Reply | Threaded
Open this post in threaded view
|

Re: Extending PostgreSQL on Windows

Magnus Hagander
While it may work, we don't fully support using MSVC for developing
server-side extensions. Not sure if it's related to your problem, but
it's quite possible. You will need to get the MingW toolset to developer
server-side. (You can still use the VS IDE if you want to, of course,
but you need to use the gcc compiler from MingW).

//Magnus

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf
> Of Kostadin Zhelev
> Sent: Thursday, June 30, 2005 4:48 PM
> To: [hidden email]
> Subject: [pgsql-hackers-win32] Extending PostgreSQL on Windows
>
> Hi I intalled postgreSQL 8.0.3 from win installer.
> I am trying to create my own c functions to exetend the
> functionallity of postgres. I had some trouble so I tryed
> add_one function as it is shown in the documentation. When I
> use the old convention I am able to run the function fine
> when I use the new convention with the macros after i call
> the function I get the following error:
> server closed the connection unexpectedly  This probably
> means the server terminated abnormally  before or while
> processing the request.
>  
> After playing with it a little I came if a conclusion that
> the arguments or the fcinfo struct is not properly
> initialized since the code breaks only when I try to access
> the arguments either through the macros or directly. My IDE
> is VS.NET 2003 The code that brakes is the following:
>  
>
> PG_FUNCTION_INFO_V1(add_one);
>
> Datum
>
> add_one(PG_FUNCTION_ARGS)
>
> {
>
> int32 arg = PG_GETARG_INT32(0);
>
> PG_RETURN_INT32(arg);
>
> }
>
> But the following works:
>
> Datum
>
> add_one(PG_FUNCTION_ARGS)
>
> {
>
> FunctionCallInfo fcc;
>
> fcc = (struct FunctionCallInfoData *)malloc(sizeof(struct
> FunctionCallInfoData));
>
> fcc->nargs = 4;
>
> return (int32)fcc->nargs;
>
> }
>
> Any help will be appreciated.
>
>
>
> email:[hidden email]
>
> ________________________________
>
> Yahoo! Sports
> Rekindle the Rivalries. Sign up for Fantasy Football
> <http://pa.yahoo.com/*http://us.rd.yahoo.com/evt=33539/*http:/
> /football.fantasysports.yahoo.com?ovchn=YAH&ovcpn=Integration&
> ovcrn=Mail+footer&ovrfd=YAH&ovtac=AD>  
>

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq
Reply | Threaded
Open this post in threaded view
|

Re: Extending PostgreSQL on Windows

Tom Lane-2
"Magnus Hagander" <[hidden email]> writes:
> While it may work, we don't fully support using MSVC for developing
> server-side extensions. Not sure if it's related to your problem, but
> it's quite possible.

The symptoms sound like the backend is not recognizing the function
as being V1 calling convention, which suggests something wrong with
the expansion of the PG_FUNCTION_INFO_V1 macro (eg, the created routine
doesn't have the right name).  Hard to say more than that.

                        regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq