Re: passing arrays to shared object functions

From: "Florian G(dot) Pflug" <fgp(at)phlo(dot)org>
To: jason(at)mbi(dot)ucla(dot)edu
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: passing arrays to shared object functions
Date: 2007-04-10 20:10:24
Message-ID: 461BEF30.2080609@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jason Nerothin wrote:
> I've been attempting for a while to figure out how to pass arrays of
> integers back and forth from a custom c-library that I'd like to plug into
> my server instance. Although I'm able to usefully pass single integers to a
> functions I've written, the best I've been able to accomplish passing in
> pointers and const pointers is to blow up the server. I've only attempted
> compiling per the instructions <a href="
> http://www.postgresql.org/docs/current/static/xfunc-c.html">here</a>. I
> wanted to check with this list first before spending any time delving into
> libpq for fear that it was the wrong rabbit-hole to go looking into in the
> first place.

arrays are not passed as pointer-to-the-first-element to your c function
as they are in plain C. There are macros defined in the postgres headers
for dealing with arrays - I suggest that you look at some backend
functions that take parameters, and see how they handle things. (I think
grepping for array_concat might give you a clue of where to look...).

At least for "version 1" functions, even ints and such are not passed
as normal parameters to your function - there are macros for accessing
such parameters too.

greetings, Florian Pflug

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Florian G. Pflug 2007-04-10 20:18:01 Re: Do I need serializable for this query?
Previous Message John D. Burger 2007-04-10 19:47:26 Re: NEWBIE: How do I get the oldest date contained in 3 tables