external function proposal for 7.2

Поиск
Список
Период
Сортировка
От mlw
Тема external function proposal for 7.2
Дата
Msg-id 3A3651F5.770EB206@mohawksoft.com
обсуждение исходный текст
Ответы Re: external function proposal for 7.2  (Vincent AE Scott <vince@codex.net>)
Список 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 по дате отправления:

Предыдущее
От: Horst Herb
Дата:
Сообщение: Re: CRC, hash & Co.
Следующее
От: "Martin A. Marques"
Дата:
Сообщение: No postgres on Solaris