passing arrays to shared object functions

From: "Jason Nerothin" <jasonnerothin(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: passing arrays to shared object functions
Date: 2007-04-10 05:09:44
Message-ID: f42b58b90704092209q10461366nd905603dddbd4c39@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.

The basic idea (in pseudo-code) is to implement the following rather simple
algorithm:

int*
and_function(const int* arr1, const int* arr2){
int sz = sizeof( arr1 ); // or obtain from another param...
// memcpy data over for arr1, arr2...
int[sz] r_arr = (int*) palloc( VARHDRZ + sz );
int i;
for( i=0; i<sz; i++ ){
r_arr[i] = arr1 & arr2;
}
return r_arr;
}

It seems that when I attempt to call the function with either "version 0" or
"version 1" syntax, the dynamic binding confuses the server even though my
CREATE OR REPLACE FUNCTION and_function(int[]) RETURNS int[] ... is
syntactically correct and the library is located appropriately.

--bash-3.00$ /opt/postgres/bin/pg_config --version
PostgreSQL 8.2.3

I apologize in advance if my problem arises from c-ignorance.

Any suggestions?

========================================================
Jason Nerothin
Programmer/Analyst IV - Database Administration
UCLA-DOE Institute for Genomics & Proteomics
Howard Hughes Medical Institute
========================================================
611 C.E. Young Drive East | Tel: (310) 206-3907
105 Boyer Hall, Box 951570 | Fax: (310) 206-3914
Los Angeles, CA 90095. USA | Mail: jason(at)mbi(dot)ucla(dot)edu
========================================================
http://www.mbi.ucla.edu/~jason
========================================================

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Leon Mergen 2007-04-10 06:46:41 INSERT..RETURNING on a partitioned table
Previous Message Robert Treat 2007-04-10 03:06:11 Re: Pg schema diff tools Was: [ANNOUNCE] == PostgreSQL Weekly News - April 08 2007 ==