external function proposal for 7.2

From: mlw <markw(at)mohawksoft(dot)com>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: external function proposal for 7.2
Date: 2000-12-12 16:27:33
Message-ID: 3A3651F5.770EB206@mohawksoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I think the newC function idea is pretty good, however, what would be
great is just one more step of protocol, perhaps an API verson 2 or 3:

One thing than makes writing a non-trivial function a bit problematic,
and perhaps even less efficient, is that the function does not know when
it is first run and when it is finished, and there is no facility to
manage contextual information. This limits external functons having to
be fairly simple, or overly complex.

I propose that when the newC structure is allocated that a function
specific "Init" function be called, and when the structure is being
freed, calling a "Exit" function. The new C structure should also have a
void pointer that allows persistent information to be passed around.

typedef struct
{
FmgrInfo *flinfo; /* ptr to lookup info used for this call
*/
Node *context; /* pass info about context of call */
Node *resultinfo; /* pass or return extra info about
result */
bool isnull; /* function must set true if result is
NULL */
short nargs; /* # arguments actually passed */
Datum arg[FUNC_MAX_ARGS]; /* Arguments passed to function */
bool argnull[FUNC_MAX_ARGS]; /* T if arg[i] is actually NULL
*/

void * userparam; /* to be used by he function */

} FunctionCallInfoData;
typedef FunctionCallInfoData* FunctionCallInfo;

The userparam can be used to store data, or a count, or whatever.

Datum function(PG_FUNCTION_ARGS) ;
bool function_Init(PG_FUNCTION_ARGS);
void function_Exit(PG_FUNCTION_ARGS);

This protocol would make writing some really cool features much easier.
As a C++ guy, I could execute "new" at Init and "delete" at Exit. ;-)

Mark.

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Zeugswetter Andreas SB 2000-12-12 16:28:20 AW: Re: COPY BINARY file format proposal
Previous Message Bruce Momjian 2000-12-12 16:22:29 Re: select cash_out('2'); crashes backend on 7.0.2