Function C and INOUT parameters

Started by Ben Ali Rachidalmost 17 years ago17 messages
#1Ben Ali Rachid
souliman239@yahoo.fr

Hello,

I posted my problem (on pgsql-interfaces list) about the INOUT parameters on PostgreSQL 8.3.6 (Win32), but without success. I re-post my question here, while hoping to have more success.

When I use a function with one INOUT (or OUT) parameter like below, everyting is OK.

CREATE OR REPLACE FUNCTION add_one(INOUT arg integer)

RETURNS integer  AS '$libdir/myDLL.dll', 'add_one'

LANGUAGE 'c' VOLATILE STRICT ;

// In 'myDLL'
void add_one(int arg)

{

arg = arg + 1 ;

}

select * from add_one(10) ;  // OK

But when I use 2 or more INOUT (or OUT) parameters like below, the server crashes with exception 0xC0000005 (access violation).

CREATE OR REPLACE FUNCTION add_one(INOUT arg1 integer, INOUT arg2 integer)

RETURNS record  AS '$libdir/myDLL.dll', 'add_one'

LANGUAGE 'c' VOLATILE STRICT ;

void add_one(int arg1, int arg2)

{

arg1 = arg1 + 1 ;

arg2 = arg2 + 1 ;

}

select * from add_one(10, 20);  // CRASH

