external function proposal for 7.2 - Mailing list pgsql-hackers

From mlw
Subject external function proposal for 7.2
Date
Msg-id 3A3651F5.770EB206@mohawksoft.com
Whole thread Raw
Responses Re: external function proposal for 7.2  (Vincent AE Scott <vince@codex.net>)
List 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
extrainfo about
 
result */   bool        isnull;         /* function must set true if result is
NULL */   short       nargs;          /* # arguments actually passed */   Datum       arg[FUNC_MAX_ARGS];  /* Arguments
passedto 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.



pgsql-hackers by date:

Previous
From: Horst Herb
Date:
Subject: Re: CRC, hash & Co.
Next
From: "Martin A. Marques"
Date:
Subject: No postgres on Solaris