Thread: Function C and INOUT parameters

Function C and INOUT parameters

From
Ben Ali Rachid
Date:
<table border="0" cellpadding="0" cellspacing="0"><tr><td style="font: inherit;" valign="top">Hello, <br /><br />I
postedmy 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.<br /><br />When I use a function with one INOUT
(orOUT) parameter like below, everyting is OK.<br /><span id="intelliTxt" name="intelliTxt"><span style="font-style:
italic;"><br/></span></span><span id="intelliTxt" name="intelliTxt" style="font-style: italic;">CREATE OR REPLACE
FUNCTIONadd_one(INOUT arg integer)<br /> RETURNS integer  AS '$libdir/myDLL.dll', 'add_one'<br /> LANGUAGE 'c' VOLATILE
STRICT;</span><br /><br /><span id="intelliTxt" name="intelliTxt" style="font-style: italic;">// In 'myDLL'<br />void
add_one(intarg)<br /> {<br /> arg = arg + 1 ;<br /> }</span><br /><br /><span id="intelliTxt" name="intelliTxt"
style="font-style:italic;">select * from add_one(10)</span><span style="font-style: italic;"> ;  // OK</span><br /><br
/>Butwhen I use 2 or more INOUT (or OUT) parameters like below, the server crashes with exception 0xC0000005 (access
violation).<br /><br /><span id="intelliTxt" name="intelliTxt"><span style="font-style: italic;">CREATE OR REPLACE
FUNCTIONadd_one(INOUT arg1 integer, INOUT arg2 integer)</span><br style="font-style: italic;" /><span
style="font-style:italic;"> RETURNS record  </span><span style="font-style: italic;">AS '$libdir/myDLL.dll',
'add_one'</span><brstyle="font-style: italic;" /><span style="font-style: italic;"> LANGUAGE 'c' VOLATILE STRICT ;<br
/><br/></span></span><span id="intelliTxt" name="intelliTxt"><span style="font-style: italic;">void add_one(int arg1,
intarg2)</span><br style="font-style: italic;" /><span style="font-style: italic;"> {</span><br style="font-style:
italic;"/><span style="font-style: italic;"> arg1 = arg1 + 1 ;</span><br style="font-style: italic;" /><span
style="font-style:italic;"> arg2 = arg2 + 1 ;</span><br style="font-style: italic;" /><span style="font-style:
italic;">}</span></span><br /><br /><span id="intelliTxt" name="intelliTxt" style="font-style: italic;">select * from
add_one(10,20);  // CRASH</span><br /><br />I probably understood something wrong with the INOUT parameter. Is there
someoneto help me ? Thanks.<br /><br /></td></tr></table><br /> 

Re: Function C and INOUT parameters

From
Tom Lane
Date:
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


Re: Function C and INOUT parameters

From
Greg Stark
Date:
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


Re: Function C and INOUT parameters

From
Robert Haas
Date:
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


Re: Function C and INOUT parameters

From
Ben Ali Rachid
Date:
<table border="0" cellpadding="0" cellspacing="0"><tr><td style="font: inherit;" valign="top"><span class="email"><br
/>Thanks ! Now, it works fine. <br /><br /></span>Greg Stark <<a
href="http://fr.mc285.mail.yahoo.com/mc/compose?to=stark@enterprisedb.com"
ymailto="mailto:stark@enterprisedb.com">stark@enterprisedb.com</a>>wrote:<br /> > Personally I'm of the opinion
weshould eliminate most of these<br /> > duplicative mailing lists like -performance and -interfaces and just<br />
>use -general. I don't see that having multiple lists for user<br /> > questions helps either the users or the
answerersdue to just this<br /> > type of problem.<br /><br /> In any case, this list has more success than
'interfaceslist' (prompt and efficient responses).<br /><br /></td></tr></table><br /> 

Re: Function C and INOUT parameters

From
Josh Berkus
Date:
> 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


Re: Function C and INOUT parameters

From
Tom Lane
Date:
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


Re: Function C and INOUT parameters

From
Josh Berkus
Date:
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



Re: Function C and INOUT parameters

From
Peter Eisentraut
Date:
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.



shut down pgsql-interfaces (was Re: Function C and INOUT parameters)

From
Alvaro Herrera
Date:
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


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


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


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


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


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


Re: [pgsql-www] shut down pgsql-interfaces (was Re: Function C and INOUT parameters)

From
"Marc G. Fournier"
Date:
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


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.