I probably understood something wrong with the INOUT parameter. Is there someone to help me ? Thanks.

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Ben Ali Rachid (#1)
Re: Function C and INOUT parameters

Ben Ali Rachid <souliman239@yahoo.fr> writes:

I posted my problem (on pgsql-interfaces list) about the INOUT parameters on PostgreSQL 8.3.6 (Win32), but without success. I re-post my question here, while hoping to have more success.

You apparently have no understanding at all of how parameters are passed
to and from C-language functions in Postgres :-(. Start here:

http://www.postgresql.org/docs/8.3/static/xfunc-c.html

and note that any situation involving multiple OUT parameters is handled
as returning an anonymous composite type. There are a number of
useful examples in the contrib modules.

regards, tom lane

#3Greg Stark
stark@enterprisedb.com
In reply to: Ben Ali Rachid (#1)
Re: Function C and INOUT parameters

On Tue, Mar 24, 2009 at 4:54 PM, Ben Ali Rachid <souliman239@yahoo.fr> wrote:

Hello,

I posted my problem (on pgsql-interfaces list) about the INOUT parameters on
PostgreSQL 8.3.6 (Win32), but without success. I re-post my question here,
while hoping to have more success.

Personally I'm of the opinion we should eliminate most of these
duplicative mailing lists like -performance and -interfaces and just
use -general. I don't see that having multiple lists for user
questions helps either the users or the answerers due to just this
type of problem.

When I use a function with one INOUT (or OUT) parameter like below,
everyting is OK.

CREATE OR REPLACE FUNCTION add_one(INOUT arg integer)
RETURNS integer  AS '$libdir/myDLL.dll', 'add_one'
LANGUAGE 'c' VOLATILE STRICT ;

// In 'myDLL'
void add_one(int arg)

a) you should probably be using V1 calling api rather than V0. see

http://www.postgresql.org/docs/8.3/interactive/xfunc-c.html#AEN40901

b) you need to arrange for the C function to return a record with all
the returned fields. You can't just set the parameters to new values
and return void.

The api to return a record is at:

http://www.postgresql.org/docs/8.3/interactive/xfunc-c.html#AEN41361

--
greg

#4Robert Haas
robertmhaas@gmail.com
In reply to: Greg Stark (#3)
Re: Function C and INOUT parameters

On Tue, Mar 24, 2009 at 2:11 PM, Greg Stark <stark@enterprisedb.com> wrote:

Personally I'm of the opinion we should eliminate most of these
duplicative mailing lists like -performance and -interfaces and just
use -general. I don't see that having multiple lists for user
questions helps either the users or the answerers due to just this
type of problem.

-1. I don't read -general; I do read -performance. The S/N ratio is
high enough to make it worth the time it takes; I don't think that
would be true on -general.

...Robert

#5Ben Ali Rachid
souliman239@yahoo.fr
In reply to: Robert Haas (#4)
Re: Function C and INOUT parameters

Thanks ! Now, it works fine.

Greg Stark <stark@enterprisedb.com> wrote:

Personally I'm of the opinion we should eliminate most of these

duplicative mailing lists like -performance and -interfaces and just

use -general. I don't see that having multiple lists for user

questions helps either the users or the answerers due to just this

type of problem.

In any case, this list has more success than 'interfaces list' (prompt and efficient responses).

#6Josh Berkus
josh@agliodbs.com
In reply to: Greg Stark (#3)
Re: Function C and INOUT parameters

Personally I'm of the opinion we should eliminate most of these
duplicative mailing lists like -performance and -interfaces and just
use -general. I don't see that having multiple lists for user
questions helps either the users or the answerers due to just this
type of problem.

... and instead drive new users away by forcing them to sign up for one
massive 400 posts/day list?

I'm not sure about -interfaces, but -performance, -sql, -jdbc and others
definitely have specific audiences and themes which they are already
handling a *lot* of traffic for.

--Josh

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Josh Berkus (#6)
Re: Function C and INOUT parameters

Josh Berkus <josh@agliodbs.com> writes:

I'm not sure about -interfaces, but -performance, -sql, -jdbc and others
definitely have specific audiences and themes which they are already
handling a *lot* of traffic for.

It does look like -interfaces is dying: almost no traffic, and what
questions it does get are off-topic more often than not. Partly this
is because the -jdbc, -odbc, and -php lists suck away all the traffic
about those interfaces, leaving not much. So we could kill -interfaces
without much loss IMHO.

The other global lists seem to be in good health from what I can see.
Can't speak to the regional or user-group lists, I don't follow them.

regards, tom lane

#8Josh Berkus
josh@agliodbs.com
In reply to: Tom Lane (#7)
Re: Function C and INOUT parameters

Tom,

The other global lists seem to be in good health from what I can see.
Can't speak to the regional or user-group lists, I don't follow them.

Those have specific reasons to survive regardless of traffic level.

--Josh

#9Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#7)
Re: Function C and INOUT parameters

Tom Lane wrote:

It does look like -interfaces is dying: almost no traffic, and what
questions it does get are off-topic more often than not. Partly this
is because the -jdbc, -odbc, and -php lists suck away all the traffic
about those interfaces, leaving not much. So we could kill -interfaces
without much loss IMHO.

It was supposed to have been killed already, as per last year's dev
meeting and subsequent discussion. Someone just needs to do it.

#10Alvaro Herrera
alvherre@commandprompt.com
In reply to: Peter Eisentraut (#9)
shut down pgsql-interfaces (was Re: [HACKERS] Function C and INOUT parameters)

Peter Eisentraut wrote:

Tom Lane wrote:

It does look like -interfaces is dying: almost no traffic, and what
questions it does get are off-topic more often than not. Partly this
is because the -jdbc, -odbc, and -php lists suck away all the traffic
about those interfaces, leaving not much. So we could kill -interfaces
without much loss IMHO.

It was supposed to have been killed already, as per last year's dev
meeting and subsequent discussion. Someone just needs to do it.

Okay, I've moved it to the inactive group; it already shows up as such
in archives, and www will be updated as soon as it rebuilds and
propagates to the mirrors.

As for actually shutting it down in Majordomo, Marc is the man.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

#11Josh Berkus
josh@agliodbs.com
In reply to: Alvaro Herrera (#10)
Re: shut down pgsql-interfaces (was Re: [HACKERS] Function C and INOUT parameters)

On 3/25/09 8:11 AM, Alvaro Herrera wrote:

Peter Eisentraut wrote:

Tom Lane wrote:

It does look like -interfaces is dying: almost no traffic, and what
questions it does get are off-topic more often than not. Partly this
is because the -jdbc, -odbc, and -php lists suck away all the traffic
about those interfaces, leaving not much. So we could kill -interfaces
without much loss IMHO.

It was supposed to have been killed already, as per last year's dev
meeting and subsequent discussion. Someone just needs to do it.

Okay, I've moved it to the inactive group; it already shows up as such
in archives, and www will be updated as soon as it rebuilds and
propagates to the mirrors.

As for actually shutting it down in Majordomo, Marc is the man.

Might want to make an announcement on that list first.

--Josh

#12Alvaro Herrera
alvherre@commandprompt.com
In reply to: Josh Berkus (#11)
Re: shut down pgsql-interfaces (was Re: [HACKERS] Function C and INOUT parameters)

Josh Berkus wrote:

On 3/25/09 8:11 AM, Alvaro Herrera wrote:

As for actually shutting it down in Majordomo, Marc is the man.

Might want to make an announcement on that list first.

http://archives.postgresql.org/pgsql-interfaces/2008-07/msg00002.php

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

#13Josh Berkus
josh@agliodbs.com
In reply to: Alvaro Herrera (#12)
Re: shut down pgsql-interfaces (was Re: [HACKERS] Function C and INOUT parameters)

On 3/25/09 12:17 PM, Alvaro Herrera wrote:

Josh Berkus wrote:

On 3/25/09 8:11 AM, Alvaro Herrera wrote:

As for actually shutting it down in Majordomo, Marc is the man.

Might want to make an announcement on that list first.

http://archives.postgresql.org/pgsql-interfaces/2008-07/msg00002.php

That was 6 months ago. I doubt anyone remembers it. Make another
announcement, so that when people get the "unsubscribed" announcement,
they're not confused.

--Josh

#14Alvaro Herrera
alvherre@commandprompt.com
In reply to: Josh Berkus (#13)
Re: shut down pgsql-interfaces (was Re: [HACKERS] Function C and INOUT parameters)

Josh Berkus wrote:

On 3/25/09 12:17 PM, Alvaro Herrera wrote:

http://archives.postgresql.org/pgsql-interfaces/2008-07/msg00002.php

That was 6 months ago. I doubt anyone remembers it. Make another
announcement, so that when people get the "unsubscribed" announcement,
they're not confused.

Done.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

#15Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#14)
Re: shut down pgsql-interfaces (was Re: [HACKERS] Function C and INOUT parameters)

Alvaro Herrera <alvherre@commandprompt.com> writes:

Josh Berkus wrote:

That was 6 months ago. I doubt anyone remembers it. Make another
announcement, so that when people get the "unsubscribed" announcement,
they're not confused.

Done.

BTW, what was the reason we didn't pull the trigger before, when we
retired the other lists? Just an oversight?

regards, tom lane

#16Marc G. Fournier
scrappy@hub.org
In reply to: Alvaro Herrera (#14)
Re: shut down pgsql-interfaces (was Re: [HACKERS] Function C and INOUT parameters)

Please clarify what you want done on the majordomo side ... I saw one
comment about unsub'ng everyone ... for archive purposes, this makes
sense, I just want to make sure before I blow them all away (and I will
unsubscribe them without having a blast of emails go out to them) ....

I will also mark the list as 'inactive' ...

On Wed, 25 Mar 2009, Alvaro Herrera wrote:

Josh Berkus wrote:

On 3/25/09 12:17 PM, Alvaro Herrera wrote:

http://archives.postgresql.org/pgsql-interfaces/2008-07/msg00002.php

That was 6 months ago. I doubt anyone remembers it. Make another
announcement, so that when people get the "unsubscribed" announcement,
they're not confused.

Done.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

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

----
Marc G. Fournier Hub.Org Networking Services (http://www.hub.org)
Email . scrappy@hub.org MSN . scrappy@hub.org
Yahoo . yscrappy Skype: hub.org ICQ . 7615664

#17Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#15)
Re: shut down pgsql-interfaces (was Re: [HACKERS] Function C and INOUT parameters)

On Wednesday 25 March 2009 23:55:06 Tom Lane wrote:

Alvaro Herrera <alvherre@commandprompt.com> writes:

Josh Berkus wrote:

That was 6 months ago. I doubt anyone remembers it. Make another
announcement, so that when people get the "unsubscribed" announcement,
they're not confused.

Done.

BTW, what was the reason we didn't pull the trigger before, when we
retired the other lists? Just an oversight?

Because the same people who complained just now complained back then as well.
So we retired the lists without objections first.