PostgreSQL Source Code git master
Loading...
Searching...
No Matches
plpy_procedure.h
Go to the documentation of this file.
1/*
2 * src/pl/plpython/plpy_procedure.h
3 */
4
5#ifndef PLPY_PROCEDURE_H
6#define PLPY_PROCEDURE_H
7
8#include "plpy_typeio.h"
9#include "utils/funccache.h"
10
11
12/*
13 * Trigger type
14 */
21
22/* saved arguments for outer recursion level or set-returning function */
23typedef struct PLySavedArgs
24{
25 struct PLySavedArgs *next; /* linked-list pointer */
26 PyObject *args; /* "args" element of globals dict */
27 PyObject *td; /* "TD" element of globals dict, if trigger */
28 int nargs; /* length of namedargs array */
31
32/* saved state for a set-returning function */
33typedef struct PLySRFState
34{
35 PyObject *iter; /* Python iterator producing results */
36 PLySavedArgs *savedargs; /* function argument values */
38
39/*
40 * Long-lived data for a PL/Python function.
41 *
42 * This struct is managed by funccache.c and can be shared across multiple
43 * executions of the same function. It must contain no execution-specific
44 * state. The CachedFunction struct must be first.
45 */
46typedef struct PLyProcedure
47{
48 CachedFunction cfunc; /* fields managed by funccache.c */
49
50 MemoryContext mcxt; /* context holding this PLyProcedure and its
51 * subsidiary data */
52 char *proname; /* SQL name of procedure */
53 char *pyname; /* Python name of procedure */
55 bool is_setof; /* true, if function returns result set */
57 PLyTrigType is_trigger; /* called as trigger? */
58 PLyObToDatum result; /* Function result output conversion info */
59 PLyDatumToOb result_in; /* For converting input tuples in a trigger */
60 char *src; /* textual procedure code, after mangling */
61 char **argnames; /* Argument names */
62 PLyDatumToOb *args; /* Argument input conversion info */
63 int nargs; /* Number of elements in above arrays */
64 Oid langid; /* OID of plpython pg_language entry */
65 List *trftypes; /* OID list of transform types */
66 PyObject *code; /* compiled procedure code */
67 PyObject *statics; /* data saved across calls, local scope */
68 PyObject *globals; /* data saved across calls, global scope */
69 long calldepth; /* depth of recursive calls of function */
70 PLySavedArgs *argstack; /* stack of outer-level call arguments */
72
73/*
74 * Per-call-site cache for a PL/Python function.
75 *
76 * This struct is stored in fn_extra and holds execution-specific state,
77 * including a pointer to the long-lived PLyProcedure. The use_count in
78 * the PLyProcedure is incremented while we hold a reference.
79 */
80typedef struct PLyProcedureCache
81{
82 PLyProcedure *proc; /* long-lived hash entry */
83 MemoryContext fcontext; /* fn_mcxt - context holding this struct */
84 PLySRFState *srfstate; /* SRF execution state, NULL if not in SRF */
85 bool shutdown_reg; /* true if registered shutdown callback */
86
87 /* Callback to release resources when fcontext is reset or deleted */
90
91/* PLyProcedure manipulation */
92extern char *PLy_procedure_name(PLyProcedure *proc);
94extern void PLy_procedure_compile(PLyProcedure *proc, const char *src);
95extern void PLy_procedure_delete(PLyProcedure *proc);
96
97#endif /* PLPY_PROCEDURE_H */
#define FLEXIBLE_ARRAY_MEMBER
Definition c.h:614
char * PLy_procedure_name(PLyProcedure *proc)
PLyTrigType
@ PLPY_EVENT_TRIGGER
@ PLPY_TRIGGER
@ PLPY_NOT_TRIGGER
PLyProcedureCache * PLy_procedure_get(FunctionCallInfo fcinfo, bool forValidator)
void PLy_procedure_compile(PLyProcedure *proc, const char *src)
void PLy_procedure_delete(PLyProcedure *proc)
unsigned int Oid
static int fb(int x)
Definition pg_list.h:54
MemoryContext fcontext
PLyProcedure * proc
MemoryContextCallback mcb
PLySRFState * srfstate
PLyDatumToOb * args
PLyTrigType is_trigger
PLyObToDatum result
PyObject * code
PLyDatumToOb result_in
PLySavedArgs * argstack
MemoryContext mcxt
CachedFunction cfunc
PyObject * globals
PyObject * statics
PLySavedArgs * savedargs
PyObject * iter
PyObject * args
struct PLySavedArgs * next
PyObject * namedargs[FLEXIBLE_ARRAY_MEMBER]
PyObject * td