Re: extending by using procedurallanguage C : problems

From: Feite Brekeveld <f(dot)brekeveld(at)osiris-it(dot)nl>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: extending by using procedurallanguage C : problems
Date: 2002-12-17 21:25:30
Message-ID: 3DFF964A.5000908@osiris-it.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Peter Eisentraut wrote:

>Feite Brekeveld writes:
>
>
>
>>I'm having some trouble extending postgresql with some C-functions.
>>
>>
>
>It seems to me that you should actually read the documentation on writing
>C extension functions, found in the Programmer's Guide, because the
>interface you are using is completely wrong.
>
>
>
Hi,

that seems like an 'ouch' for me!

I've read chapter 12.5.3 !

using the examples for the 'old-style' the only remark I can make myself on the email sent is the misuse of the word 'procedural'.

An example from an earlier version of postgres works fine:
--------------------------------------------------------------
#include "/usr/include/pgsql/server/postgres.h"

double *ctof(double *deg)
{
double *ret = palloc(sizeof(double));

*ret = (*deg * 9.0 / 5.0) + 32.0;
return ret;
}

create or replace function ctof(float8) RETURNS float8
AS '/users/home/feite/proj/postgres.d/pgsql/pg_osiris' LANGUAGE C
WITH (isStrict);
-----------------------------------------------------------------
Also thisone is working fine:
-----------------------------------------------------------------
#include "/usr/include/pgsql/server/postgres.h"
#include "examp.h"

double *mav(double *a, double *b)
{
double *ret = palloc(sizeof(double));

*ret = ti_mav(a , b);
return ret;
}

#include "examp.h"

double ti_mav(double *a, double *b)
{
double ret;

ret = (*a + *b) / 2.0;
return ret;
}

[feite(at)osiris-1 pgsql]$ psql -U postgres tst
Welcome to psql, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit

tst=# select mav(8,22);
mav
-----
15
(1 row)

---------------------------------------------------------------
The code I sent before is a minor change to get data from shared memory instead. The exception occurs ONLY when the 'shmat' statement is there.

(Same kind of function written in pl/perlu works fine !)

It seems that you know a lot about it. Please give me some tips on this issue. I would appreciate is very much !

Thanks,

Feite Brekeveld

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John Cochran 2002-12-17 22:33:34 Creating trigger functions in pl/pgsql
Previous Message Han Holl 2002-12-17 20:19:18 Re: RPMS for Redhat 7.3 ??